{"action":"created","comment":{"url":"https://api.github.com/repos/getify/JSON.minify/pulls/comments/46076787","id":46076787,"diff_hunk":"@@ -0,0 +1,164 @@\n+//\n+//  Minify.java\n+//  jsonminifier - Ported from https://github.com/getify/JSON.minify\n+//\n+//  Created by Bernhard Gass on 8/01/13.\n+//  Copyright © 2013 Bernhard Gass. All rights reserved.\n+\n+package com.changeme.json;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.regex.Matcher;\n+import java.util.regex.Pattern;\n+\n+import org.junit.Test;\n+\n+public class Minify {\n+\n+    public String minify(String jsonString) {\n+        String tokenizer = \"\\\"|(/\\\\*)|(\\\\*/)|(//)|\\\\n|\\\\r\";\n+        String magic = \"(\\\\\\\\)*$\";\n+        Boolean in_string = false;\n+        Boolean in_multiline_comment = false;\n+        Boolean in_singleline_comment = false;\n+        String tmp = \"\";\n+        String tmp2 = \"\";\n+        List<String> new_str = new ArrayList<String>();\n+        Integer from = 0;\n+        String lc = \"\";\n+        String rc = \"\";\n+\n+        Pattern pattern = Pattern.compile(tokenizer);\n+        Matcher matcher = pattern.matcher(jsonString);\n+\n+        Pattern magicPattern = Pattern.compile(magic);\n+        Matcher magicMatcher = null;\n+        Boolean foundMagic = false;\n+\n+        if (!matcher.find())\n+            return jsonString;\n+        else\n+            matcher.reset();\n+\n+        while (matcher.find()) {\n+            lc = jsonString.substring(0, matcher.start());\n+            rc = jsonString.substring(matcher.end(), jsonString.length());\n+            tmp = jsonString.substring(matcher.start(), matcher.end());\n+\n+            if (!in_multiline_comment && !in_singleline_comment) {\n+                tmp2 = lc.substring(from);\n+                if (!in_string)\n+                    tmp2 = tmp2.replaceAll(\"(\\\\n|\\\\r|\\\\s)*\", \"\");\n+\n+                new_str.add(tmp2);\n+            }\n+            from = matcher.end();\n+\n+            if (tmp.charAt(0) == '\\\"' && !in_multiline_comment && !in_singleline_comment) {\n+                magicMatcher = magicPattern.matcher(lc);\n+                foundMagic = magicMatcher.find();\n+                if (!in_string || !foundMagic || (magicMatcher.end() - magicMatcher.start()) % 2 == 0) {\n+                    in_string = !in_string;\n+                }\n+                from--;\n+                rc = jsonString.substring(from);\n+            }\n+            else\n+            if (tmp.startsWith(\"/*\") && !in_string && !in_multiline_comment && !in_singleline_comment) {\n+                in_multiline_comment = true;\n+            }\n+            else\n+            if (tmp.startsWith(\"*/\") && !in_string && in_multiline_comment && !in_singleline_comment) {\n+                in_multiline_comment = false;\n+            }\n+            else\n+            if (tmp.startsWith(\"//\") && !in_string && !in_multiline_comment && !in_singleline_comment) {\n+                in_singleline_comment = true;\n+            }\n+            else\n+            if ((tmp.startsWith(\"\\n\") || tmp.startsWith(\"\\r\")) && !in_string && !in_multiline_comment && in_singleline_comment) {\n+                in_singleline_comment = false;\n+            }\n+            else\n+            if (!in_multiline_comment && !in_singleline_comment && !tmp.substring(0, 1).matches(\"\\\\n|\\\\r|\\\\s\")) {\n+                    new_str.add(tmp);\n+            }\n+        }\n+\n+        new_str.add(rc);\n+        StringBuffer sb = new StringBuffer();\n+        for (String str : new_str)\n+            sb.append(str);\n+\n+        return sb.toString();\n+    }\n+\n+    @Test\n+    public void testMinify() {\n+        System.out.println(\"!! Assertions will only be executed if the -ea vm argument is set !!\");\n+\n+        System.out.println(\"Running test1...\");\n+        String test1 = \"// this is a JSON file with comments\\n\" +\n+                \"{\\n\" +\n+                \"\\\"foo\\\": \\\"bar\\\",    // this is cool\\n\" +\n+                \"\\\"bar\\\": [\\n\" +\n+                \"\\\"baz\\\", \\\"bum\\\", \\\"zam\\\"\\n\" +\n+                \"],\\n\" +\n+                \"/* the rest of this document is just fluff\\n\" +\n+                \"in case you are interested. */\\n\" +\n+                \"\\\"something\\\": 10,\\n\" +\n+                \"\\\"else\\\": 20\\n\" +\n+                \"}\\n\" +\n+                \"/* NOTE: You can easily strip the whitespace and comments\\n\" +\n+                \"   from such a file with the JSON.minify() project hosted \\n\"+\n+                \"   here on github at http://github.com/getify/JSON.minify \\n\"+\n+                \"*/\";\n+\n+        String test1_res = \"{\\\"foo\\\":\\\"bar\\\",\\\"bar\\\":[\\\"baz\\\",\\\"bum\\\",\\\"zam\\\"],\\\"something\\\":10,\\\"else\\\":20}\";\n+        assert(minify(test1).equals(test1_res));\n+\n+        System.out.println(\"Running test2...\");\n+        String test2 = \"{\\\"/*\\\":\\\"*/\\\",\\\"//\\\":\\\"\\\",/*\\\"//\\\"*/\\\"/*/\\\"://\\n\" +\n+                      \"\\\"//\\\"}\" +\n+                      \"\";\n+\n+        String test2_res = \"{\\\"/*\\\":\\\"*/\\\",\\\"//\\\":\\\"\\\",\\\"/*/\\\":\\\"//\\\"}\";\n+        assert(minify(test2).equals(test2_res));","path":"Minify.java","position":127,"original_position":127,"commit_id":"493dbaf1a37c9da67a2aaa18f554c337baf83792","original_commit_id":"493dbaf1a37c9da67a2aaa18f554c337baf83792","user":{"login":"kag0","id":3280689,"avatar_url":"https://avatars.githubusercontent.com/u/3280689?v=3","gravatar_id":"","url":"https://api.github.com/users/kag0","html_url":"https://github.com/kag0","followers_url":"https://api.github.com/users/kag0/followers","following_url":"https://api.github.com/users/kag0/following{/other_user}","gists_url":"https://api.github.com/users/kag0/gists{/gist_id}","starred_url":"https://api.github.com/users/kag0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kag0/subscriptions","organizations_url":"https://api.github.com/users/kag0/orgs","repos_url":"https://api.github.com/users/kag0/repos","events_url":"https://api.github.com/users/kag0/events{/privacy}","received_events_url":"https://api.github.com/users/kag0/received_events","type":"User","site_admin":false},"body":"use assertEquals","created_at":"2015-11-28T06:50:29Z","updated_at":"2015-11-28T06:50:29Z","html_url":"https://github.com/getify/JSON.minify/pull/27#discussion_r46076787","pull_request_url":"https://api.github.com/repos/getify/JSON.minify/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/getify/JSON.minify/pulls/comments/46076787"},"html":{"href":"https://github.com/getify/JSON.minify/pull/27#discussion_r46076787"},"pull_request":{"href":"https://api.github.com/repos/getify/JSON.minify/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/getify/JSON.minify/pulls/27","id":37662160,"html_url":"https://github.com/getify/JSON.minify/pull/27","diff_url":"https://github.com/getify/JSON.minify/pull/27.diff","patch_url":"https://github.com/getify/JSON.minify/pull/27.patch","issue_url":"https://api.github.com/repos/getify/JSON.minify/issues/27","number":27,"state":"closed","locked":false,"title":"Add Java port","user":{"login":"pradyunsg","id":3275593,"avatar_url":"https://avatars.githubusercontent.com/u/3275593?v=3","gravatar_id":"","url":"https://api.github.com/users/pradyunsg","html_url":"https://github.com/pradyunsg","followers_url":"https://api.github.com/users/pradyunsg/followers","following_url":"https://api.github.com/users/pradyunsg/following{/other_user}","gists_url":"https://api.github.com/users/pradyunsg/gists{/gist_id}","starred_url":"https://api.github.com/users/pradyunsg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pradyunsg/subscriptions","organizations_url":"https://api.github.com/users/pradyunsg/orgs","repos_url":"https://api.github.com/users/pradyunsg/repos","events_url":"https://api.github.com/users/pradyunsg/events{/privacy}","received_events_url":"https://api.github.com/users/pradyunsg/received_events","type":"User","site_admin":false},"body":"Part of #23\r\n\r\nAny chance of someone running :eyes: through this?","created_at":"2015-06-15T06:42:35Z","updated_at":"2015-11-28T06:50:29Z","closed_at":"2015-11-28T05:54:37Z","merged_at":"2015-11-28T05:54:37Z","merge_commit_sha":"842725cc3a1b23b77a153d4679766959818183b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/getify/JSON.minify/pulls/27/commits","review_comments_url":"https://api.github.com/repos/getify/JSON.minify/pulls/27/comments","review_comment_url":"https://api.github.com/repos/getify/JSON.minify/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getify/JSON.minify/issues/27/comments","statuses_url":"https://api.github.com/repos/getify/JSON.minify/statuses/493dbaf1a37c9da67a2aaa18f554c337baf83792","head":{"label":"pradyunsg:java","ref":"java","sha":"493dbaf1a37c9da67a2aaa18f554c337baf83792","user":{"login":"pradyunsg","id":3275593,"avatar_url":"https://avatars.githubusercontent.com/u/3275593?v=3","gravatar_id":"","url":"https://api.github.com/users/pradyunsg","html_url":"https://github.com/pradyunsg","followers_url":"https://api.github.com/users/pradyunsg/followers","following_url":"https://api.github.com/users/pradyunsg/following{/other_user}","gists_url":"https://api.github.com/users/pradyunsg/gists{/gist_id}","starred_url":"https://api.github.com/users/pradyunsg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pradyunsg/subscriptions","organizations_url":"https://api.github.com/users/pradyunsg/orgs","repos_url":"https://api.github.com/users/pradyunsg/repos","events_url":"https://api.github.com/users/pradyunsg/events{/privacy}","received_events_url":"https://api.github.com/users/pradyunsg/received_events","type":"User","site_admin":false},"repo":{"id":18409585,"name":"JSON.minify","full_name":"pradyunsg/JSON.minify","owner":{"login":"pradyunsg","id":3275593,"avatar_url":"https://avatars.githubusercontent.com/u/3275593?v=3","gravatar_id":"","url":"https://api.github.com/users/pradyunsg","html_url":"https://github.com/pradyunsg","followers_url":"https://api.github.com/users/pradyunsg/followers","following_url":"https://api.github.com/users/pradyunsg/following{/other_user}","gists_url":"https://api.github.com/users/pradyunsg/gists{/gist_id}","starred_url":"https://api.github.com/users/pradyunsg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pradyunsg/subscriptions","organizations_url":"https://api.github.com/users/pradyunsg/orgs","repos_url":"https://api.github.com/users/pradyunsg/repos","events_url":"https://api.github.com/users/pradyunsg/events{/privacy}","received_events_url":"https://api.github.com/users/pradyunsg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pradyunsg/JSON.minify","description":"Simple minifier for JSON to remove comments and whitespace","fork":true,"url":"https://api.github.com/repos/pradyunsg/JSON.minify","forks_url":"https://api.github.com/repos/pradyunsg/JSON.minify/forks","keys_url":"https://api.github.com/repos/pradyunsg/JSON.minify/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pradyunsg/JSON.minify/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pradyunsg/JSON.minify/teams","hooks_url":"https://api.github.com/repos/pradyunsg/JSON.minify/hooks","issue_events_url":"https://api.github.com/repos/pradyunsg/JSON.minify/issues/events{/number}","events_url":"https://api.github.com/repos/pradyunsg/JSON.minify/events","assignees_url":"https://api.github.com/repos/pradyunsg/JSON.minify/assignees{/user}","branches_url":"https://api.github.com/repos/pradyunsg/JSON.minify/branches{/branch}","tags_url":"https://api.github.com/repos/pradyunsg/JSON.minify/tags","blobs_url":"https://api.github.com/repos/pradyunsg/JSON.minify/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pradyunsg/JSON.minify/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pradyunsg/JSON.minify/git/refs{/sha}","trees_url":"https://api.github.com/repos/pradyunsg/JSON.minify/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pradyunsg/JSON.minify/statuses/{sha}","languages_url":"https://api.github.com/repos/pradyunsg/JSON.minify/languages","stargazers_url":"https://api.github.com/repos/pradyunsg/JSON.minify/stargazers","contributors_url":"https://api.github.com/repos/pradyunsg/JSON.minify/contributors","subscribers_url":"https://api.github.com/repos/pradyunsg/JSON.minify/subscribers","subscription_url":"https://api.github.com/repos/pradyunsg/JSON.minify/subscription","commits_url":"https://api.github.com/repos/pradyunsg/JSON.minify/commits{/sha}","git_commits_url":"https://api.github.com/repos/pradyunsg/JSON.minify/git/commits{/sha}","comments_url":"https://api.github.com/repos/pradyunsg/JSON.minify/comments{/number}","issue_comment_url":"https://api.github.com/repos/pradyunsg/JSON.minify/issues/comments{/number}","contents_url":"https://api.github.com/repos/pradyunsg/JSON.minify/contents/{+path}","compare_url":"https://api.github.com/repos/pradyunsg/JSON.minify/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pradyunsg/JSON.minify/merges","archive_url":"https://api.github.com/repos/pradyunsg/JSON.minify/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pradyunsg/JSON.minify/downloads","issues_url":"https://api.github.com/repos/pradyunsg/JSON.minify/issues{/number}","pulls_url":"https://api.github.com/repos/pradyunsg/JSON.minify/pulls{/number}","milestones_url":"https://api.github.com/repos/pradyunsg/JSON.minify/milestones{/number}","notifications_url":"https://api.github.com/repos/pradyunsg/JSON.minify/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pradyunsg/JSON.minify/labels{/name}","releases_url":"https://api.github.com/repos/pradyunsg/JSON.minify/releases{/id}","created_at":"2014-04-03T16:15:09Z","updated_at":"2015-01-01T07:35:55Z","pushed_at":"2015-06-15T07:05:16Z","git_url":"git://github.com/pradyunsg/JSON.minify.git","ssh_url":"git@github.com:pradyunsg/JSON.minify.git","clone_url":"https://github.com/pradyunsg/JSON.minify.git","svn_url":"https://github.com/pradyunsg/JSON.minify","homepage":"http://blog.getify.com/2010/06/json-comments/","size":193,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"getify:java","ref":"java","sha":"a6a6c31d909ce5f7646a4c77b37faa61a78f792e","user":{"login":"getify","id":150330,"avatar_url":"https://avatars.githubusercontent.com/u/150330?v=3","gravatar_id":"","url":"https://api.github.com/users/getify","html_url":"https://github.com/getify","followers_url":"https://api.github.com/users/getify/followers","following_url":"https://api.github.com/users/getify/following{/other_user}","gists_url":"https://api.github.com/users/getify/gists{/gist_id}","starred_url":"https://api.github.com/users/getify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getify/subscriptions","organizations_url":"https://api.github.com/users/getify/orgs","repos_url":"https://api.github.com/users/getify/repos","events_url":"https://api.github.com/users/getify/events{/privacy}","received_events_url":"https://api.github.com/users/getify/received_events","type":"User","site_admin":false},"repo":{"id":733754,"name":"JSON.minify","full_name":"getify/JSON.minify","owner":{"login":"getify","id":150330,"avatar_url":"https://avatars.githubusercontent.com/u/150330?v=3","gravatar_id":"","url":"https://api.github.com/users/getify","html_url":"https://github.com/getify","followers_url":"https://api.github.com/users/getify/followers","following_url":"https://api.github.com/users/getify/following{/other_user}","gists_url":"https://api.github.com/users/getify/gists{/gist_id}","starred_url":"https://api.github.com/users/getify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getify/subscriptions","organizations_url":"https://api.github.com/users/getify/orgs","repos_url":"https://api.github.com/users/getify/repos","events_url":"https://api.github.com/users/getify/events{/privacy}","received_events_url":"https://api.github.com/users/getify/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/getify/JSON.minify","description":"Simple minifier for JSON to remove comments and whitespace","fork":false,"url":"https://api.github.com/repos/getify/JSON.minify","forks_url":"https://api.github.com/repos/getify/JSON.minify/forks","keys_url":"https://api.github.com/repos/getify/JSON.minify/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getify/JSON.minify/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getify/JSON.minify/teams","hooks_url":"https://api.github.com/repos/getify/JSON.minify/hooks","issue_events_url":"https://api.github.com/repos/getify/JSON.minify/issues/events{/number}","events_url":"https://api.github.com/repos/getify/JSON.minify/events","assignees_url":"https://api.github.com/repos/getify/JSON.minify/assignees{/user}","branches_url":"https://api.github.com/repos/getify/JSON.minify/branches{/branch}","tags_url":"https://api.github.com/repos/getify/JSON.minify/tags","blobs_url":"https://api.github.com/repos/getify/JSON.minify/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getify/JSON.minify/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getify/JSON.minify/git/refs{/sha}","trees_url":"https://api.github.com/repos/getify/JSON.minify/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getify/JSON.minify/statuses/{sha}","languages_url":"https://api.github.com/repos/getify/JSON.minify/languages","stargazers_url":"https://api.github.com/repos/getify/JSON.minify/stargazers","contributors_url":"https://api.github.com/repos/getify/JSON.minify/contributors","subscribers_url":"https://api.github.com/repos/getify/JSON.minify/subscribers","subscription_url":"https://api.github.com/repos/getify/JSON.minify/subscription","commits_url":"https://api.github.com/repos/getify/JSON.minify/commits{/sha}","git_commits_url":"https://api.github.com/repos/getify/JSON.minify/git/commits{/sha}","comments_url":"https://api.github.com/repos/getify/JSON.minify/comments{/number}","issue_comment_url":"https://api.github.com/repos/getify/JSON.minify/issues/comments{/number}","contents_url":"https://api.github.com/repos/getify/JSON.minify/contents/{+path}","compare_url":"https://api.github.com/repos/getify/JSON.minify/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getify/JSON.minify/merges","archive_url":"https://api.github.com/repos/getify/JSON.minify/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getify/JSON.minify/downloads","issues_url":"https://api.github.com/repos/getify/JSON.minify/issues{/number}","pulls_url":"https://api.github.com/repos/getify/JSON.minify/pulls{/number}","milestones_url":"https://api.github.com/repos/getify/JSON.minify/milestones{/number}","notifications_url":"https://api.github.com/repos/getify/JSON.minify/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getify/JSON.minify/labels{/name}","releases_url":"https://api.github.com/repos/getify/JSON.minify/releases{/id}","created_at":"2010-06-22T12:25:20Z","updated_at":"2015-11-21T13:00:37Z","pushed_at":"2015-11-28T05:54:56Z","git_url":"git://github.com/getify/JSON.minify.git","ssh_url":"git@github.com:getify/JSON.minify.git","clone_url":"https://github.com/getify/JSON.minify.git","svn_url":"https://github.com/getify/JSON.minify","homepage":"http://blog.getify.com/2010/06/json-comments/","size":103,"stargazers_count":227,"watchers_count":227,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":63,"mirror_url":null,"open_issues_count":10,"forks":63,"open_issues":10,"watchers":227,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getify/JSON.minify/pulls/27"},"html":{"href":"https://github.com/getify/JSON.minify/pull/27"},"issue":{"href":"https://api.github.com/repos/getify/JSON.minify/issues/27"},"comments":{"href":"https://api.github.com/repos/getify/JSON.minify/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/getify/JSON.minify/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/getify/JSON.minify/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getify/JSON.minify/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/getify/JSON.minify/statuses/493dbaf1a37c9da67a2aaa18f554c337baf83792"}}}}