[Freeswitch-svn] [commit] r11777 - in freeswitch/trunk/libs/sofia-sip: . libsofia-sip-ua/su

FreeSWITCH SVN mikej at freeswitch.org
Wed Feb 11 08:16:52 PST 2009


Author: mikej
Date: Wed Feb 11 10:16:52 2009
New Revision: 11777

Log:
Thu Jan  8 12:04:21 CST 2009  Pekka Pessi <first.last at nokia.com>
  * sofia-sip/su_string.h: added
  
  Adding locale-independent, NULL-safe string comparison, 
  matching and searching functions:
  - su_strcmp()
  - su_strncmp()
  - su_strcasecmp()
  - su_strncasecmp()
  - su_strmatch()
  - su_strnmatch()
  - su_casematch()
  - su_casenmatch()
  - su_strcasestr()
  - su_strnspn()
  - su_strncspn()
  - su_memspn()
  - su_memcspn()



Modified:
   freeswitch/trunk/libs/sofia-sip/.update
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/Makefile.am
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/test_memmem.c

Modified: freeswitch/trunk/libs/sofia-sip/.update
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/.update	(original)
+++ freeswitch/trunk/libs/sofia-sip/.update	Wed Feb 11 10:16:52 2009
@@ -1 +1 @@
-Wed Feb 11 10:15:25 CST 2009
+Wed Feb 11 10:16:40 CST 2009

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/Makefile.am	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/Makefile.am	Wed Feb 11 10:16:52 2009
@@ -54,7 +54,7 @@
 			sofia-sip/su_config.h sofia-sip/su_md5.h \
 			sofia-sip/su_uniqueid.h sofia-sip/su_bm.h \
 			sofia-sip/tstdef.h sofia-sip/su_os_nw.h \
-			sofia-sip/string0.h \
+			sofia-sip/su_string.h sofia-sip/string0.h \
 			$(OSXHEADERS)
 
 nobase_nodist_include_sofia_HEADERS = sofia-sip/su_configure.h
@@ -73,11 +73,12 @@
 	su_os_nw.c \
 	su_taglist.c su_tag.c su_tag_io.c \
 	su_log.c su_global_log.c su_default_log.c su_module_debug.h \
-	su_md5.c su_uniqueid.c su_bm.c smoothsort.c string0.c $(OSXSOURCES)
+	su_md5.c su_uniqueid.c su_bm.c smoothsort.c su_string.c string0.c \
+	$(OSXSOURCES)
 
 
 EXTRA_libsu_la_SOURCES = \
-			memmem.c strtoull.c strcasestr.c \
+			memmem.c strtoull.c \
 			memspn.c memcspn.c memccpy.c \
 			inet_ntop.c inet_pton.c poll.c getopt.c \
 			su_tag_ref.c

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/test_memmem.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/test_memmem.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/test_memmem.c	Wed Feb 11 10:16:52 2009
@@ -22,11 +22,11 @@
  *
  */
 
-/**@ingroup test_memmem
+/**@ingroup test_su_string
  *
  * @CFILE test_memmem.c
  *
- * Torture tests for memmem() and strcasestr().
+ * Torture tests for various string utility functions.
  *
  * @author Pekka Pessi <Pekka.Pessi at nokia.com>
  *
@@ -35,6 +35,8 @@
 
 #include "config.h"
 
+#include <sofia-sip/su_string.h>
+
 #include <stddef.h>
 #include <stdlib.h>
 #include <limits.h>
@@ -45,9 +47,6 @@
 void *memmem(const void *haystack, size_t haystacklen,
 	     const void *needle, size_t needlelen);
 #endif
-#if !HAVE_STRCASESTR
-char *strcasestr(const char *haystack, const char *needle);
-#endif
 
 #include <string.h>
 
@@ -116,38 +115,38 @@
       "A case-folding string searching test consisting of a Long String";
     char const *s;
 
-    s = strcasestr(hs, "sting");
+    s = su_strcasestr(hs, "sting");
     TEST_S(s, hs + 42);
 
-    s = strcasestr(hs, "String");
+    s = su_strcasestr(hs, "String");
     TEST_S(s, hs + 15);
 
-    s = strcasestr(hs, "S");
+    s = su_strcasestr(hs, "S");
     TEST_S(s, hs + 4);
 
-    s = strcasestr(hs, "L");
+    s = su_strcasestr(hs, "L");
     TEST_S(s, hs + 9);
 
-    s = strcasestr(hs, "trings");
+    s = su_strcasestr(hs, "trings");
     TEST_1(s == NULL);
 
-    s = strcasestr(hs, "String");
+    s = su_strcasestr(hs, "String");
     TEST_S(s, hs + 15);
 
-    s = strcasestr(hs, "StRiNg");
+    s = su_strcasestr(hs, "StRiNg");
     TEST_S(s, hs + 15);
 
-    s = strcasestr(hs, "OnG");
+    s = su_strcasestr(hs, "OnG");
     TEST_S(s, hs + 54);
 
     /* Special cases */
