X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ftrim.c;h=9581f511f0b0b7a530e615d6d3386ce3ce55ef68;hb=5191b3546cfb6c163228c23f214e325ddf60d46f;hp=c8b0c7fe49eebcbb5f0e46c109f9f3b3944de082;hpb=aeb898d88cddc17cefc7738940b4917e9ee27933;p=gnulib.git diff --git a/lib/trim.c b/lib/trim.c index c8b0c7fe4..9581f511f 100644 --- a/lib/trim.c +++ b/lib/trim.c @@ -1,5 +1,5 @@ /* Removes leading and/or trailing whitespaces - Copyright (C) 2006-2010 Free Software Foundation, Inc. + Copyright (C) 2006-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ #include "mbiter.h" #include "xalloc.h" -/* Use this to suppress gcc's `...may be used before initialized' warnings. */ +/* Use this to suppress gcc's "...may be used before initialized" warnings. */ #ifdef lint # define IF_LINT(Code) Code #else @@ -65,7 +65,7 @@ trim2 (const char *s, int how) /* Trim trailing whitespaces. */ if (how != TRIM_LEADING) { - int state = 0; + unsigned int state = 0; char *r IF_LINT (= NULL); /* used only while state = 2 */ mbi_init (i, d, strlen (d)); @@ -73,10 +73,7 @@ trim2 (const char *s, int how) for (; mbi_avail (i); mbi_advance (i)) { if (state == 0 && mb_isspace (mbi_cur (i))) - { - state = 0; - continue; - } + continue; if (state == 0 && !mb_isspace (mbi_cur (i))) { @@ -85,10 +82,7 @@ trim2 (const char *s, int how) } if (state == 1 && !mb_isspace (mbi_cur (i))) - { - state = 1; - continue; - } + continue; if (state == 1 && mb_isspace (mbi_cur (i))) { @@ -97,7 +91,7 @@ trim2 (const char *s, int how) } else if (state == 2 && mb_isspace (mbi_cur (i))) { - state = 2; + /* empty */ } else { @@ -114,20 +108,22 @@ trim2 (const char *s, int how) char *p; /* Trim leading whitespaces. */ - if (how != TRIM_TRAILING) { - for (p = d; *p && isspace ((unsigned char) *p); p++) - ; + if (how != TRIM_TRAILING) + { + for (p = d; *p && isspace ((unsigned char) *p); p++) + ; - memmove (d, p, strlen (p) + 1); - } + memmove (d, p, strlen (p) + 1); + } /* Trim trailing whitespaces. */ - if (how != TRIM_LEADING) { - for (p = d + strlen (d) - 1; p >= d && isspace ((unsigned char) *p); p--) - *p = '\0'; - } + if (how != TRIM_LEADING) + { + for (p = d + strlen (d) - 1; + p >= d && isspace ((unsigned char) *p); p--) + *p = '\0'; + } } return d; } -