From a5938ea8996bd55365c4bfa6b2ecfdee288083a1 Mon Sep 17 00:00:00 2001 From: Dawn Perchik Date: Thu, 14 Nov 2019 16:45:46 -0800 Subject: [PATCH 1/4] P1892R1 Extended locale-specific presentation specifiers for std::format Also fixes NB GB 226 (C++20 CD). --- source/utilities.tex | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/source/utilities.tex b/source/utilities.tex index 9afb80543f..cbc5b89cd5 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -19682,7 +19682,7 @@ \begin{ncbnf} \fmtnontermdef{std-format-spec}\br - \opt{fill-and-align} \opt{sign} \opt{\terminal{\#}} \opt{\terminal{0}} \opt{width} \opt{precision} \opt{type} + \opt{fill-and-align} \opt{sign} \opt{\terminal{\#}} \opt{\terminal{0}} \opt{width} \opt{precision} \opt{\terminal{L}} \opt{type} \end{ncbnf} \begin{ncbnf} @@ -19719,7 +19719,7 @@ \begin{ncbnf} \fmtnontermdef{type} \textnormal{one of}\br - \terminal{a A b B c d e E f F g G n o p s x X} + \terminal{a A b B c d e E f F g G o p s x X} \end{ncbnf} \pnum @@ -19880,6 +19880,22 @@ For floating-point types this field specifies the formatting precision. For string types it specifies how many characters will be used from the string. +\pnum +The \tcode{L} option causes +the \defnx{locale-specific form}{locale-specific form!format string} +to be used for the conversion. +This option is only valid for arithmetic types. +For integral types, the locale-specific form +causes the context's locale to be used +to insert the appropriate digit group separator characters. +For floating-point types, the locale-specific form +causes the context's locale to be used +to insert the appropriate digit group and decimal radix separator characters. +For the textual representation of \tcode{bool}, the locale-specific form +causes the context's locale to be used +to insert the appropriate string as if obtained +with \tcode{numpunct::truename} or \tcode{numpunct::falsename}. + \pnum The \fmtgrammarterm{type} determines how the data should be presented. @@ -19919,7 +19935,7 @@ string s0 = format("{}", 42); // value of \tcode{s0} is \tcode{"42"} string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // value of \tcode{s1} is \tcode{"101010 42 52 2a"} string s2 = format("{0:#x} {0:#X}", 42); // value of \tcode{s2} is \tcode{"0x2a 0X2A"} -string s3 = format("{:n}", 1234); // value of \tcode{s3} might be \tcode{"1,234"} +string s3 = format("{:L}", 1234); // value of \tcode{s3} might be \tcode{"1,234"} // (depending on the locale) \end{codeblock} \end{example} @@ -19968,12 +19984,6 @@ the base prefix is \tcode{0X}. \\ \rowsep % -\tcode{n} & -The same as \tcode{d}, except that -it uses the context's locale -to insert the appropriate digit group separator characters. -\\ \rowsep -% none & The same as \tcode{d}. \begin{note} @@ -19993,7 +20003,7 @@ Copies the character to the output. \\ \rowsep % -\tcode{b}, \tcode{B}, \tcode{d}, \tcode{o}, \tcode{x}, \tcode{X}, \tcode{n} & +\tcode{b}, \tcode{B}, \tcode{d}, \tcode{o}, \tcode{x}, \tcode{X} & As specified in \tref{format.type.int}. \\ \end{floattable} @@ -20009,7 +20019,7 @@ Copies textual representation, either \tcode{true} or \tcode{false}, to the output. \\ \rowsep % -\tcode{b}, \tcode{B}, \tcode{c}, \tcode{d}, \tcode{o}, \tcode{x}, \tcode{X}, \tcode{n} & +\tcode{b}, \tcode{B}, \tcode{c}, \tcode{d}, \tcode{o}, \tcode{x}, \tcode{X} & As specified in \tref{format.type.int} for the value \tcode{static_cast(value)}. @@ -20087,12 +20097,6 @@ it uses \tcode{E} to indicate exponent. \\ \rowsep % -\tcode{n} & -The same as \tcode{g}, except that -it uses the context's locale to insert the appropriate -digit group and decimal radix separator characters. -\\ \rowsep -% none & If \fmtgrammarterm{precision} is specified, equivalent to \begin{codeblock} From ad91aa2b2b62305250e7667c53276c794e3eee8d Mon Sep 17 00:00:00 2001 From: Dawn Perchik Date: Thu, 14 Nov 2019 17:10:58 -0800 Subject: [PATCH 2/4] [format.string.std] Use bullets to list the effects of the locale-specific form on each arithmetic type. --- source/utilities.tex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/utilities.tex b/source/utilities.tex index cbc5b89cd5..b4855b9fed 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -19884,17 +19884,25 @@ The \tcode{L} option causes the \defnx{locale-specific form}{locale-specific form!format string} to be used for the conversion. -This option is only valid for arithmetic types. +This option is only valid for arithmetic types, and +its effect depends upon the type. +\begin{itemize} +\item For integral types, the locale-specific form causes the context's locale to be used to insert the appropriate digit group separator characters. + +\item For floating-point types, the locale-specific form causes the context's locale to be used to insert the appropriate digit group and decimal radix separator characters. + +\item For the textual representation of \tcode{bool}, the locale-specific form causes the context's locale to be used to insert the appropriate string as if obtained with \tcode{numpunct::truename} or \tcode{numpunct::falsename}. +\end{itemize} \pnum The \fmtgrammarterm{type} determines how the data should be presented. From dea4ded28cf7e315b728f3ad31f0af96f9ff58e8 Mon Sep 17 00:00:00 2001 From: Dawn Perchik Date: Thu, 14 Nov 2019 17:15:49 -0800 Subject: [PATCH 3/4] [format.string.std] Provide a definition for the locale-specific form. --- source/utilities.tex | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/utilities.tex b/source/utilities.tex index b4855b9fed..596433fb48 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -19881,10 +19881,9 @@ For string types it specifies how many characters will be used from the string. \pnum -The \tcode{L} option causes -the \defnx{locale-specific form}{locale-specific form!format string} -to be used for the conversion. -This option is only valid for arithmetic types, and +When the \tcode{L} option is used, the form used for the conversion is called +the \defnx{locale-specific form}{locale-specific form!format string}. +The \tcode{L} option is only valid for arithmetic types, and its effect depends upon the type. \begin{itemize} \item From d1d3793c1fa08eb4246ac8f218e7a949ae61e28b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 22 Nov 2019 20:51:26 -0800 Subject: [PATCH 4/4] [format.string.std] 'decimal radix separator' -> 'radix separator'. The use of the word 'decimal' here is not intended to mean "only base 10", and so serves only to confuse the reader. --- source/utilities.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/utilities.tex b/source/utilities.tex index 596433fb48..fc9d75c25b 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -19894,7 +19894,7 @@ \item For floating-point types, the locale-specific form causes the context's locale to be used -to insert the appropriate digit group and decimal radix separator characters. +to insert the appropriate digit group and radix separator characters. \item For the textual representation of \tcode{bool}, the locale-specific form