]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
PHP: Support newer format string directives.
authorBruno Haible <bruno@clisp.org>
Sat, 21 Sep 2024 13:11:51 +0000 (15:11 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 21 Sep 2024 13:11:51 +0000 (15:11 +0200)
Reported by José Luis Jiménez Fernández <jjimenez@interhost.com> in
<https://lists.gnu.org/archive/html/bug-gettext/2023-05/msg00037.html>.

* gettext-tools/src/format-php.c (format_parse): Treat E, F, g, G, h, H like
e, f.
* gettext-tools/tests/format-php-1: Test the %E, %F, %g, %G, %h, %H directives.
* gettext-tools/tests/format-php-2: Update type compatibility tests.
* NEWS: Mention the change.

NEWS
gettext-tools/src/format-php.c
gettext-tools/tests/format-php-1
gettext-tools/tests/format-php-2

diff --git a/NEWS b/NEWS
index 24be260ee8edb24224bb213f2eaafda2c92d0699..265db1590a650b226ecc631d0c15542dbfd2464c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,8 @@ Version 0.23 - September 2024
   - PHP:
     o Strings with embedded expressions are now recognized.
     o Heredoc and Nowdoc strings are now scanned correctly.
+    o The format string directives %E, %F, %g, %G, %h, %H are now regarded as
+      valid.
 
 * Runtime behaviour:
   - In the C.UTF-8 locale, like in the C locale, the *gettext() functions
index 4a37cfee8c89127d882aca8b398a8beb5b2aec37..8d941401d5e8b5adf9d03b29e1089cf084e9755c 100644 (file)
@@ -1,5 +1,5 @@
 /* PHP format strings.
-   Copyright (C) 2001-2004, 2006-2007, 2009, 2019-2020, 2023 Free Software Foundation, Inc.
+   Copyright (C) 2001-2024 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2002.
 
    This program is free software: you can redistribute it and/or modify
@@ -31,9 +31,9 @@
 
 #define _(str) gettext (str)
 
-/* PHP format strings are described in phpdoc-4.0.6, file
-   phpdoc/manual/function.sprintf.html, and are implemented in
-   php-4.1.0/ext/standard/formatted_print.c.
+/* PHP format strings are described in
+   https://www.php.net/manual/en/function.sprintf.php, and are implemented in
+   php-8.1.0/ext/standard/formatted_print.c.
    A directive
    - starts with '%' or '%m$' where m is a positive integer,
    - is optionally followed by any of the characters '0', '-', ' ', or
@@ -46,7 +46,8 @@
    - is finished by a specifier
        - 's', that needs a string argument,
        - 'b', 'd', 'u', 'o', 'x', 'X', that need an integer argument,
-       - 'e', 'f', that need a floating-point argument,
+       - 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', that need a floating-point
+         argument,
        - 'c', that needs a character argument.
    Additionally there is the directive '%%', which takes no argument.
    Numbered and unnumbered argument specifications can be used in the same
@@ -201,7 +202,8 @@ format_parse (const char *format, bool translated, char *fdi,
               case 'b': case 'd': case 'u': case 'o': case 'x': case 'X':
                 type = FAT_INTEGER;
                 break;
-              case 'e': case 'f':
+              case 'e': case 'E': case 'f': case 'F': case 'g': case 'G':
+              case 'h': case 'H':
                 type = FAT_FLOAT;
                 break;
               case 'c':
index 79583d28e08a930ecf163b806a4e4b7144228d30..a7420375d2c375a336036f207519ce8acd3a07f1 100755 (executable)
@@ -23,7 +23,19 @@ cat <<\EOF > f-ph-1.data
 # Valid: one floating-point argument
 "abc%e"
 # Valid: one floating-point argument
+"abc%E"
+# Valid: one floating-point argument
 "abc%f"
+# Valid: one floating-point argument
+"abc%F"
+# Valid: one floating-point argument
+"abc%g"
+# Valid: one floating-point argument
+"abc%G"
+# Valid: one floating-point argument
+"abc%h"
+# Valid: one floating-point argument
+"abc%H"
 # Valid: one character argument
 "abc%c"
 # Valid: one argument with flags
@@ -40,8 +52,6 @@ cat <<\EOF > f-ph-1.data
 "abc%"
 # Invalid: unknown format specifier
 "abc%y"
-# Invalid: unknown format specifier
-"abc%F"
 # Invalid: flags after width
 "abc%5-f"
 # Invalid: twice precision
index dc6fbc231460fb6f3197ccdfff20c3beaae0058c..9066b955db0be29955882e750d2f21fd705fe5fc 100755 (executable)
@@ -60,7 +60,43 @@ msgid  "abc%X"
 msgstr "xyz%d"
 # Valid: type compatibility
 msgid  "abc%e"
+msgstr "xyz%E"
+# Valid: type compatibility
+msgid  "abc%e"
 msgstr "xyz%f"
+# Valid: type compatibility
+msgid  "abc%e"
+msgstr "xyz%F"
+# Valid: type compatibility
+msgid  "abc%e"
+msgstr "xyz%g"
+# Valid: type compatibility
+msgid  "abc%e"
+msgstr "xyz%G"
+# Valid: type compatibility
+msgid  "abc%e"
+msgstr "xyz%h"
+# Valid: type compatibility
+msgid  "abc%e"
+msgstr "xyz%H"
+# Valid: type compatibility
+msgid  "abc%E"
+msgstr "xyz%f"
+# Valid: type compatibility
+msgid  "abc%E"
+msgstr "xyz%F"
+# Valid: type compatibility
+msgid  "abc%E"
+msgstr "xyz%g"
+# Valid: type compatibility
+msgid  "abc%E"
+msgstr "xyz%G"
+# Valid: type compatibility
+msgid  "abc%E"
+msgstr "xyz%h"
+# Valid: type compatibility
+msgid  "abc%E"
+msgstr "xyz%H"
 # Invalid: type incompatibility
 msgid  "abc%s"
 msgstr "xyz%d"