From 8a75bccf005b936fdc400aa9cb6188f3e021fe1b Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Fri, 28 Nov 2025 01:10:13 +0100 Subject: [PATCH] printf: simplify conversion specifier We already compute the length of the substring we want to print in Rust. Passing that length as the precision to let printf formatting limit the length is brittle, as it requires that the same semantics for "length" are used. Simplifying conversion specifiers also makes the transition to Fluent easier. Part of #12119 --- po/de.po | 8 ++++---- po/en.po | 8 ++++---- po/fr.po | 8 ++++---- po/pl.po | 8 ++++---- po/pt_BR.po | 8 ++++---- po/sv.po | 8 ++++---- po/zh_CN.po | 8 ++++---- po/zh_TW.po | 8 ++++---- src/builtins/printf.rs | 8 +++++--- 9 files changed, 37 insertions(+), 35 deletions(-) diff --git a/po/de.po b/po/de.po index fbad820f8..5c4a2439a 100644 --- a/po/de.po +++ b/po/de.po @@ -79,10 +79,6 @@ msgstr "" msgid "$status is not valid as a command. See `help %s`" msgstr "$status ist kein gültiger Befehl. Siehe `help %s`" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "%.*s: Ungültige Umwandlungsspezifikation" - #, c-format msgid "%s" msgstr "" @@ -727,6 +723,10 @@ msgstr "%s: Brauche Funktionsnamen" msgid "%s: given %d indexes but %d values\n" msgstr "" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "%s: Ungültige Umwandlungsspezifikation" + #, c-format msgid "%s: invalid option combination\n" msgstr "%s: ungültige Optionskombination\n" diff --git a/po/en.po b/po/en.po index 7a1f9e32e..1b04e2404 100644 --- a/po/en.po +++ b/po/en.po @@ -77,10 +77,6 @@ msgstr "" msgid "$status is not valid as a command. See `help %s`" msgstr "" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "%.*s: invalid conversion specification" - #, c-format msgid "%s" msgstr "" @@ -725,6 +721,10 @@ msgstr "" msgid "%s: given %d indexes but %d values\n" msgstr "" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "%s: invalid conversion specification" + #, c-format msgid "%s: invalid option combination\n" msgstr "" diff --git a/po/fr.po b/po/fr.po index 1e6a0edf1..38907eac6 100644 --- a/po/fr.po +++ b/po/fr.po @@ -208,10 +208,6 @@ msgstr "$@ n’est pas supporté. Dans fish, veuillez utiliser $argv." msgid "$status is not valid as a command. See `help %s`" msgstr "$status n’est pas une commande valide. Voir « help %s »" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "%.*s : spécification de conversion invalide" - #, c-format msgid "%s" msgstr "%s" @@ -856,6 +852,10 @@ msgstr "" msgid "%s: given %d indexes but %d values\n" msgstr "" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "%s : spécification de conversion invalide" + #, c-format msgid "%s: invalid option combination\n" msgstr "" diff --git a/po/pl.po b/po/pl.po index 2e218af75..ab2cfaacd 100644 --- a/po/pl.po +++ b/po/pl.po @@ -73,10 +73,6 @@ msgstr "$@ nie jest obsługiwane. W fish używane jest $argv." msgid "$status is not valid as a command. See `help %s`" msgstr "" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "" - #, c-format msgid "%s" msgstr "" @@ -721,6 +717,10 @@ msgstr "" msgid "%s: given %d indexes but %d values\n" msgstr "" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "" + #, c-format msgid "%s: invalid option combination\n" msgstr "" diff --git a/po/pt_BR.po b/po/pt_BR.po index 22c74b2f3..26028ccb9 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -78,10 +78,6 @@ msgstr "" msgid "$status is not valid as a command. See `help %s`" msgstr "" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "%.*s: especificação de conversão inválida" - #, c-format msgid "%s" msgstr "" @@ -726,6 +722,10 @@ msgstr "" msgid "%s: given %d indexes but %d values\n" msgstr "" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "%s: especificação de conversão inválida" + #, c-format msgid "%s: invalid option combination\n" msgstr "" diff --git a/po/sv.po b/po/sv.po index 483b0ac35..6f7669d2f 100644 --- a/po/sv.po +++ b/po/sv.po @@ -74,10 +74,6 @@ msgstr "" msgid "$status is not valid as a command. See `help %s`" msgstr "" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "" - #, c-format msgid "%s" msgstr "" @@ -722,6 +718,10 @@ msgstr "" msgid "%s: given %d indexes but %d values\n" msgstr "" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "" + #, c-format msgid "%s: invalid option combination\n" msgstr "" diff --git a/po/zh_CN.po b/po/zh_CN.po index 704efe922..497ddbf4c 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -100,10 +100,6 @@ msgstr "不支持 $@。在 fish 中,请使用 $argv。" msgid "$status is not valid as a command. See `help %s`" msgstr "$status 不是有效的命令。参见 `help %s`" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "%.*s: 无效的转换规范" - #, c-format msgid "%s" msgstr "%s" @@ -748,6 +744,10 @@ msgstr "%s: 函数名称是必须的" msgid "%s: given %d indexes but %d values\n" msgstr "%s: 给定索引 %d 但只有 %d 个值\n" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "%s: 无效的转换规范" + #, c-format msgid "%s: invalid option combination\n" msgstr "%s: 无效的选项组合\n" diff --git a/po/zh_TW.po b/po/zh_TW.po index d1716e4b9..2cdf3a9a8 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -73,10 +73,6 @@ msgstr "不支援 $@。在 fish 中請使用 $argv。" msgid "$status is not valid as a command. See `help %s`" msgstr "$status 不是有效的命令。參見「help %s」" -#, c-format -msgid "%.*s: invalid conversion specification" -msgstr "%.*s:轉換規格無效" - #, c-format msgid "%s" msgstr "%s" @@ -721,6 +717,10 @@ msgstr "%s:需要函式名稱" msgid "%s: given %d indexes but %d values\n" msgstr "%s:指定了 %d 個索引卻有 %d 個值\n" +#, c-format +msgid "%s: invalid conversion specification" +msgstr "%s:轉換規格無效" + #, c-format msgid "%s: invalid option combination\n" msgstr "%s:無效的選項組合\n" diff --git a/src/builtins/printf.rs b/src/builtins/printf.rs index 8ba7df1ad..f01a52e02 100644 --- a/src/builtins/printf.rs +++ b/src/builtins/printf.rs @@ -526,10 +526,12 @@ fn print_formatted(&mut self, format: &wstr, mut argv: &[&wstr]) -> usize { let conversion = f.char_at(0); if (conversion as usize) > 0xFF || !ok[conversion as usize] { + let directive = &directive_start[0..directive_start + .len() + .min(wstr_offset_in(f, directive_start) + 1)]; self.fatal_error(wgettext_fmt!( - "%.*s: invalid conversion specification", - wstr_offset_in(f, directive_start) + 1, - directive_start + "%s: invalid conversion specification", + directive )); return 0; }