From 5210c16bfafb78af01cb899f5f1d893ab436cfa4 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Fri, 28 Nov 2025 01:34:52 +0100 Subject: [PATCH] printf: simplify conversion specifiers This is another case where we can don't need to use complicated formatting specifiers. There is also no need to use `wgettext_fmt` for messages which don't contain any localizable parts. The instances using `sprintf` could be kept as is, but I think it's better to keep the width computation at the place where it can sensibly be done, even though it is not done correctly at the moment because it does not use grapheme widths. Removing complicated conversion specifiers from localized messages helps with the transition to Fluent. Closes #12119 --- po/de.po | 4 ---- po/en.po | 4 ---- po/fr.po | 4 ---- po/pl.po | 4 ---- po/pt_BR.po | 4 ---- po/sv.po | 4 ---- po/zh_CN.po | 4 ---- po/zh_TW.po | 4 ---- src/builtins/abbr.rs | 8 ++++++-- src/builtins/string.rs | 6 +++++- 10 files changed, 11 insertions(+), 35 deletions(-) diff --git a/po/de.po b/po/de.po index 5c4a2439a..5bef898fa 100644 --- a/po/de.po +++ b/po/de.po @@ -155,10 +155,6 @@ msgstr "" msgid "%s, version %s\n" msgstr "%s, version %s\n" -#, c-format -msgid "%s: %*s\n" -msgstr "" - #, c-format msgid "%s: %s\n" msgstr "" diff --git a/po/en.po b/po/en.po index 1b04e2404..78184556f 100644 --- a/po/en.po +++ b/po/en.po @@ -153,10 +153,6 @@ msgstr "" msgid "%s, version %s\n" msgstr "%s, version %s\n" -#, c-format -msgid "%s: %*s\n" -msgstr "" - #, c-format msgid "%s: %s\n" msgstr "" diff --git a/po/fr.po b/po/fr.po index 38907eac6..1e9eab368 100644 --- a/po/fr.po +++ b/po/fr.po @@ -284,10 +284,6 @@ msgstr "%s, version %s" msgid "%s, version %s\n" msgstr "%s, version %s\n" -#, c-format -msgid "%s: %*s\n" -msgstr "%s : %*s\n" - #, c-format msgid "%s: %s\n" msgstr "%s : %s\n" diff --git a/po/pl.po b/po/pl.po index ab2cfaacd..ab905fcb1 100644 --- a/po/pl.po +++ b/po/pl.po @@ -149,10 +149,6 @@ msgstr "" msgid "%s, version %s\n" msgstr "%s, wersja %s\n" -#, c-format -msgid "%s: %*s\n" -msgstr "" - #, c-format msgid "%s: %s\n" msgstr "" diff --git a/po/pt_BR.po b/po/pt_BR.po index 26028ccb9..68b33c31d 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -154,10 +154,6 @@ msgstr "" msgid "%s, version %s\n" msgstr "%s, versão %s\n" -#, c-format -msgid "%s: %*s\n" -msgstr "" - #, c-format msgid "%s: %s\n" msgstr "" diff --git a/po/sv.po b/po/sv.po index 6f7669d2f..3d122d1a7 100644 --- a/po/sv.po +++ b/po/sv.po @@ -150,10 +150,6 @@ msgstr "" msgid "%s, version %s\n" msgstr "%s, version %s\n" -#, c-format -msgid "%s: %*s\n" -msgstr "" - #, c-format msgid "%s: %s\n" msgstr "" diff --git a/po/zh_CN.po b/po/zh_CN.po index 497ddbf4c..9028dea99 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -176,10 +176,6 @@ msgstr "%s,版本 %s" msgid "%s, version %s\n" msgstr "%s,版本 %s\n" -#, c-format -msgid "%s: %*s\n" -msgstr "%s: %*s\n" - #, c-format msgid "%s: %s\n" msgstr "%s: %s\n" diff --git a/po/zh_TW.po b/po/zh_TW.po index 2cdf3a9a8..8bba47bbf 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -149,10 +149,6 @@ msgstr "%s,%s 版" msgid "%s, version %s\n" msgstr "%s,%s 版\n" -#, c-format -msgid "%s: %*s\n" -msgstr "%s:%*s\n" - #, c-format msgid "%s: %s\n" msgstr "%s:%s\n" diff --git a/src/builtins/abbr.rs b/src/builtins/abbr.rs index 816a72d5f..f4e52a1b4 100644 --- a/src/builtins/abbr.rs +++ b/src/builtins/abbr.rs @@ -353,8 +353,12 @@ fn abbr_add(opts: &Options, streams: &mut IoStreams) -> BuiltinResult { if let Some(offset) = error.offset() { streams .err - .append(wgettext_fmt!("%s: %s\n", CMD, regex_pattern.as_utfstr())); - streams.err.append(sprintf!("%s: %*s\n", CMD, offset, "^")); + .append(sprintf!("%s: %s\n", CMD, regex_pattern.as_utfstr())); + // TODO: This is misaligned if `regex_pattern` contains characters which are not + // exactly 1 terminal cell wide. + let mut marker = " ".repeat(offset.saturating_sub(1)); + marker.push('^'); + streams.err.append(sprintf!("%s: %s\n", CMD, marker)); } return Err(STATUS_INVALID_ARGS); } diff --git a/src/builtins/string.rs b/src/builtins/string.rs index d2ea05165..58bf06696 100644 --- a/src/builtins/string.rs +++ b/src/builtins/string.rs @@ -187,7 +187,11 @@ fn print_error(&self, args: &[&wstr], streams: &mut IoStreams) { &WString::from(e.error_message()) ); string_error!(streams, "%s: %s\n", cmd, pattern); - string_error!(streams, "%s: %*s\n", cmd, e.offset().unwrap_or(0), "^"); + // TODO: This is misaligned if `pattern` contains characters which are not exactly 1 + // terminal cell wide. + let mut marker = " ".repeat(e.offset().unwrap_or(0).saturating_sub(1)); + marker.push('^'); + string_error!(streams, "%s: %s\n", cmd, marker); } InvalidCaptureGroupName(name) => { streams.err.append(wgettext_fmt!(