# HG changeset patch # User Sascha Wilde # Date 1395670307 -3600 # Node ID c719d3fdbc15652ba7445fe559107588f3395579 # Parent 4691d9e3b1d3d2480cbc40b93d9130718fb29df1 Added functrion to trim white space from string. diff -r 4691d9e3b1d3 -r c719d3fdbc15 common/strhelp.c --- a/common/strhelp.c Mon Mar 24 13:35:20 2014 +0100 +++ b/common/strhelp.c Mon Mar 24 15:11:47 2014 +0100 @@ -123,3 +123,14 @@ else return false; } + +void +str_trim (char **s) +{ + size_t i; + while (isspace(**s)) + (*s)++; + i = strlen(*s); + while (isspace((*s)[--i])) + (*s)[i] = '\0'; +} diff -r 4691d9e3b1d3 -r c719d3fdbc15 common/strhelp.h --- a/common/strhelp.h Mon Mar 24 13:35:20 2014 +0100 +++ b/common/strhelp.h Mon Mar 24 15:11:47 2014 +0100 @@ -66,4 +66,13 @@ */ bool str_starts_with (char *s1, char *s2); +/** + * @brief Trims all white space from the start and end of string. + * @details the start of the string is trimmed by setting *s to the + * first non white space character. The end is trimmed by setting the + * first character after the last non white space character to \0. + * @param[inout] s ponter to the string to strip + */ +bool str_trim (char **s); + #endif