fixed sstrtrim for empty strings

Wed, 27 Feb 2013 14:12:28 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 14:12:28 +0100
changeset 98
0a752853f792
parent 97
499e1b465d77
child 99
4566ef29f16b

fixed sstrtrim for empty strings

test/string_tests.c file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
--- a/test/string_tests.c	Wed Feb 27 14:04:45 2013 +0100
+++ b/test/string_tests.c	Wed Feb 27 14:12:28 2013 +0100
@@ -177,7 +177,9 @@
 
 UCX_TEST_IMPLEMENT(test_sstrtrim) {
     sstr_t test = sstrtrim(sstr("  ein test   "));
+    sstr_t empty = sstrtrim(sstr(""));
     UCX_TEST_BEGIN
     UCX_TEST_ASSERT(strncmp(test.ptr, "ein test", test.length) == 0, "failed");
+    UCX_TEST_ASSERT(empty.length == 0, "empty string failed");
     UCX_TEST_END
 }
--- a/ucx/string.c	Wed Feb 27 14:04:45 2013 +0100
+++ b/ucx/string.c	Wed Feb 27 14:12:28 2013 +0100
@@ -176,6 +176,10 @@
 
 sstr_t sstrtrim(sstr_t string) {
     sstr_t newstr = string;
+    if (string.length == 0) {
+        return newstr;
+    }
+    
     size_t i;
     for(i=0;i<string.length;i++) {
         char c = string.ptr[i];

mercurial