# HG changeset patch # User Mike Becker # Date 1427789856 -7200 # Node ID f43bbd33fec087590c79c41845109cbef46e4440 # Parent 63f87e2884c103cf723b3100cc8bcb7439696e5f sstrtrim now uses isspace() diff -r 63f87e2884c1 -r f43bbd33fec0 ucx/string.c --- a/ucx/string.c Mon Jul 28 15:10:22 2014 +0200 +++ b/ucx/string.c Tue Mar 31 10:17:36 2015 +0200 @@ -29,6 +29,7 @@ #include #include #include +#include #include "string.h" #include "allocator.h" @@ -296,37 +297,14 @@ sstr_t sstrtrim(sstr_t string) { sstr_t newstr = string; - if (string.length == 0) { - return newstr; + + while (newstr.length > 0 && isspace(*newstr.ptr)) { + newstr.ptr++; + newstr.length--; } - - size_t i; - for(i=0;i 32) { - break; - } + while (newstr.length > 0 && isspace(newstr.ptr[newstr.length-1])) { + newstr.length--; } - newstr.ptr = &string.ptr[i]; - newstr.length = string.length - i; - - if(newstr.length == 0) { - return newstr; - } - - i = newstr.length - 1; - for(;;) { - char c = newstr.ptr[i]; - if(c > 32) { - break; - } - if(i > 0) { - i--; - } else { - break; - } - } - newstr.length = i + 1; return newstr; }