-    TEST_1(strcasestr(hs, "") == hs);
-    TEST_1(strcasestr("", "ong") == NULL);
-    TEST_1(strcasestr("", "OnG") == NULL);
-    TEST_1(strcasestr("ong", hs) == NULL);
-    TEST_1(strcasestr("OnG", hs) == NULL);
-    TEST_1(strcasestr(hs, "Z") == NULL);
-    TEST_1(strcasestr(hs, "z") == NULL);
+    TEST_1(su_strcasestr(hs, "") == hs);
+    TEST_1(su_strcasestr("", "ong") == NULL);
+    TEST_1(su_strcasestr("", "OnG") == NULL);
+    TEST_1(su_strcasestr("ong", hs) == NULL);
+    TEST_1(su_strcasestr("OnG", hs) == NULL);
+    TEST_1(su_strcasestr(hs, "Z") == NULL);
+    TEST_1(su_strcasestr(hs, "z") == NULL);
   }
 
   {
@@ -219,16 +218,114 @@
 
     char const *s;
 
-    s = strcasestr(hs, needle);
+    s = su_strcasestr(hs, needle);
     TEST_S(s, hs + 1920);
 
-    s = strcasestr(hs, Needle);
+    s = su_strcasestr(hs, Needle);
     TEST_S(s, hs + 1920);
   }
 
   END();
 }
 
+static int test_casematch(void)
+{
+  BEGIN();
+
+  TEST_1(!su_casematch(NULL, ""));
+  TEST_1(su_casematch(NULL, NULL));
+  TEST_1(!su_casematch("", NULL));
+
+  TEST_1(!su_casenmatch(NULL, "", 1));
+  TEST_1(su_casenmatch(NULL, NULL, 1));
+  TEST_1(!su_casenmatch("", NULL, 1));
+
+  TEST_1(su_casenmatch(NULL, "", 0));
+  TEST_1(su_casenmatch(NULL, NULL, 0));
+  TEST_1(su_casenmatch("", NULL, 0));
+
+  TEST_1(su_casenmatch("foo", "foo", 3));
+  TEST_1(su_casenmatch("FOO", "foo", 3));
+  TEST_1(su_casenmatch("foo", "FOO", 3));
+
+  TEST_1(su_casenmatch("foo", "foo", 4));
+  TEST_1(su_casenmatch("FOO", "foo", 4));
+  TEST_1(su_casenmatch("foo", "FOO", 4));
+
+  TEST_1(su_casematch("foo", "foo"));
+  TEST_1(su_casematch("FOO", "foo"));
+  TEST_1(su_casematch("foo", "FOO"));
+
+  TEST_1(!su_casematch("foo_", "foo"));
+  TEST_1(!su_casematch("FOO_", "foo"));
+  TEST_1(!su_casematch("foo_", "FOO"));
+
+  TEST_1(su_casenmatch("foo\0X", "foo\0z", 5));
+  TEST_1(su_casenmatch("FOO\0X", "foo\0z", 5));
+  TEST_1(su_casenmatch("foo\0X", "FOO\0z", 5));
+
+  END();
+}
+
+static int test_strmatch(void)
+{
+  BEGIN();
+
+  TEST_1(!su_strmatch(NULL, ""));
+  TEST_1(su_strmatch(NULL, NULL));
+  TEST_1(!su_strmatch("", NULL));
+
+  TEST_1(!su_strnmatch(NULL, "", 1));
+  TEST_1(su_strnmatch(NULL, NULL, 1));
+  TEST_1(!su_strnmatch("", NULL, 1));
+
+  TEST_1(su_strnmatch(NULL, "", 0));
+  TEST_1(su_strnmatch(NULL, NULL, 0));
+  TEST_1(su_strnmatch("", NULL, 0));
+
+  TEST_1(su_strnmatch("foo", "foo", 3));
+  TEST_1(!su_strnmatch("FOO", "foo", 3));
+  TEST_1(!su_strnmatch("foo", "FOO", 3));
+
+  TEST_1(su_strnmatch("foo", "foo", 4));
+  TEST_1(!su_strnmatch("FOO", "foo", 4));
+  TEST_1(!su_strnmatch("foo", "FOO", 4));
+
+  TEST_1(su_strmatch("foo", "foo"));
+  TEST_1(!su_strmatch("FOO", "foo"));
+  TEST_1(!su_strmatch("foo", "FOO"));
+
+  TEST_1(!su_strmatch("foo_", "foo"));
+
+  TEST_1(su_strnmatch("foo\0X", "foo\0z", 5));
+  TEST_1(!su_strnmatch("FOO\0X", "foo\0z", 5));
+  TEST_1(!su_strnmatch("foo\0X", "FOO\0z", 5));
+
+  END();
+}
+
+static int test_strnspn(void)
+{
+  BEGIN();
+
+  TEST(su_strnspn("foobar", 3, ""), 0);
+  TEST(su_strnspn("foobar", 5, "fo"), 3);
+  TEST(su_strnspn("foobar", 5, "o"), 0);
+  TEST(su_strnspn("foobar", 5, "f"), 1);
+  TEST(su_strnspn("", 5, "fo"), 0);
+  TEST(su_strnspn("foobarf", 5, "fob"), 4);
+
+  TEST(su_strncspn("foobar", 3, ""), 3);
+  TEST(su_strncspn("foobar", 5, "bach"), 3);
+  TEST(su_strncspn("foobar", 5, "ri"), 5);
+  TEST(su_strncspn("foobar", 5, "b"), 3);
+  TEST(su_strncspn("", 5, "fo"), 0);
+  TEST(su_strncspn(NULL, 0, "fo"), 0);
+  TEST(su_strncspn("foobarf", 5, "a"), 4);
+
+  END();
+}
+
 int main(int argc, char *argv[])
 {
   int retval = 0;
@@ -247,7 +344,10 @@
   retval |= test_pattern(); fflush(stdout);
   retval |= test_strcasestr(); fflush(stdout);
 
+  retval |= test_casematch(); fflush(stdout);
+  retval |= test_strmatch(); fflush(stdout);
+
+  retval |= test_strnspn(); fflush(stdout);
 
   return retval;
 }
-



More information about the Freeswitch-svn mailing list