From: Bruno Haible Date: Sat, 21 Sep 2024 13:11:51 +0000 (+0200) Subject: PHP: Support newer format string directives. X-Git-Tag: v0.23~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3b3f8e916801a1a3309d13d11916b3fff8d496b;p=thirdparty%2Fgettext.git PHP: Support newer format string directives. Reported by José Luis Jiménez Fernández in . * 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. --- diff --git a/NEWS b/NEWS index 24be260ee..265db1590 100644 --- 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 diff --git a/gettext-tools/src/format-php.c b/gettext-tools/src/format-php.c index 4a37cfee8..8d941401d 100644 --- a/gettext-tools/src/format-php.c +++ b/gettext-tools/src/format-php.c @@ -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 , 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': diff --git a/gettext-tools/tests/format-php-1 b/gettext-tools/tests/format-php-1 index 79583d28e..a7420375d 100755 --- a/gettext-tools/tests/format-php-1 +++ b/gettext-tools/tests/format-php-1 @@ -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 diff --git a/gettext-tools/tests/format-php-2 b/gettext-tools/tests/format-php-2 index dc6fbc231..9066b955d 100755 --- a/gettext-tools/tests/format-php-2 +++ b/gettext-tools/tests/format-php-2 @@ -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"