maint: update copyright
[gnulib.git] / lib / trim.c
index 1f4d0c1..742de9b 100644 (file)
@@ -1,5 +1,5 @@
 /* Removes leading and/or trailing whitespaces
-   Copyright (C) 2006-2011 Free Software Foundation, Inc.
+   Copyright (C) 2006-2014 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;
 }
-