Fri, 21 Jun 2013 10:27:03 +0200
fixed sstrtrim and some warnings
.hgignore | file | annotate | diff | comparison | revisions | |
osx-debug.mk | file | annotate | diff | comparison | revisions | |
osx.mk | file | annotate | diff | comparison | revisions | |
test/Makefile | file | annotate | diff | comparison | revisions | |
test/string_tests.c | file | annotate | diff | comparison | revisions | |
ucx/Makefile | file | annotate | diff | comparison | revisions | |
ucx/string.c | file | annotate | diff | comparison | revisions |
1.1 --- a/.hgignore Thu Feb 28 08:50:24 2013 +0100 1.2 +++ b/.hgignore Fri Jun 21 10:27:03 2013 +0200 1.3 @@ -2,5 +2,6 @@ 1.4 ^nbproject/.*$ 1.5 ^build/.*$ 1.6 core$ 1.7 +DS_Store$ 1.8 ^.c?project$ 1.9 ^.settings/.*$
2.1 --- a/osx-debug.mk Thu Feb 28 08:50:24 2013 +0100 2.2 +++ b/osx-debug.mk Fri Jun 21 10:27:03 2013 +0200 2.3 @@ -26,12 +26,12 @@ 2.4 # POSSIBILITY OF SUCH DAMAGE. 2.5 # 2.6 2.7 -CC = gcc 2.8 -LD = gcc 2.9 +CC = cc 2.10 +LD = cc 2.11 AR = ar 2.12 RM = rm 2.13 2.14 -CFLAGS = -std=gnu99 -g -c 2.15 +CFLAGS = -g -c 2.16 COFLAGS = -o 2.17 LDFLAGS = 2.18 LOFLAGS = -o
3.1 --- a/osx.mk Thu Feb 28 08:50:24 2013 +0100 3.2 +++ b/osx.mk Fri Jun 21 10:27:03 2013 +0200 3.3 @@ -26,12 +26,12 @@ 3.4 # POSSIBILITY OF SUCH DAMAGE. 3.5 # 3.6 3.7 -CC = gcc 3.8 -LD = gcc 3.9 +CC = cc 3.10 +LD = cc 3.11 AR = ar 3.12 RM = rm 3.13 3.14 -CFLAGS = -std=gnu99 -O2 -c 3.15 +CFLAGS = -O2 -c 3.16 COFLAGS = -o 3.17 LDFLAGS = 3.18 LOFLAGS = -o
4.1 --- a/test/Makefile Thu Feb 28 08:50:24 2013 +0100 4.2 +++ b/test/Makefile Fri Jun 21 10:27:03 2013 +0200 4.3 @@ -42,11 +42,11 @@ 4.4 all: ../build/test1 4.5 4.6 ../build/test1: $(OBJ) 4.7 - $(LD) $(LDFLAGS) $(LOFLAGS)../build/test$(APP_EXT) $(OBJ) \ 4.8 + $(LD) $(LDFLAGS) $(LOFLAGS) ../build/test$(APP_EXT) $(OBJ) \ 4.9 ../build/libucx.$(LIB_EXT) 4.10 4.11 ../build/%.$(OBJ_EXT): %.c ../build 4.12 - $(CC) $(CFLAGS) -I../ $(COFLAGS)$@ $< 4.13 + $(CC) $(CFLAGS) -I../ $(COFLAGS) $@ $< 4.14 4.15 ../build: 4.16 mkdir -p build
5.1 --- a/test/string_tests.c Thu Feb 28 08:50:24 2013 +0100 5.2 +++ b/test/string_tests.c Fri Jun 21 10:27:03 2013 +0200 5.3 @@ -194,10 +194,18 @@ 5.4 } 5.5 5.6 UCX_TEST_IMPLEMENT(test_sstrtrim) { 5.7 - sstr_t test = sstrtrim(sstr((char*)" ein test ")); 5.8 + sstr_t t1 = sstrtrim(sstr((char*)" ein test ")); 5.9 + sstr_t t2 = sstrtrim(sstr((char*)"abc")); 5.10 + sstr_t t3 = sstrtrim(sstr((char*)" 123")); 5.11 + sstr_t t4 = sstrtrim(sstr((char*)"xyz ")); 5.12 + sstr_t t5 = sstrtrim(sstr((char*)" ")); 5.13 sstr_t empty = sstrtrim(sstr((char*)"")); 5.14 UCX_TEST_BEGIN 5.15 - UCX_TEST_ASSERT(strncmp(test.ptr, "ein test", test.length) == 0, "failed"); 5.16 + UCX_TEST_ASSERT(strncmp(t1.ptr, "ein test", t1.length) == 0, "failed"); 5.17 + UCX_TEST_ASSERT(strncmp(t2.ptr, "abc", t2.length) == 0, "failed"); 5.18 + UCX_TEST_ASSERT(strncmp(t3.ptr, "123", t3.length) == 0, "failed"); 5.19 + UCX_TEST_ASSERT(strncmp(t4.ptr, "xyz", t4.length) == 0, "failed"); 5.20 + UCX_TEST_ASSERT(t5.length == 0, "string t5 not empty"); 5.21 UCX_TEST_ASSERT(empty.length == 0, "empty string failed"); 5.22 UCX_TEST_END 5.23 }
6.1 --- a/ucx/Makefile Thu Feb 28 08:50:24 2013 +0100 6.2 +++ b/ucx/Makefile Fri Jun 21 10:27:03 2013 +0200 6.3 @@ -45,10 +45,10 @@ 6.4 all: libucx 6.5 6.6 libucx: $(OBJ) 6.7 - $(AR) $(ARFLAGS) $(AOFLAGS)../build/libucx.$(LIB_EXT) $(OBJ) 6.8 + $(AR) $(ARFLAGS) $(AOFLAGS) ../build/libucx.$(LIB_EXT) $(OBJ) 6.9 6.10 ../build/%.$(OBJ_EXT): %.c ../build 6.11 - $(CC) $(CFLAGS) $(COFLAGS)$@ $< 6.12 + $(CC) $(CFLAGS) $(COFLAGS) $@ $< 6.13 6.14 ../build: 6.15 mkdir -p ../build
7.1 --- a/ucx/string.c Thu Feb 28 08:50:24 2013 +0100 7.2 +++ b/ucx/string.c Fri Jun 21 10:27:03 2013 +0200 7.3 @@ -95,7 +95,7 @@ 7.4 7.5 sstr_t sstrsubsl(sstr_t s, size_t start, size_t length) { 7.6 sstr_t new_sstr; 7.7 - if (start < 0 || start >= s.length || length < 0) { 7.8 + if (start >= s.length) { 7.9 return s; 7.10 } 7.11 if (length > s.length-start) { 7.12 @@ -197,11 +197,21 @@ 7.13 newstr.ptr = &string.ptr[i]; 7.14 newstr.length = string.length - i; 7.15 7.16 - for(i=newstr.length-1;i>=0;i--) { 7.17 + if(newstr.length == 0) { 7.18 + return newstr; 7.19 + } 7.20 + 7.21 + i = newstr.length - 1; 7.22 + for(;;) { 7.23 char c = newstr.ptr[i]; 7.24 if(c > 32) { 7.25 break; 7.26 } 7.27 + if(i > 0) { 7.28 + i--; 7.29 + } else { 7.30 + break; 7.31 + } 7.32 } 7.33 newstr.length = i + 1; 7.34