happy 100th commit + removed deprecated sstrcat + fixed sstrncat

Wed, 27 Feb 2013 16:59:02 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 16:59:02 +0100
changeset 100
e0ec80179a5d
parent 99
4566ef29f16b
child 101
bfd620e092c3

happy 100th commit + removed deprecated sstrcat + fixed sstrncat

g++-debug.mk file | annotate | diff | comparison | revisions
g++.mk file | annotate | diff | comparison | revisions
test/string_tests.c file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
--- a/g++-debug.mk	Wed Feb 27 14:52:52 2013 +0100
+++ b/g++-debug.mk	Wed Feb 27 16:59:02 2013 +0100
@@ -31,7 +31,7 @@
 AR = ar
 RM = rm
 
-CFLAGS  = -std=gnu++11 -g -O2 -fstrict-aliasing -Werror -Wall -pedantic -c
+CFLAGS  = -std=gnu++0x -g -O2 -fstrict-aliasing -Werror -Wall -pedantic -c
 COFLAGS = -o
 LDFLAGS = 
 LOFLAGS = -o
--- a/g++.mk	Wed Feb 27 14:52:52 2013 +0100
+++ b/g++.mk	Wed Feb 27 16:59:02 2013 +0100
@@ -31,7 +31,7 @@
 AR = ar
 RM = rm
 
-CFLAGS  = -std=gnu++11 -O2 -fstrict-aliasing -c
+CFLAGS  = -std=gnu++0x -O2 -fstrict-aliasing -c
 COFLAGS = -o
 LDFLAGS = 
 LOFLAGS = -o
--- a/test/string_tests.c	Wed Feb 27 14:52:52 2013 +0100
+++ b/test/string_tests.c	Wed Feb 27 16:59:02 2013 +0100
@@ -21,22 +21,15 @@
     sstr_t s2 = S(".:.:.");
     sstr_t s3 = S("X");
     
+    size_t len = sstrnlen(3, s1, s2, s3);
     sstr_t cat;
-    
-    size_t len = sstrnlen(3, s1, s2, s3);
+    cat.ptr = (char*) malloc(16);
+    cat.length = 16;
+    cat = sstrncat(3, cat, s1, s2, s3);
     
     UCX_TEST_BEGIN
     
-    UCX_TEST_ASSERT(len == s1.length + s2.length + s3.length,
-            "sstrnlen returned wrong size");
-    
-    len = s1.length + s2.length + s3.length;
-    
-    cat.ptr = (char*) malloc(len + 1);
-    cat.ptr[len] = 0;
-    cat.length = len;
-    
-    sstrncat(3, cat, s1, s2, s3);
+    UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size");
     
     UCX_TEST_ASSERT(cat.ptr[0] == '1', "sstrncat, wrong content");
     UCX_TEST_ASSERT(cat.ptr[1] == '2', "sstrncat, wrong content");
@@ -45,6 +38,7 @@
     UCX_TEST_ASSERT(cat.ptr[4] == '.', "sstrncat, wrong content");
     UCX_TEST_ASSERT(cat.ptr[8] == '.', "sstrncat, wrong content");
     UCX_TEST_ASSERT(cat.ptr[9] == 'X', "sstrncat, wrong content");
+    UCX_TEST_ASSERT(cat.length == 10, "sstrncat, wrong length");
     
     UCX_TEST_END
     
@@ -176,8 +170,8 @@
 }
 
 UCX_TEST_IMPLEMENT(test_sstrtrim) {
-    sstr_t test = sstrtrim(sstr("  ein test   "));
-    sstr_t empty = sstrtrim(sstr(""));
+    sstr_t test = sstrtrim(sstr((char*)"  ein test   "));
+    sstr_t empty = sstrtrim(sstr((char*)""));
     UCX_TEST_BEGIN
     UCX_TEST_ASSERT(strncmp(test.ptr, "ein test", test.length) == 0, "failed");
     UCX_TEST_ASSERT(empty.length == 0, "empty string failed");
--- a/ucx/string.c	Wed Feb 27 14:52:52 2013 +0100
+++ b/ucx/string.c	Wed Feb 27 16:59:02 2013 +0100
@@ -39,21 +39,6 @@
     return size;
 }
 
-sstr_t sstrcat(sstr_t s, ...) {
-    va_list ap;
-    va_start(ap, s);
-    s.ptr[0] = 0;
-
-    sstr_t str = va_arg (ap, sstr_t);
-    while (str.ptr != NULL) {
-        s.ptr = strncat (s.ptr, str.ptr, s.length);
-        str = va_arg (ap, sstr_t);
-    }
-    va_end(ap);
-
-    return s;
-}
-
 sstr_t sstrncat(size_t n, sstr_t s, sstr_t c1, ...) {
     va_list ap;
     va_start(ap, c1);
@@ -78,6 +63,7 @@
         ptr += cplen;
     }
     va_end(ap);
+    s.length = ptr - s.ptr;
 
     return s;
 }

mercurial