From nobody Tue Oct 25 21:51:28 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Mxly92mS6z4g6DP; Tue, 25 Oct 2022 21:51:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Mxly912H0z3g6m; Tue, 25 Oct 2022 21:51:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666734689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ebl0jfWVkI6jHtmZX/epvWb84LpWav4Tp9CVE/+8+hg=; b=WpfLZS88ea6H+NqAM6bDJHFmbiibBGZcox/bpwtbk74Vbfmzws6U6UX1TSpcWbLK90WTfd ocM67higOTf8eN2LuuIZD2WXhxTBtZwwLkFklTVtAh05oO54h9IRV0c54jrrZ8L3cmLnHw UHDwziLNAZ37Lv5iYa9T6vRyPAM7F7b3xM7wpm0Qu2umemwgk1fQSkDki7yjaci5kwleIk p4ZT5NhT5SsIcFhn6tXt+eAWrCne3jPnGNneP0pd+BYk9+VDY1firyZDI8as0dWn6vcpXt EsMZZCNeMkcN+9sR4P+ul0SlK5rRcn3+sP2mPDJ7tiG2zngwWTxuE7vb4VnT7g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Mxly907ryzsdw; Tue, 25 Oct 2022 21:51:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29PLpSkd088491; Tue, 25 Oct 2022 21:51:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29PLpSwD088490; Tue, 25 Oct 2022 21:51:28 GMT (envelope-from git) Date: Tue, 25 Oct 2022 21:51:28 GMT Message-Id: <202210252151.29PLpSwD088490@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 750fe3e6a461 - main - strfmon: Fix an edge case when sep_by_space is 2 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 750fe3e6a4619e040c7b0951775698b61290102e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666734689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ebl0jfWVkI6jHtmZX/epvWb84LpWav4Tp9CVE/+8+hg=; b=thZlY4dQFpFCM/X2KJjcvzpZjOhE0dDBhNX+SXoJ64wdoB18fKWkQaYbJ+GYcn01YJeqej VyoaMlAtNADkqWDq87q9ATbO5hmWuR3cXYw5wy9mPS+LbPCkPTLCu9zXkO9PsGa1OzdYLG bRV3yKhXFb5rzlAwiNnALu/m7+xvdkCn1l3N/0WNHuJmp2y1ANro8i2Zjl3/ek4GC7J/L1 XGlXJq7yP32JO7Nx3LAeqDvlttBSk7X2YyuhBaGDJIQOWSMecv61g111oQzf8xrR67pdvk crppAyUWpq33ahc+aTmwWOSAqfkXYTVnG8nfdEifdcY7qw7J6/Cfcggru7eNcA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666734689; a=rsa-sha256; cv=none; b=VluClgN/vkV24ND/g1RmvSdy3GgAl3kYO1BP38oQji3aXSrdaOL1WPFu0EaR+ohDt7WsAz LO18MsvGFAljdLHoD7dVd7bE/Yt15VQky1zmRN6HfEU3KXmrI8JbVOKtOEBeE/TwByDclm siuY8wzfcP8EqO5st9zivGB2oSXrfg4vc/4utwSbHzjkWsZMI7Hog4KuUYg+SR8ZPuzI/i N/piPw0KR42Rxx4WmlM9FB0lHDVuMoj3hGPF541eHR0zG0UyaQv7jFkqQVeVK9EVKr5eWk EaAQJg1dZEve11G4BNAryf0DCK0Ccn8hLQsjwj85ZU2yfZpUYcvQYEe3aDTtsg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=750fe3e6a4619e040c7b0951775698b61290102e commit 750fe3e6a4619e040c7b0951775698b61290102e Author: Jose Luis Duran AuthorDate: 2022-10-18 02:24:03 +0000 Commit: Konstantin Belousov CommitDate: 2022-10-25 21:40:17 +0000 strfmon: Fix an edge case when sep_by_space is 2 Fix an edge case by printing the required space when, the currency symbol succeeds the value, a space separates the sign from the value and the sign position precedes the quantity and the currency symbol. In other words: n_cs_precedes = 0 n_sep_by_space = 2 n_sign_posn = 1 From The Open Group's localeconv[1]: > When {p,n,int_p,int_n}_sep_by_space is 2: > If the currency symbol and sign string are adjacent, a space separates > them; otherwise, a space separates the sign string from the value. Format Before After [%n] [-123.45¤] [- 123.45¤] [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/localeconv.html Obtained from: Darwin Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week --- lib/libc/stdlib/strfmon.c | 8 ++++++-- lib/libc/tests/stdlib/strfmon_test.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c index 80a73ee28916..d453b7a3943b 100644 --- a/lib/libc/stdlib/strfmon.c +++ b/lib/libc/stdlib/strfmon.c @@ -296,7 +296,8 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, * non-negative value * = 1 - space separates the symbol from the value * = 2 - space separates the symbol and the sign string, - * if adjacent. + * if adjacent; otherwise, a space separates + * the sign string from the value * * p_sign_posn & n_sign_posn * @@ -338,8 +339,11 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, } else if (sep_by_space == 1) PRINT(space_char); } - } else if (sign_posn == 1) + } else if (sign_posn == 1) { PRINTS(signstr); + if (sep_by_space == 2) + PRINT(' '); + } PRINTS(asciivalue); diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c index d4d1f6a580d9..664d1811dc46 100644 --- a/lib/libc/tests/stdlib/strfmon_test.c +++ b/lib/libc/tests/stdlib/strfmon_test.c @@ -116,7 +116,7 @@ ATF_TC_BODY(strfmon_cs_precedes_0, tc) /* sep_by_space x sign_posn */ { "[(123.00$)] [-123.00$] [123.00$-] [123.00-$] [123.00$-]" }, { "[(123.00 $)] [-123.00 $] [123.00 $-] [123.00 -$] [123.00 $-]" }, - { "[(123.00$)] [-123.00$] [123.00$ -] [123.00- $] [123.00$ -]" }, /* XXX */ + { "[(123.00$)] [- 123.00$] [123.00$ -] [123.00- $] [123.00$ -]" }, }; size_t i, j; struct lconv *lc;