]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
its: Simplify code.
authorBruno Haible <bruno@clisp.org>
Wed, 27 Mar 2019 20:36:14 +0000 (21:36 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 27 Mar 2019 20:37:24 +0000 (21:37 +0100)
Suggested by Daiki Ueno.

* gettext-tools/src/its.c (normalize_whitespace): Remove local variable.

gettext-tools/src/its.c

index 8b72e1e19ba75ca734239ec6aeef647a75c43c09..d9306cd23f2b4799cecc19908556fdbe7659913e 100644 (file)
@@ -480,28 +480,25 @@ normalize_whitespace (const char *text, enum its_whitespace_type_ty whitespace)
         return result;
       }
     default:
-      /* Normalize whitespaces within the text, but not at the beginning
-         nor the end of the text.  */
+      /* Normalize whitespaces within the text, but do not eliminate whitespace
+         at the beginning nor the end of the text.  */
       {
-        char *result, *p, *out;
-        bool last_ws = false;
+        char *result = xstrdup (text);
+        char *out;
+        const char *p;
 
-        result = xstrdup (text);
-        for (p = out = result; *p != '\0'; p++)
+        out = result;
+        for (p = result; *p != '\0';)
           {
             if (*p == ' ' || *p == '\t' || *p == '\n')
               {
-                if (!last_ws)
-                  {
-                    *out++ = ' ';
-                    last_ws = true;
-                  }
+                do
+                  p++;
+                while (*p == ' ' || *p == '\t' || *p == '\n');
+                *out++ = ' ';
               }
             else
-              {
-                *out++ = *p;
-                last_ws = false;
-              }
+              *out++ = *p++;
           }
         *out = '\0';
         return result;