X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ftrim.c;h=9581f511f0b0b7a530e615d6d3386ce3ce55ef68;hb=bbfcd2f1a92c9bdbb8d7d7d0a8a8c6665c316747;hp=62f8ebffe5f66532e5fb3d4ba8ef5675c4cb4549;hpb=b2e2010c7c902235b5efb5bd3c6529f61b093aa4;p=gnulib.git diff --git a/lib/trim.c b/lib/trim.c index 62f8ebffe..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 @@ -38,14 +38,14 @@ #endif char * -trim2(const char *s, int how) +trim2 (const char *s, int how) { char *d; - d = strdup(s); + d = strdup (s); if (!d) - xalloc_die(); + xalloc_die (); if (MB_CUR_MAX > 1) { @@ -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; } -