From 8c4569991dfd46082cc84da5549aff3b50fb1b05 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Fri, 28 Feb 2014 23:14:18 +0100 Subject: [PATCH] Fix indentation and formatting of str_clean_whitespaces (cherry picked from commit https://github.com/teeworlds/teeworlds/commit/b9c40863828681988554c1d847673fea2ddc2ff2) --- src/base/system.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 7d1ad6019..93d63d08b 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -2423,30 +2423,33 @@ void str_sanitize_filename(char *str_in) /* removes leading and trailing spaces and limits the use of multiple spaces */ void str_clean_whitespaces(char *str_in) { - char* r = str_in; - int c = 0; - - while(*r == ' ') - ++r; - - while(*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) { - for(; *r == ' '; ++r) - c = 1; - - if(*r) + /* skip whitespace */ + int found_whitespace = 0; + for(; *read == ' '; read++) + found_whitespace = 1; + /* if not at the end of the string, put a found whitespace here */ + if(*read) { - if(c) - { - *str_in++ = ' '; - c = 0; - } - - *str_in++ = *r++; - } + if(found_whitespace) + *write++ = ' '; + *write++ = *read++; + } else - *str_in = 0; - } + { + *write = 0; + break; + } + } } char *str_skip_to_whitespace(char *str)