GitHub PullRequestReviewCommentEvent at 2014-03-16 19:45:15
Repository: phobos
Actor: JakobOvrum
Payload: {"comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/10641257","id":10641257,"diff_hunk":"@@ -927,6 +927,377 @@ unittest\n     }\n }\n \n+private ptrdiff_t indexOfAnyImpl(bool direction, Char, Char2)(\n+        const(Char)[] haystack, const(Char2)[] needles, \n+        CaseSensitive cs = CaseSensitive.yes) @safe pure\n+    if (isSomeChar!Char && isSomeChar!Char2)\n+{\n+    if (cs == CaseSensitive.yes)\n+    {\n+        static if (direction)\n+        {\n+            size_t n = haystack.findAmong(needles).length;\n+            return n ? haystack.length - n : -1;\n+        }\n+        else\n+        {\n+            size_t n = haystack.retro.findAmong(needles).source.length;\n+            if (n) \n+            {\n+                return n - haystack.strideBack(n);\n+            }\n+            return -1;\n+        }\n+\n+    }\n+    else\n+    {\n+        bool toLowerFind(const dchar hay, const(Char2)[] needles)\n+        {\n+            dchar hLow = std.uni.toLower(hay);\n+            foreach (dchar o; needles)\n+            {\n+                dchar oLow = std.uni.toLower(o);\n+                if (hLow == oLow)\n+                {\n+                    return true;\n+                }\n+            }\n+            return false;\n+        }\n+\n+        static if (direction)\n+        {\n+            foreach (i, dchar c; haystack)\n+            {\n+                if (toLowerFind(c, needles))\n+                {\n+                    return i;\n+                }\n+            }\n+        }\n+        else\n+        {\n+            foreach_reverse (i, dchar c; haystack)\n+            {\n+                if (toLowerFind(c, needles))\n+                {\n+                    return i;\n+                }\n+            }\n+        }\n+    }\n+\n+    return -1;\n+}\n+\n+/**\n+    Returns the index of the first occurence of any of the elements in $(D\n+    needles) in $(D haystack). If no element of $(D needles) is not found, \n+    then $(D -1) is returned.\n+\n+    Params:\n+        cs = Indicates whether the comparisons are case sensitive.\n+*/\n+ptrdiff_t indexOfAny(Char,Char2)(const(Char)[] haystack, const(Char2)[] needles,\n+        CaseSensitive cs = CaseSensitive.yes) @safe pure\n+    if (isSomeChar!Char && isSomeChar!Char2)\n+{    \n+    return indexOfAnyImpl!(true)(haystack, needles, cs);\n+}\n+\n+///\n+unittest {\n+    ptrdiff_t i = \"helloWorld\".indexOfAny(\"Wr\");\n+    assert(i == 5);\n+    i = \"öällo world\".indexOfAny(\"lo \");\n+    assert(i == 4, to!string(i));\n+}\n+\n+unittest\n+{\n+    debug(string) printf(\"string.indexOfAny.unittest\\n\");\n+\n+    assertCTFEable!(\n+    {\n+    foreach (S; TypeTuple!(string, wstring, dstring))\n+    {\n+        foreach (T; TypeTuple!(string, wstring, dstring))\n+        {\n+            assert(indexOfAny(cast(S)null, to!T(\"a\")) == -1);\n+            assert(indexOfAny(to!S(\"def\"), to!T(\"rsa\")) == -1);\n+            assert(indexOfAny(to!S(\"abba\"), to!T(\"a\")) == 0);\n+            assert(indexOfAny(to!S(\"def\"), to!T(\"f\")) == 2);\n+            assert(indexOfAny(to!S(\"dfefffg\"), to!T(\"fgh\")) == 1);\n+            assert(indexOfAny(to!S(\"dfeffgfff\"), to!T(\"feg\")) == 1);\n+\n+            assert(indexOfAny(to!S(\"zfeffgfff\"), to!T(\"ACDC\"), \n+                CaseSensitive.no) == -1);\n+            assert(indexOfAny(to!S(\"def\"), to!T(\"MI6\"), \n+                CaseSensitive.no) == -1);\n+            assert(indexOfAny(to!S(\"abba\"), to!T(\"DEA\"), \n+                CaseSensitive.no) == 0);\n+            assert(indexOfAny(to!S(\"def\"), to!T(\"FBI\"), CaseSensitive.no) == 2);\n+            assert(indexOfAny(to!S(\"dfefffg\"), to!T(\"NSA\"), CaseSensitive.no) \n+                == -1);\n+            assert(indexOfAny(to!S(\"dfeffgfff\"), to!T(\"BND\"), \n+                CaseSensitive.no) == 0);\n+\n+            assert(indexOfAny(\"\\u0100\", to!T(\"\\u0100\"), CaseSensitive.no) == 0);\n+        }\n+    }\n+    });\n+}\n+\n+/**\n+    Returns the index of the last occurence of any of the elements in $(D\n+    needles) in $(D haystack). If no element of $(D needles) is not found, \n+    then $(D -1) is returned.\n+\n+    Params:\n+        cs = Indicates whether the comparisons are case sensitive.\n+*/\n+ptrdiff_t lastIndexOfAny(Char,Char2)(const(Char)[] haystack, \n+        const(Char2)[] needles, CaseSensitive cs = CaseSensitive.yes) @safe pure\n+    if (isSomeChar!Char && isSomeChar!Char2)\n+{    \n+    return indexOfAnyImpl!(false)(haystack, needles, cs);\n+}\n+\n+///\n+unittest\n+{\n+    ptrdiff_t i = \"helloWorld\".lastIndexOfAny(\"Wlo\");\n+    assert(i == 8); \n+\n+    i = \"Foo öäöllo world\".lastIndexOfAny(\"öF\");\n+    assert(i == 8);\n+}\n+\n+unittest\n+{\n+    debug(string) printf(\"string.lastIndexOfAny.unittest\\n\");\n+\n+    assertCTFEable!(\n+    {\n+    foreach (S; TypeTuple!(string, wstring, dstring))\n+    {\n+        foreach (T; TypeTuple!(string, wstring, dstring))\n+        {\n+            assert(lastIndexOfAny(cast(S)null, to!T(\"a\")) == -1);\n+            assert(lastIndexOfAny(to!S(\"def\"), to!T(\"rsa\")) == -1);\n+            assert(lastIndexOfAny(to!S(\"abba\"), to!T(\"a\")) == 3);\n+            assert(lastIndexOfAny(to!S(\"def\"), to!T(\"f\")) == 2);\n+            assert(lastIndexOfAny(to!S(\"dfefffg\"), to!T(\"fgh\")) == 6);\n+\n+            ptrdiff_t oeIdx = 9;\n+               if (is(S == wstring) || is(S == dstring))\n+            {\n+                oeIdx = 8;\n+            }\n+\n+            auto foundOeIdx = lastIndexOfAny(to!S(\"dfeffgföf\"), to!T(\"feg\"));\n+            assert(foundOeIdx == oeIdx, to!string(foundOeIdx));\n+\n+            assert(lastIndexOfAny(to!S(\"zfeffgfff\"), to!T(\"ACDC\"), \n+                CaseSensitive.no) == -1);\n+            assert(lastIndexOfAny(to!S(\"def\"), to!T(\"MI6\"), \n+                CaseSensitive.no) == -1);\n+            assert(lastIndexOfAny(to!S(\"abba\"), to!T(\"DEA\"), \n+                CaseSensitive.no) == 3);\n+            assert(lastIndexOfAny(to!S(\"def\"), to!T(\"FBI\"), \n+                CaseSensitive.no) == 2);\n+            assert(lastIndexOfAny(to!S(\"dfefffg\"), to!T(\"NSA\"), \n+                CaseSensitive.no) == -1);\n+\n+            oeIdx = 2;\n+               if (is(S == wstring) || is(S == dstring))\n+            {\n+                oeIdx = 1;\n+            }\n+            assert(lastIndexOfAny(to!S(\"ödfeffgfff\"), to!T(\"BND\"), \n+                CaseSensitive.no) == oeIdx);\n+\n+            assert(lastIndexOfAny(\"\\u0100\", to!T(\"\\u0100\"), \n+                CaseSensitive.no) == 0);\n+        }\n+    }\n+    });\n+}\n+\n+/**\n+    Returns the index of the last occurence of any of the elements in $(D\n+    needles) in $(D haystack). If no element of $(D needles) is not found, \n+    then $(D -1) is returned. The $(D startIdx) slices $(D s) in the following \n+    way $(D haystack[startIdx .. $]). $(D startIdx) represents a codeunit \n+    index in $(D haystack). If the sequence ending at $(D startIdx) does not\n+    represent a well formed codepoint, then a $(XREF utf,UTFException) may be\n+    thrown.\n+\n+    Params:\n+        cs = Indicates whether the comparisons are case sensitive.\n+        startIdx = slices haystack like this $(D haystack[startIdx .. $]). If\n+        the startIdx is greater equal the length of haystack the functions\n+        returns $(D -1).\n+*/\n+ptrdiff_t indexOfAny(Char,Char2)(const(Char)[] haystack, const(Char2)[] needles,\n+        const size_t startIdx, CaseSensitive cs = CaseSensitive.yes) @safe pure\n+    if (isSomeChar!Char && isSomeChar!Char2)\n+{    \n+    if (startIdx < haystack.length)","path":"std/string.d","position":221,"original_position":221,"commit_id":"b4f433f22691e602612dfced04ef81091e560b63","original_commit_id":"431901e5feea249bb414ebb0d187b0ef626b9f72","user":{"login":"JakobOvrum","id":155856,"avatar_url":"https://gravatar.com/avatar/4604ad384160886ea9abf7cae9e9657e?d=https%3A%2F%2Fidenticons.github.com%2F6a443a5ce3b273c7e7896969011ba6cd.png&r=x","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":"Aye, didn't know existing functions did it, consistency is king.\r\n","created_at":"2014-03-16T19:45:15Z","updated_at":"2014-03-16T19:45:15Z","html_url":"https://github.com/D-Programming-Language/phobos/pull/1952#discussion_r10641257","pull_request_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/1952","_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/10641257"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/1952#discussion_r10641257"},"pull_request":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/1952"}}}}