{"action":"created","comment":{"url":"https://api.github.com/repos/ghewgill/neon-lang/pulls/comments/49036938","id":49036938,"diff_hunk":"@@ -0,0 +1,135 @@\n+%|\n+ |  File: encoding\n+ |\n+ |  Functions for encoding and decoding ASCII or Binary data in various formats.\n+ |%\n+IMPORT bitwise\n+\n+EXPORT base64Encode\n+EXPORT base64Decode\n+\n+TYPE State IS ENUM\n+    byte1\n+    byte2\n+    byte3\n+    byte4\n+END ENUM\n+\n+CONSTANT Base64EncodeTable: String := \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\"\n+\n+LET Base64DecodeTable: Array<Number> := [\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0x00 - 0x0f\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0x10 - 0x1f\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  62,  -1,  -1,  -1,  63,    % 0x20 - 0x2f\n+     52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  -1,  -1,  -1,  64,  -1,  -1,    % 0x30 - 0x3f\n+     -1,   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,    % 0x40 - 0x4f\n+     15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  -1,  -1,  -1,  -1,  -1,    % 0x50 - 0x5f\n+     -1,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,    % 0x60 - 0x6f\n+     41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  -1,  -1,  -1,  -1,  -1,    % 0x70 - 0x7f\n+    % This table simply ignores these values.\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0x80 - 0x8f\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0x90 - 0x9f\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0xa0 - 0xaf\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0xb0 - 0xbf\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0xc0 - 0xcf\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0xd0 - 0xdf\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0xe0 - 0xef\n+     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,    % 0xf0 - 0xff\n+]\n+\n+%|\n+ |  Function: base64Encode\n+ |\n+ |  Encodes the provided Bytes into Base64 encoded data.\n+ |\n+ |  Parameters:\n+ |      src - The source data to encode.\n+ |\n+ |%\n+FUNCTION base64Encode(src: Bytes): String\n+    VAR encoded: String := \"\"\n+    VAR char1, char2: Number\n+    VAR status: State := State.byte1\n+\n+    LET source: Array<Number> := src.toArray()\n+\n+    FOR i := 0 TO src.size() - 1 DO\n+        LET char: Number := source[i]\n+        CASE status\n+            WHEN State.byte1 DO\n+                encoded.append(Base64EncodeTable[bitwise.shiftRight32(char, 2)])\n+                char1 := bitwise.and32(bitwise.shiftLeft32(char, 4), 0b00110000)\n+                status := State.byte2\n+            WHEN State.byte2 DO\n+                encoded.append(Base64EncodeTable[bitwise.or32(char1, bitwise.shiftRight32(char, 4))])\n+                char2 := bitwise.and32(bitwise.shiftLeft32(char, 2), 0b00111100)\n+                status := State.byte3\n+            WHEN State.byte3 DO\n+                encoded.append(Base64EncodeTable[bitwise.or32(char2, bitwise.shiftRight32(char, 6))])\n+                encoded.append(Base64EncodeTable[bitwise.and32(char, 0b00111111)])\n+                status := State.byte1\n+        END CASE\n+    END FOR\n+\n+    CASE status\n+        % In base64, when the data being encoded is NOT a multiple of 6 bits, \n+        % needs to be padded.  The following pads the output data and signals \n+        % we've hit the end of the encoded data when decoding.\n+        WHEN State.byte2 DO\n+            encoded.append(Base64EncodeTable[char1])\n+            encoded.append(\"==\")\n+        WHEN State.byte3 DO\n+            encoded.append(Base64EncodeTable[char2])\n+            encoded.append(\"=\")\n+    END CASE\n+    RETURN encoded\n+END FUNCTION\n+\n+%|\n+ |  Function: base64Decode\n+ |\n+ |  Decodes the provided Base64 string data back into binary data.\n+ |\n+ |  Parameters:\n+ |      src - The source Base64 to decode.\n+ |\n+ |%\n+FUNCTION base64Decode(src: String): Bytes\n+    VAR char1, char2, char3: Number := 0\n+    VAR decoded: Array<Number> := []\n+    VAR state: State := State.byte1\n+\n+    FOR i := 0 TO src.length() - 1 DO","path":"lib/encoding.neon","position":102,"original_position":102,"commit_id":"2a482f4588d9d9d6b4db0fd74caa643d3af38b35","original_commit_id":"2a482f4588d9d9d6b4db0fd74caa643d3af38b35","user":{"login":"ghewgill","id":17221,"avatar_url":"https://avatars.githubusercontent.com/u/17221?v=3","gravatar_id":"","url":"https://api.github.com/users/ghewgill","html_url":"https://github.com/ghewgill","followers_url":"https://api.github.com/users/ghewgill/followers","following_url":"https://api.github.com/users/ghewgill/following{/other_user}","gists_url":"https://api.github.com/users/ghewgill/gists{/gist_id}","starred_url":"https://api.github.com/users/ghewgill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghewgill/subscriptions","organizations_url":"https://api.github.com/users/ghewgill/orgs","repos_url":"https://api.github.com/users/ghewgill/repos","events_url":"https://api.github.com/users/ghewgill/events{/privacy}","received_events_url":"https://api.github.com/users/ghewgill/received_events","type":"User","site_admin":false},"body":"And a `FOREACH` here too.","created_at":"2016-01-07T02:41:44Z","updated_at":"2016-01-07T02:41:44Z","html_url":"https://github.com/ghewgill/neon-lang/pull/114#discussion_r49036938","pull_request_url":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114","_links":{"self":{"href":"https://api.github.com/repos/ghewgill/neon-lang/pulls/comments/49036938"},"html":{"href":"https://github.com/ghewgill/neon-lang/pull/114#discussion_r49036938"},"pull_request":{"href":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114"}}},"pull_request":{"url":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114","id":55021823,"html_url":"https://github.com/ghewgill/neon-lang/pull/114","diff_url":"https://github.com/ghewgill/neon-lang/pull/114.diff","patch_url":"https://github.com/ghewgill/neon-lang/pull/114.patch","issue_url":"https://api.github.com/repos/ghewgill/neon-lang/issues/114","number":114,"state":"open","locked":false,"title":"added binary encoding/decoding lib","user":{"login":"gitlarryf","id":8064499,"avatar_url":"https://avatars.githubusercontent.com/u/8064499?v=3","gravatar_id":"","url":"https://api.github.com/users/gitlarryf","html_url":"https://github.com/gitlarryf","followers_url":"https://api.github.com/users/gitlarryf/followers","following_url":"https://api.github.com/users/gitlarryf/following{/other_user}","gists_url":"https://api.github.com/users/gitlarryf/gists{/gist_id}","starred_url":"https://api.github.com/users/gitlarryf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitlarryf/subscriptions","organizations_url":"https://api.github.com/users/gitlarryf/orgs","repos_url":"https://api.github.com/users/gitlarryf/repos","events_url":"https://api.github.com/users/gitlarryf/events{/privacy}","received_events_url":"https://api.github.com/users/gitlarryf/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-04T21:04:21Z","updated_at":"2016-01-07T02:41:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6cd6a595cd1594bfcd0f1fef6ca522a652fbed7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114/commits","review_comments_url":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114/comments","review_comment_url":"https://api.github.com/repos/ghewgill/neon-lang/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ghewgill/neon-lang/issues/114/comments","statuses_url":"https://api.github.com/repos/ghewgill/neon-lang/statuses/2a482f4588d9d9d6b4db0fd74caa643d3af38b35","head":{"label":"gitlarryf:encoding-libs","ref":"encoding-libs","sha":"2a482f4588d9d9d6b4db0fd74caa643d3af38b35","user":{"login":"gitlarryf","id":8064499,"avatar_url":"https://avatars.githubusercontent.com/u/8064499?v=3","gravatar_id":"","url":"https://api.github.com/users/gitlarryf","html_url":"https://github.com/gitlarryf","followers_url":"https://api.github.com/users/gitlarryf/followers","following_url":"https://api.github.com/users/gitlarryf/following{/other_user}","gists_url":"https://api.github.com/users/gitlarryf/gists{/gist_id}","starred_url":"https://api.github.com/users/gitlarryf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitlarryf/subscriptions","organizations_url":"https://api.github.com/users/gitlarryf/orgs","repos_url":"https://api.github.com/users/gitlarryf/repos","events_url":"https://api.github.com/users/gitlarryf/events{/privacy}","received_events_url":"https://api.github.com/users/gitlarryf/received_events","type":"User","site_admin":false},"repo":{"id":25283698,"name":"neon-lang","full_name":"gitlarryf/neon-lang","owner":{"login":"gitlarryf","id":8064499,"avatar_url":"https://avatars.githubusercontent.com/u/8064499?v=3","gravatar_id":"","url":"https://api.github.com/users/gitlarryf","html_url":"https://github.com/gitlarryf","followers_url":"https://api.github.com/users/gitlarryf/followers","following_url":"https://api.github.com/users/gitlarryf/following{/other_user}","gists_url":"https://api.github.com/users/gitlarryf/gists{/gist_id}","starred_url":"https://api.github.com/users/gitlarryf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitlarryf/subscriptions","organizations_url":"https://api.github.com/users/gitlarryf/orgs","repos_url":"https://api.github.com/users/gitlarryf/repos","events_url":"https://api.github.com/users/gitlarryf/events{/privacy}","received_events_url":"https://api.github.com/users/gitlarryf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gitlarryf/neon-lang","description":"Implementation of a simple programming language","fork":true,"url":"https://api.github.com/repos/gitlarryf/neon-lang","forks_url":"https://api.github.com/repos/gitlarryf/neon-lang/forks","keys_url":"https://api.github.com/repos/gitlarryf/neon-lang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gitlarryf/neon-lang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gitlarryf/neon-lang/teams","hooks_url":"https://api.github.com/repos/gitlarryf/neon-lang/hooks","issue_events_url":"https://api.github.com/repos/gitlarryf/neon-lang/issues/events{/number}","events_url":"https://api.github.com/repos/gitlarryf/neon-lang/events","assignees_url":"https://api.github.com/repos/gitlarryf/neon-lang/assignees{/user}","branches_url":"https://api.github.com/repos/gitlarryf/neon-lang/branches{/branch}","tags_url":"https://api.github.com/repos/gitlarryf/neon-lang/tags","blobs_url":"https://api.github.com/repos/gitlarryf/neon-lang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gitlarryf/neon-lang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gitlarryf/neon-lang/git/refs{/sha}","trees_url":"https://api.github.com/repos/gitlarryf/neon-lang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gitlarryf/neon-lang/statuses/{sha}","languages_url":"https://api.github.com/repos/gitlarryf/neon-lang/languages","stargazers_url":"https://api.github.com/repos/gitlarryf/neon-lang/stargazers","contributors_url":"https://api.github.com/repos/gitlarryf/neon-lang/contributors","subscribers_url":"https://api.github.com/repos/gitlarryf/neon-lang/subscribers","subscription_url":"https://api.github.com/repos/gitlarryf/neon-lang/subscription","commits_url":"https://api.github.com/repos/gitlarryf/neon-lang/commits{/sha}","git_commits_url":"https://api.github.com/repos/gitlarryf/neon-lang/git/commits{/sha}","comments_url":"https://api.github.com/repos/gitlarryf/neon-lang/comments{/number}","issue_comment_url":"https://api.github.com/repos/gitlarryf/neon-lang/issues/comments{/number}","contents_url":"https://api.github.com/repos/gitlarryf/neon-lang/contents/{+path}","compare_url":"https://api.github.com/repos/gitlarryf/neon-lang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gitlarryf/neon-lang/merges","archive_url":"https://api.github.com/repos/gitlarryf/neon-lang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gitlarryf/neon-lang/downloads","issues_url":"https://api.github.com/repos/gitlarryf/neon-lang/issues{/number}","pulls_url":"https://api.github.com/repos/gitlarryf/neon-lang/pulls{/number}","milestones_url":"https://api.github.com/repos/gitlarryf/neon-lang/milestones{/number}","notifications_url":"https://api.github.com/repos/gitlarryf/neon-lang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gitlarryf/neon-lang/labels{/name}","releases_url":"https://api.github.com/repos/gitlarryf/neon-lang/releases{/id}","created_at":"2014-10-16T02:48:55Z","updated_at":"2015-01-07T23:20:38Z","pushed_at":"2016-01-07T02:36:50Z","git_url":"git://github.com/gitlarryf/neon-lang.git","ssh_url":"git@github.com:gitlarryf/neon-lang.git","clone_url":"https://github.com/gitlarryf/neon-lang.git","svn_url":"https://github.com/gitlarryf/neon-lang","homepage":null,"size":32183,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ghewgill:master","ref":"master","sha":"898a531a24aa40fb5545413701505069f0db8c7f","user":{"login":"ghewgill","id":17221,"avatar_url":"https://avatars.githubusercontent.com/u/17221?v=3","gravatar_id":"","url":"https://api.github.com/users/ghewgill","html_url":"https://github.com/ghewgill","followers_url":"https://api.github.com/users/ghewgill/followers","following_url":"https://api.github.com/users/ghewgill/following{/other_user}","gists_url":"https://api.github.com/users/ghewgill/gists{/gist_id}","starred_url":"https://api.github.com/users/ghewgill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghewgill/subscriptions","organizations_url":"https://api.github.com/users/ghewgill/orgs","repos_url":"https://api.github.com/users/ghewgill/repos","events_url":"https://api.github.com/users/ghewgill/events{/privacy}","received_events_url":"https://api.github.com/users/ghewgill/received_events","type":"User","site_admin":false},"repo":{"id":22769864,"name":"neon-lang","full_name":"ghewgill/neon-lang","owner":{"login":"ghewgill","id":17221,"avatar_url":"https://avatars.githubusercontent.com/u/17221?v=3","gravatar_id":"","url":"https://api.github.com/users/ghewgill","html_url":"https://github.com/ghewgill","followers_url":"https://api.github.com/users/ghewgill/followers","following_url":"https://api.github.com/users/ghewgill/following{/other_user}","gists_url":"https://api.github.com/users/ghewgill/gists{/gist_id}","starred_url":"https://api.github.com/users/ghewgill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghewgill/subscriptions","organizations_url":"https://api.github.com/users/ghewgill/orgs","repos_url":"https://api.github.com/users/ghewgill/repos","events_url":"https://api.github.com/users/ghewgill/events{/privacy}","received_events_url":"https://api.github.com/users/ghewgill/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ghewgill/neon-lang","description":"Implementation of a simple programming language","fork":false,"url":"https://api.github.com/repos/ghewgill/neon-lang","forks_url":"https://api.github.com/repos/ghewgill/neon-lang/forks","keys_url":"https://api.github.com/repos/ghewgill/neon-lang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ghewgill/neon-lang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ghewgill/neon-lang/teams","hooks_url":"https://api.github.com/repos/ghewgill/neon-lang/hooks","issue_events_url":"https://api.github.com/repos/ghewgill/neon-lang/issues/events{/number}","events_url":"https://api.github.com/repos/ghewgill/neon-lang/events","assignees_url":"https://api.github.com/repos/ghewgill/neon-lang/assignees{/user}","branches_url":"https://api.github.com/repos/ghewgill/neon-lang/branches{/branch}","tags_url":"https://api.github.com/repos/ghewgill/neon-lang/tags","blobs_url":"https://api.github.com/repos/ghewgill/neon-lang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ghewgill/neon-lang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ghewgill/neon-lang/git/refs{/sha}","trees_url":"https://api.github.com/repos/ghewgill/neon-lang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ghewgill/neon-lang/statuses/{sha}","languages_url":"https://api.github.com/repos/ghewgill/neon-lang/languages","stargazers_url":"https://api.github.com/repos/ghewgill/neon-lang/stargazers","contributors_url":"https://api.github.com/repos/ghewgill/neon-lang/contributors","subscribers_url":"https://api.github.com/repos/ghewgill/neon-lang/subscribers","subscription_url":"https://api.github.com/repos/ghewgill/neon-lang/subscription","commits_url":"https://api.github.com/repos/ghewgill/neon-lang/commits{/sha}","git_commits_url":"https://api.github.com/repos/ghewgill/neon-lang/git/commits{/sha}","comments_url":"https://api.github.com/repos/ghewgill/neon-lang/comments{/number}","issue_comment_url":"https://api.github.com/repos/ghewgill/neon-lang/issues/comments{/number}","contents_url":"https://api.github.com/repos/ghewgill/neon-lang/contents/{+path}","compare_url":"https://api.github.com/repos/ghewgill/neon-lang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ghewgill/neon-lang/merges","archive_url":"https://api.github.com/repos/ghewgill/neon-lang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ghewgill/neon-lang/downloads","issues_url":"https://api.github.com/repos/ghewgill/neon-lang/issues{/number}","pulls_url":"https://api.github.com/repos/ghewgill/neon-lang/pulls{/number}","milestones_url":"https://api.github.com/repos/ghewgill/neon-lang/milestones{/number}","notifications_url":"https://api.github.com/repos/ghewgill/neon-lang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ghewgill/neon-lang/labels{/name}","releases_url":"https://api.github.com/repos/ghewgill/neon-lang/releases{/id}","created_at":"2014-08-08T19:59:17Z","updated_at":"2015-05-03T21:47:31Z","pushed_at":"2016-01-07T02:36:51Z","git_url":"git://github.com/ghewgill/neon-lang.git","ssh_url":"git@github.com:ghewgill/neon-lang.git","clone_url":"https://github.com/ghewgill/neon-lang.git","svn_url":"https://github.com/ghewgill/neon-lang","homepage":null,"size":32237,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":27,"forks":2,"open_issues":27,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114"},"html":{"href":"https://github.com/ghewgill/neon-lang/pull/114"},"issue":{"href":"https://api.github.com/repos/ghewgill/neon-lang/issues/114"},"comments":{"href":"https://api.github.com/repos/ghewgill/neon-lang/issues/114/comments"},"review_comments":{"href":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114/comments"},"review_comment":{"href":"https://api.github.com/repos/ghewgill/neon-lang/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ghewgill/neon-lang/pulls/114/commits"},"statuses":{"href":"https://api.github.com/repos/ghewgill/neon-lang/statuses/2a482f4588d9d9d6b4db0fd74caa643d3af38b35"}}}}