]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
go-format: Accept null precision.
authorBruno Haible <bruno@clisp.org>
Sat, 21 Jun 2025 23:08:15 +0000 (01:08 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 21 Jun 2025 23:08:15 +0000 (01:08 +0200)
* gettext-tools/src/format-go.c: Clarify comment regarding the precision.
(format_parse): Accept a null precision after '.'.
* gettext-tools/tests/format-go-1: Add a test case with null precision.

gettext-tools/src/format-go.c
gettext-tools/tests/format-go-1

index dcf88e127cea99776629c7fece159bd66dcd682d..466d6cd621fbe27269f88674e2c948675a370871 100644 (file)
@@ -44,7 +44,7 @@
      sequence with value <= 1000000,
    - is optionally followed by '.' and a precision specification: '*' (reads an
      argument) or '[m]*' (moves to the m-th argument and reads that argument) or
-     a digit sequence with value <= 1000000,
+     optionally a nonempty digit sequence with value <= 1000000,
    - is optionally followed by '[m]', where m is a digit sequence with a
      positive value <= 1000000,
    - is finished by a specifier
@@ -252,11 +252,12 @@ format_parse (const char *format, bool translated, char *fdi,
         /* Parse precision.  */
         if (*format == '.')
           {
-            if (format[1] == '[')
+            format++;
+            if (*format == '[')
               {
-                if (c_isdigit (format[2]))
+                if (c_isdigit (format[1]))
                   {
-                    const char *f = format + 2;
+                    const char *f = format + 1;
                     unsigned int m = 0;
 
                     do
@@ -312,9 +313,9 @@ format_parse (const char *format, bool translated, char *fdi,
               }
 
             /* Parse precision other than [m]*.  */
-            if (c_isdigit (format[1]))
+            if (c_isdigit (*format))
               {
-                const char *f = format + 1;
+                const char *f = format;
                 unsigned int precision = 0;
 
                 do
@@ -335,7 +336,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
                 format = f;
               }
-            else if (format[1] == '*')
+            else if (*format == '*')
               {
                 unsigned int precision_number = number;
 
@@ -349,7 +350,7 @@ format_parse (const char *format, bool translated, char *fdi,
                 spec.numbered_arg_count++;
 
                 number++;
-                format += 2;
+                format++;
               }
           }
 
index 396fd7c974ca999edb068870d26fe06ef9433c49..1d7cb351ca4d6bd21b22c85375390a5cc1d49f46 100755 (executable)
@@ -58,6 +58,8 @@ cat <<\EOF > f-go-1.data
 "abc%y"
 # Invalid: flags after width
 "abc%2#d"
+# Valid: null precision
+"abc%.f"
 # Invalid: twice precision
 "abc%.4.2d"
 # Valid: three arguments