Index: src/format-qt.c =================================================================== RCS file: /sources/gettext/gettext/gettext-tools/src/format-qt.c,v retrieving revision 1.8 diff -u -r1.8 format-qt.c --- src/format-qt.c 27 Nov 2006 12:46:23 -0000 1.8 +++ src/format-qt.c 4 Jul 2007 23:31:26 -0000 @@ -31,14 +31,16 @@ #define _(str) gettext (str) /* Qt format strings are processed by QString::arg and are documented in - qt-3.0.5/doc/html/qstring.html. - A directive starts with '%' and is followed by a digit ('0' to '9'). - Each %n must occur only once in the given string. - The first .arg() invocation replaces the %n with the lowest numbered n, - the next .arg() invocation then replaces the %n with the second-lowest + qt4/doc/html/qstring.html. + A directive starts with '%' and is followed by one or two digits + (both '0' to '9', e.g. %00 is allowed). + Same %n directive may occur more than once in the given string. + The first .arg() invocation replaces all %n with the lowest numbered n, + the next .arg() invocation then replaces all %n with the second-lowest numbered n, and so on. (This is inherently buggy because a '%' in the first replacement confuses - the second .arg() invocation.) + the second .arg() invocation. There is also a multi-parameter QString::arg + which avoids this problem, but takes only QString parameters.) Although %0 is supported, usually %1 denotes the first argument, %2 the second argument etc. */ @@ -46,7 +48,7 @@ { unsigned int directives; unsigned int arg_count; - bool args_used[10]; + bool args_used[100]; }; @@ -72,16 +74,15 @@ spec.directives++; number = *format - '0'; + /* Check if there is also a second digit. */ + if (*(format + 1) >= '0' && *(format + 1) <= '9') + { + format++; + number = number * 10 + (*format - '0'); + } while (spec.arg_count <= number) spec.args_used[spec.arg_count++] = false; - if (spec.args_used[number]) - { - *invalid_reason = - xasprintf (_("Multiple references to %%%c."), *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } spec.args_used[number] = true; FDI_SET (format, FMTDIR_END); @@ -122,15 +123,21 @@ struct spec *spec2 = (struct spec *) msgstr_descr; bool err = false; unsigned int i; + unsigned int ndiff; - for (i = 0; i < spec1->arg_count || i < spec2->arg_count; i++) + for (i = 0, ndiff = 0; i < spec1->arg_count || i < spec2->arg_count; i++) { bool arg_used1 = (i < spec1->arg_count && spec1->args_used[i]); bool arg_used2 = (i < spec2->arg_count && spec2->args_used[i]); /* The translator cannot omit a %n from the msgstr because that would - yield a "Argument missing" warning at runtime. */ - if (arg_used1 != arg_used2) + yield a "Argument missing" warning at runtime. + An exception is a non-strict plural form msgstr, where one of the + arguments may be missing (as handled by KDE; pure Qt in fact cannot + make proper use of gettextn call with non-strict rule). */ + if (equality + ? arg_used1 != arg_used2 + : arg_used1 != arg_used2 && i >= spec1->arg_count) { if (error_logger) error_logger (arg_used1 @@ -140,6 +147,18 @@ err = true; break; } + /* Count the number of unmatched arguments in non-strict mode. */ + if (!equality && arg_used1 != arg_used2) + ndiff++; + } + + /* Check that no more than one argument is unmatched in non-strict mode. */ + if (!equality && ndiff > 1) + { + if (error_logger) + error_logger (_("at most one unmatched argument allowed in non-strict '%s'"), + pretty_msgstr); + err = true; } return err; Index: tests/format-qt-1 =================================================================== RCS file: /sources/gettext/gettext/gettext-tools/tests/format-qt-1,v retrieving revision 1.1 diff -u -r1.1 format-qt-1 --- tests/format-qt-1 28 Oct 2003 16:10:35 -0000 1.1 +++ tests/format-qt-1 4 Jul 2007 23:31:26 -0000 @@ -13,15 +13,19 @@ "abc%1def" # Valid: one argument "abc%9def" +# Valid: one argument +"abc%99def" # Valid: unterminated "abc%1def%" # Valid: non-digit "abc%1def%x" # Valid: zero "abc%1def%0" +# Valid: leading zero +"abc%01def%00" # Valid: permutation "abc%2def%1" -# Invalid: multiple uses of same argument +# Valid: multiple uses of same argument "abc%2def%1ghi%2" EOF Index: tests/format-qt-2 =================================================================== RCS file: /sources/gettext/gettext/gettext-tools/tests/format-qt-2,v retrieving revision 1.1 diff -u -r1.1 format-qt-2 --- tests/format-qt-2 28 Oct 2003 16:10:35 -0000 1.1 +++ tests/format-qt-2 4 Jul 2007 23:31:26 -0000 @@ -10,9 +10,6 @@ # Valid: %% doesn't count msgid "abc%%def" msgstr "xyz" -# Invalid: invalid msgstr -msgid "abc%1def" -msgstr "xyz%1%1" # Valid: same arguments msgid "abc%2def" msgstr "xyz%2"