Commit 91a0e640 authored by Pekka Pessi's avatar Pekka Pessi

su_string.c: fixed su_strcasestr()

darcs-hash:20090108201149-db55f-a1c45995433f7631f142aa869c9d3f3c25449440.gz
parent 39f0d052
......@@ -55,7 +55,7 @@ su_strcasestr(const char *haystack,
lcn = ucn = needle[0];
if ('A' <= lcn && lcn <= 'Z')
lcn += 'a' - 'A';
else if ('a' <= ucn && ucn <= 'Z')
else if ('a' <= ucn && ucn <= 'z')
ucn += 'A' - 'a';
if (lcn == 0)
......@@ -71,6 +71,8 @@ su_strcasestr(const char *haystack,
return NULL;
if (n == h)
continue;
if ((n ^ h) != ('A' ^ 'a'))
break;
if ('A' <= n && n <= 'Z')
n += 'a' - 'A';
else if ('A' <= h && h <= 'Z')
......
......@@ -147,6 +147,9 @@ int test_strcasestr(void)
TEST_1(su_strcasestr("OnG", hs) == NULL);
TEST_1(su_strcasestr(hs, "Z") == NULL);
TEST_1(su_strcasestr(hs, "z") == NULL);
TEST_S(su_strcasestr("foobar", "OB"), "obar");
TEST_S(su_strcasestr("FOOBAR", "ob"), "OBAR");
}
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment