core/sm_stringutil.cpp
changeset 1738 cb3be0b31d99
parent 1677 9e81dcf43499
child 1947 e73a1e51833b
     1.1 --- a/core/sm_stringutil.cpp	Sun Dec 02 02:05:55 2007 +0000
     1.2 +++ b/core/sm_stringutil.cpp	Sun Dec 02 02:10:37 2007 +0000
     1.3 @@ -1275,3 +1275,34 @@
     1.4  
     1.5  	return NULL;
     1.6  }
     1.7 +
     1.8 +char *UTIL_TrimWhitespace(char *str, size_t &len)
     1.9 +{
    1.10 +	char *end = str + len - 1;
    1.11 +
    1.12 +	if (!len)
    1.13 +	{
    1.14 +		return str;
    1.15 +	}
    1.16 +
    1.17 +	/* Iterate backwards through string until we reach first non-whitespace char */
    1.18 +	while (end >= str && textparsers->IsWhitespace(end))
    1.19 +	{
    1.20 +		end--;
    1.21 +		len--;
    1.22 +	}
    1.23 +
    1.24 +	/* Replace first whitespace char (at the end) with null terminator.
    1.25 +	 * If there is none, we're just replacing the null terminator. 
    1.26 +	 */
    1.27 +	*(end + 1) = '\0';
    1.28 +
    1.29 +	while (*str != '\0' && textparsers->IsWhitespace(str))
    1.30 +	{
    1.31 +		str++;
    1.32 +		len--;
    1.33 +	}
    1.34 +
    1.35 +	return str;
    1.36 +}
    1.37 +