GitHub PullRequestReviewCommentEvent at 2014-07-19 14:10:22
Repository: phobos
Actor: quickfur
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/15143874","id":15143874,"diff_hunk":"@@ -4647,96 +4647,64 @@ void main() {\n     });\n }\n \n-/** This function makes the assumption that the passed unsigned integer type\n-array passed is actually a character array.\n+/** Assume the given array of integers $(D arr) is a well-formed UTF string and\n+return it typed as a UTF string.\n \n-$(D ubyte[]) are mapped to $(D char[]), $(D ushort[]) are mapped to\n-$(D wchar[]) and $(D uint[]) are mapped to $(D dchar[]) qualifier are\n-preserved.\n+$(D ubyte) becomes $(D char), $(D ushort) becomes $(D wchar) and $(D uint)\n+becomes $(D dchar). Type qualifiers are preserved.\n \n-See_Also: $(LINK2 std_exception.html,assumeUnique)\n+See_Also: $(LREF representation)\n */\n-auto assumeUTF(T)(T[] t) pure @trusted\n-{\n-\tstatic if(is(T == ubyte))\n-\t{\n-\t\tauto r = cast(char[])t;\n-\t}\n-\telse static if(is(T == const(ubyte)))\n-\t{\n-\t\tauto r = cast(const(char)[])t;\n-\t}\n-\telse static if(is(T == immutable(ubyte)))\n-\t{\n-\t\tauto r = cast(immutable(char)[])t;\n-\t}\n-\telse static if(is(T == ushort))\n-\t{\n-\t\tauto r = cast(wchar[])t;\n-\t}\n-\telse static if(is(T == const(ushort)))\n-\t{\n-\t\tauto r = cast(const(wchar)[])t;\n-\t}\n-\telse static if(is(T == immutable(ushort)))\n-\t{\n-\t\tauto r = cast(immutable(wchar)[])t;\n-\t}\n-\telse static if(is(T == uint))\n-\t{\n-\t\tauto r = cast(dchar[])t;\n-\t}\n-\telse static if(is(T == const(uint)))\n-\t{\n-\t\tauto r = cast(const(dchar)[])t;\n-\t}\n-\telse static if(is(T == immutable(uint)))\n-\t{\n-\t\tauto r = cast(immutable(dchar)[])t;\n-\t}\n-\telse\n-\t{\n-\t\tstatic assert(false,\n-\t\t\t\"assumeUTF only accepts ubyte, ushort or uint arrays not :\" ~\n-\t\t\tT.stringof);\n-\t}\n-\n-\tdebug \n-\t{\n-\t\tvalidate(r);\n-\t}\n-\n-\treturn r;\n+auto assumeUTF(T)(T[] arr) @trusted pure nothrow\n+    if(staticIndexOf!(Unqual!T, ubyte, ushort, uint) != -1)\n+{\n+    alias UTFType = TypeTuple!(char, wchar, dchar)[T.sizeof / 2];\n+\n+    static if(is(T == immutable))\n+        alias U = immutable(UTFType);\n+    else static if(is(T == const))\n+        alias U = const(UTFType);\n+    else\n+        alias U = UTFType;\n+\n+    static if(is(T == shared))\n+        alias SU = shared(U);\n+    else\n+        alias SU = U;\n+\n+    auto asUTF = cast(U[])arr;\n+    debug validate(asUTF);\n+    return asUTF;\n }\n \n ///\n-unittest\n+@safe pure nothrow unittest\n {\n-    char[] a = \"Hölo World\".dup;\n-    ubyte[] b = cast(ubyte[])a;\n-    char[] c = assumeUTF(b);\n+    string a = \"Hölo World\";","path":"std/string.d","position":98,"original_position":98,"commit_id":"f5780519e8f2ca0adbcadfeb039ffb6dafa6ee0d","original_commit_id":"f5780519e8f2ca0adbcadfeb039ffb6dafa6ee0d","user":{"login":"quickfur","id":405446,"avatar_url":"https://avatars.githubusercontent.com/u/405446?","gravatar_id":"bb6f8417aa752588d5eef452479d62e8","url":"https://api.github.com/users/quickfur","html_url":"https://github.com/quickfur","followers_url":"https://api.github.com/users/quickfur/followers","following_url":"https://api.github.com/users/quickfur/following{/other_user}","gists_url":"https://api.github.com/users/quickfur/gists{/gist_id}","starred_url":"https://api.github.com/users/quickfur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quickfur/subscriptions","organizations_url":"https://api.github.com/users/quickfur/orgs","repos_url":"https://api.github.com/users/quickfur/repos","events_url":"https://api.github.com/users/quickfur/events{/privacy}","received_events_url":"https://api.github.com/users/quickfur/received_events","type":"User","site_admin":false},"body":"Why change the unittest from `char[]` to `string`? We should test for both. Not every conversion is with immutable data.","created_at":"2014-07-19T14:10:22Z","updated_at":"2014-07-19T14:10:22Z","html_url":"https://github.com/D-Programming-Language/phobos/pull/2352#discussion_r15143874","pull_request_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352","_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/15143874"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/2352#discussion_r15143874"},"pull_request":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352"}}},"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352","id":18620732,"html_url":"https://github.com/D-Programming-Language/phobos/pull/2352","diff_url":"https://github.com/D-Programming-Language/phobos/pull/2352.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/2352.patch","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2352","number":2352,"state":"open","title":"Fix assumeUTF","user":{"login":"JakobOvrum","id":155856,"avatar_url":"https://avatars.githubusercontent.com/u/155856?","gravatar_id":"4604ad384160886ea9abf7cae9e9657e","url":"https://api.github.com/users/JakobOvrum","html_url":"https://github.com/JakobOvrum","followers_url":"https://api.github.com/users/JakobOvrum/followers","following_url":"https://api.github.com/users/JakobOvrum/following{/other_user}","gists_url":"https://api.github.com/users/JakobOvrum/gists{/gist_id}","starred_url":"https://api.github.com/users/JakobOvrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakobOvrum/subscriptions","organizations_url":"https://api.github.com/users/JakobOvrum/orgs","repos_url":"https://api.github.com/users/JakobOvrum/repos","events_url":"https://api.github.com/users/JakobOvrum/events{/privacy}","received_events_url":"https://api.github.com/users/JakobOvrum/received_events","type":"User","site_admin":false},"body":"Felt [#2341](https://github.com/D-Programming-Language/phobos/pull/2341) completely lacked quality control, so here's a few fixes.\r\n\r\n* Now supports shared (though not tested because `validate` does not support it, but a non-debug build will support it)\r\n* Shortened implementation considerably\r\n* Uses template constraint instead of static assert to reject invalid calls at the call-site\r\n* Documentation now references `representation` instead of `assumeUnique`. The relationship between `assumeUTF` and `assumeUnique` is pure trivia, while `representation` is its counter-function.\r\n* Annotated with nothrow, and annotated unit tests.\r\n* Fixed wrong naming convention used in one of the unit tests.\r\n","created_at":"2014-07-19T13:30:40Z","updated_at":"2014-07-19T14:10:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4d193867ff9bbff2db43feb0973ab3a6c9dec4f5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352/commits","review_comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352/comments","review_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/{number}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2352/comments","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/f5780519e8f2ca0adbcadfeb039ffb6dafa6ee0d","head":{"label":"JakobOvrum:assumeutf","ref":"assumeutf","sha":"f5780519e8f2ca0adbcadfeb039ffb6dafa6ee0d","user":{"login":"JakobOvrum","id":155856,"avatar_url":"https://avatars.githubusercontent.com/u/155856?","gravatar_id":"4604ad384160886ea9abf7cae9e9657e","url":"https://api.github.com/users/JakobOvrum","html_url":"https://github.com/JakobOvrum","followers_url":"https://api.github.com/users/JakobOvrum/followers","following_url":"https://api.github.com/users/JakobOvrum/following{/other_user}","gists_url":"https://api.github.com/users/JakobOvrum/gists{/gist_id}","starred_url":"https://api.github.com/users/JakobOvrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakobOvrum/subscriptions","organizations_url":"https://api.github.com/users/JakobOvrum/orgs","repos_url":"https://api.github.com/users/JakobOvrum/repos","events_url":"https://api.github.com/users/JakobOvrum/events{/privacy}","received_events_url":"https://api.github.com/users/JakobOvrum/received_events","type":"User","site_admin":false},"repo":{"id":6076265,"name":"phobos","full_name":"JakobOvrum/phobos","owner":{"login":"JakobOvrum","id":155856,"avatar_url":"https://avatars.githubusercontent.com/u/155856?","gravatar_id":"4604ad384160886ea9abf7cae9e9657e","url":"https://api.github.com/users/JakobOvrum","html_url":"https://github.com/JakobOvrum","followers_url":"https://api.github.com/users/JakobOvrum/followers","following_url":"https://api.github.com/users/JakobOvrum/following{/other_user}","gists_url":"https://api.github.com/users/JakobOvrum/gists{/gist_id}","starred_url":"https://api.github.com/users/JakobOvrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakobOvrum/subscriptions","organizations_url":"https://api.github.com/users/JakobOvrum/orgs","repos_url":"https://api.github.com/users/JakobOvrum/repos","events_url":"https://api.github.com/users/JakobOvrum/events{/privacy}","received_events_url":"https://api.github.com/users/JakobOvrum/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JakobOvrum/phobos","description":"Runtime library for the D programming language","fork":true,"url":"https://api.github.com/repos/JakobOvrum/phobos","forks_url":"https://api.github.com/repos/JakobOvrum/phobos/forks","keys_url":"https://api.github.com/repos/JakobOvrum/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JakobOvrum/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JakobOvrum/phobos/teams","hooks_url":"https://api.github.com/repos/JakobOvrum/phobos/hooks","issue_events_url":"https://api.github.com/repos/JakobOvrum/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/JakobOvrum/phobos/events","assignees_url":"https://api.github.com/repos/JakobOvrum/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/JakobOvrum/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/JakobOvrum/phobos/tags","blobs_url":"https://api.github.com/repos/JakobOvrum/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JakobOvrum/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JakobOvrum/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/JakobOvrum/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JakobOvrum/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/JakobOvrum/phobos/languages","stargazers_url":"https://api.github.com/repos/JakobOvrum/phobos/stargazers","contributors_url":"https://api.github.com/repos/JakobOvrum/phobos/contributors","subscribers_url":"https://api.github.com/repos/JakobOvrum/phobos/subscribers","subscription_url":"https://api.github.com/repos/JakobOvrum/phobos/subscription","commits_url":"https://api.github.com/repos/JakobOvrum/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/JakobOvrum/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/JakobOvrum/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/JakobOvrum/phobos/issues/comments/{number}","contents_url":"https://api.github.com/repos/JakobOvrum/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/JakobOvrum/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JakobOvrum/phobos/merges","archive_url":"https://api.github.com/repos/JakobOvrum/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JakobOvrum/phobos/downloads","issues_url":"https://api.github.com/repos/JakobOvrum/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/JakobOvrum/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/JakobOvrum/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/JakobOvrum/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JakobOvrum/phobos/labels{/name}","releases_url":"https://api.github.com/repos/JakobOvrum/phobos/releases{/id}","created_at":"2012-10-04T14:09:48Z","updated_at":"2014-03-23T01:50:08Z","pushed_at":"2014-07-19T13:39:48Z","git_url":"git://github.com/JakobOvrum/phobos.git","ssh_url":"git@github.com:JakobOvrum/phobos.git","clone_url":"https://github.com/JakobOvrum/phobos.git","svn_url":"https://github.com/JakobOvrum/phobos","homepage":"d-programming-language.org","size":25457,"stargazers_count":0,"watchers_count":0,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"D-Programming-Language:master","ref":"master","sha":"e119dad7f571d00692770479f90ef117edaa3a26","user":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?","gravatar_id":"1fe90c0586802aee103ff9ac0b8f3fbe","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"repo":{"id":1257084,"name":"phobos","full_name":"D-Programming-Language/phobos","owner":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?","gravatar_id":"1fe90c0586802aee103ff9ac0b8f3fbe","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/D-Programming-Language/phobos","description":"The standard library of the D programming language","fork":false,"url":"https://api.github.com/repos/D-Programming-Language/phobos","forks_url":"https://api.github.com/repos/D-Programming-Language/phobos/forks","keys_url":"https://api.github.com/repos/D-Programming-Language/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/D-Programming-Language/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/D-Programming-Language/phobos/teams","hooks_url":"https://api.github.com/repos/D-Programming-Language/phobos/hooks","issue_events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/events","assignees_url":"https://api.github.com/repos/D-Programming-Language/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/D-Programming-Language/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/tags","blobs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/D-Programming-Language/phobos/languages","stargazers_url":"https://api.github.com/repos/D-Programming-Language/phobos/stargazers","contributors_url":"https://api.github.com/repos/D-Programming-Language/phobos/contributors","subscribers_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscribers","subscription_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscription","commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments/{number}","contents_url":"https://api.github.com/repos/D-Programming-Language/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/D-Programming-Language/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/D-Programming-Language/phobos/merges","archive_url":"https://api.github.com/repos/D-Programming-Language/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/D-Programming-Language/phobos/downloads","issues_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/D-Programming-Language/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/D-Programming-Language/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/labels{/name}","releases_url":"https://api.github.com/repos/D-Programming-Language/phobos/releases{/id}","created_at":"2011-01-15T07:00:06Z","updated_at":"2014-07-18T17:14:25Z","pushed_at":"2014-07-19T12:45:05Z","git_url":"git://github.com/D-Programming-Language/phobos.git","ssh_url":"git@github.com:D-Programming-Language/phobos.git","clone_url":"https://github.com/D-Programming-Language/phobos.git","svn_url":"https://github.com/D-Programming-Language/phobos","homepage":"dlang.org/phobos","size":55158,"stargazers_count":498,"watchers_count":498,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":339,"mirror_url":null,"open_issues_count":66,"forks":339,"open_issues":66,"watchers":498,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/2352"},"issue":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2352"},"comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2352/comments"},"review_comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352/comments"},"review_comment":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2352/commits"},"statuses":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/f5780519e8f2ca0adbcadfeb039ffb6dafa6ee0d"}}}}