git: 6da51e19e347 - main - strfmon: Trim the SPACE from international currency symbol
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 25 Oct 2022 21:51:26 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=6da51e19e347c13e133bcba68cc6100c16320a01
commit 6da51e19e347c13e133bcba68cc6100c16320a01
Author: Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-21 16:13:27 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-25 21:40:17 +0000
strfmon: Trim the SPACE from international currency symbol
The international currency symbol (int_curr_symbol) has a mandatory
SPACE character as the last character.
Trim this space after reading it, otherwise this extra space will always
be printed when displaying the int_curr_symbol.
Fixes the output when the international currency format is selected
(%i).
Locale Format Before After
en_US.UTF-8 [%i] [USD 123.45] [USD123.45]
fr_FR.UTF-8 [%i] [123,45 EUR ] [123,45 EUR]
Note that the en_US.UTF-8 locale states that no space should be printed
between the currency symbol and the value (sep_by_space = 0).
Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week
---
lib/libc/stdlib/strfmon.c | 4 +++-
lib/libc/tests/stdlib/strfmon_test.c | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c
index 2526ab8fd8b1..a7a48317c97c 100644
--- a/lib/libc/stdlib/strfmon.c
+++ b/lib/libc/stdlib/strfmon.c
@@ -240,8 +240,10 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc,
if (flags & USE_INTL_CURRENCY) {
currency_symbol = strdup(lc->int_curr_symbol);
if (currency_symbol != NULL &&
- strlen(currency_symbol) > 3)
+ strlen(currency_symbol) > 3) {
space_char = currency_symbol[3];
+ currency_symbol[3] = '\0';
+ }
} else
currency_symbol = strdup(lc->currency_symbol);
diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c
index dc328e974bb8..b5b22f9a483d 100644
--- a/lib/libc/tests/stdlib/strfmon_test.c
+++ b/lib/libc/tests/stdlib/strfmon_test.c
@@ -195,8 +195,8 @@ ATF_TC_BODY(strfmon_international_currency_code, tc)
const char *locale;
const char *expected;
} tests[] = {
- { "en_US.UTF-8", "[USD 123.45]" }, /* XXX */
- { "de_DE.UTF-8", "[123,45 EUR ]" }, /* XXX */
+ { "en_US.UTF-8", "[USD123.45]" },
+ { "de_DE.UTF-8", "[123,45 EUR]" },
{ "C", "[123.45]" },
};
size_t i;