diff --git a/src/base/system.c b/src/base/system.c index f200055a7..efef47d83 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -1913,6 +1913,38 @@ void str_clean_whitespaces(char *str_in) } } +/* removes leading and trailing spaces */ +void str_clean_whitespaces_simple(char *str_in) +{ + char *read = str_in; + char *write = str_in; + + /* skip initial whitespace */ + while(*read == ' ') + read++; + + /* end of read string is detected in the loop */ + while(1) + { + /* skip whitespace */ + int found_whitespace = 0; + for(; *read == ' ' && !found_whitespace; read++) + found_whitespace = 1; + /* if not at the end of the string, put a found whitespace here */ + if(*read) + { + if(found_whitespace) + *write++ = ' '; + *write++ = *read++; + } + else + { + *write = 0; + break; + } + } +} + char *str_skip_to_whitespace(char *str) { while(*str && (*str != ' ' && *str != '\t' && *str != '\n')) @@ -1920,6 +1952,13 @@ char *str_skip_to_whitespace(char *str) return str; } +const char *str_skip_to_whitespace_const(const char *str) +{ + while(*str && (*str != ' ' && *str != '\t' && *str != '\n')) + str++; + return str; +} + char *str_skip_whitespaces(char *str) { while(*str && (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r')) diff --git a/src/base/system.h b/src/base/system.h index a21e4b811..ed5345d28 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -912,6 +912,18 @@ int str_check_pathname(const char* str); */ void str_clean_whitespaces(char *str); +/* + Function: str_clean_whitespaces_simple + Removes leading and trailing spaces + + Parameters: + str - String to clean up + + Remarks: + - The strings are treated as zero-terminated strings. +*/ +void str_clean_whitespaces_simple(char *str); + /* Function: str_skip_to_whitespace Skips leading non-whitespace characters(all but ' ', '\t', '\n', '\r'). @@ -928,6 +940,12 @@ void str_clean_whitespaces(char *str); */ char *str_skip_to_whitespace(char *str); +/* + Function: str_skip_to_whitespace_const + See str_skip_to_whitespace. +*/ +const char *str_skip_to_whitespace_const(const char *str); + /* Function: str_skip_whitespaces Skips leading whitespace characters(' ', '\t', '\n', '\r').