+2008-08-28 Bastien Nocera <hadess@hadess.net>
+
+ Bug 548612 – g_strstr_len() should use memmem when available
+
+ * glib/tests/strfuncs.c (test_strstr):
+ * tests/string-test.c (main): Patch by Paolo Borelli
+ <pborelli@katamail.com> to move the tests to the right place,
+ and add more tests
+
+ * glib/gstrfuncs.c (g_strstr_len): Fix problem with memmem ignoring
+ nul-terminators in strings, and using the haystack_len instead
+
2008-08-28 Bastien Nocera <hadess@hadess.net>
Bug 548612 – g_strstr_len() should use memmem when available
res = g_strstr_len (haystack, 6, "FooBarFooBarFooBar");
g_assert (res == NULL);
+ res = g_strstr_len (haystack, 3, "Bar");
+ g_assert (res == NULL);
+
res = g_strstr_len (haystack, 6, "");
g_assert (res == haystack);
+ g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
res = g_strstr_len (haystack, 6, "Bar");
+ g_assert (res == haystack + 3);
+ g_assert_cmpstr (res, ==, "BarFooBarFoo");
+
+ res = g_strstr_len (haystack, -1, "Bar");
+ g_assert (res == haystack + 3);
g_assert_cmpstr (res, ==, "BarFooBarFoo");
/* strrstr */
res = g_strrstr (haystack, "");
g_assert (res == haystack);
+ g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
res = g_strrstr (haystack, "Bar");
+ g_assert (res == haystack + 9);
g_assert_cmpstr (res, ==, "BarFoo");
/* strrstr_len */
res = g_strrstr_len (haystack, 14, "FooBarFooBarFooBar");
g_assert (res == NULL);
+ res = g_strrstr_len (haystack, 3, "Bar");
+ g_assert (res == NULL);
+
res = g_strrstr_len (haystack, 14, "BarFoo");
+ g_assert (res == haystack + 3);
g_assert_cmpstr (res, ==, "BarFooBarFoo");
+ res = g_strrstr_len (haystack, 15, "BarFoo");
+ g_assert (res == haystack + 9);
+ g_assert_cmpstr (res, ==, "BarFoo");
+
+ res = g_strrstr_len (haystack, -1, "BarFoo");
+ g_assert (res == haystack + 9);
+ g_assert_cmpstr (res, ==, "BarFoo");
+
+ /* test case for strings with \0 in the middle */
+ *(haystack + 7) = '\0';
+ res = g_strstr_len (haystack, 15, "BarFoo");
+ g_assert (res == NULL);
+
g_free (haystack);
}