Wed, 27 Feb 2013 13:53:28 +0100
added sstrtrim
ucx/string.c | file | annotate | diff | comparison | revisions | |
ucx/string.h | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/string.c Wed Feb 27 13:30:21 2013 +0100 1.2 +++ b/ucx/string.c Wed Feb 27 13:53:28 2013 +0100 1.3 @@ -161,6 +161,7 @@ 1.4 sstr_t sstrdup(sstr_t s) { 1.5 sstr_t newstring; 1.6 newstring.ptr = (char*) malloc(s.length + 1); 1.7 + newstring.length = 0; 1.8 if (newstring.ptr) { 1.9 newstring.length = s.length; 1.10 newstring.ptr[newstring.length] = 0; 1.11 @@ -172,3 +173,26 @@ 1.12 1.13 return newstring; 1.14 } 1.15 + 1.16 +sstr_t sstrtrim(sstr_t string) { 1.17 + sstr_t newstr = string; 1.18 + int i; 1.19 + for(i=0;i<string.length;i++) { 1.20 + char c = string.ptr[i]; 1.21 + if(c > 32) { 1.22 + break; 1.23 + } 1.24 + } 1.25 + newstr.ptr = &string.ptr[i]; 1.26 + newstr.length = string.length - i; 1.27 + 1.28 + for(i=newstr.length-1;i>=0;i--) { 1.29 + char c = newstr.ptr[i]; 1.30 + if(c > 32) { 1.31 + break; 1.32 + } 1.33 + } 1.34 + newstr.length = i + 1; 1.35 + 1.36 + return newstr; 1.37 +}
2.1 --- a/ucx/string.h Wed Feb 27 13:30:21 2013 +0100 2.2 +++ b/ucx/string.h Wed Feb 27 13:53:28 2013 +0100 2.3 @@ -92,6 +92,8 @@ 2.4 2.5 sstr_t sstrdup(sstr_t s); 2.6 2.7 +sstr_t sstrtrim(sstr_t string); 2.8 + 2.9 #ifdef __cplusplus 2.10 } 2.11 #endif