# HG changeset patch # User Olaf Wintermann # Date 1361969608 -3600 # Node ID fbbff331beba197e774f575416f0bb9a852046c7 # Parent ecfdc1c4a552c0e0b3db3f0166e94bb7c557cac4 added sstrtrim diff -r ecfdc1c4a552 -r fbbff331beba ucx/string.c --- a/ucx/string.c Wed Feb 27 13:30:21 2013 +0100 +++ b/ucx/string.c Wed Feb 27 13:53:28 2013 +0100 @@ -161,6 +161,7 @@ sstr_t sstrdup(sstr_t s) { sstr_t newstring; newstring.ptr = (char*) malloc(s.length + 1); + newstring.length = 0; if (newstring.ptr) { newstring.length = s.length; newstring.ptr[newstring.length] = 0; @@ -172,3 +173,26 @@ return newstring; } + +sstr_t sstrtrim(sstr_t string) { + sstr_t newstr = string; + int i; + for(i=0;i 32) { + break; + } + } + newstr.ptr = &string.ptr[i]; + newstr.length = string.length - i; + + for(i=newstr.length-1;i>=0;i--) { + char c = newstr.ptr[i]; + if(c > 32) { + break; + } + } + newstr.length = i + 1; + + return newstr; +} diff -r ecfdc1c4a552 -r fbbff331beba ucx/string.h --- a/ucx/string.h Wed Feb 27 13:30:21 2013 +0100 +++ b/ucx/string.h Wed Feb 27 13:53:28 2013 +0100 @@ -92,6 +92,8 @@ sstr_t sstrdup(sstr_t s); +sstr_t sstrtrim(sstr_t string); + #ifdef __cplusplus } #endif