Skip to content

P1892R1 Extended locale-specific presentation specifiers for std::format #3474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions source/utilities.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -19880,6 +19880,29 @@
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
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
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 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.

Expand Down Expand Up @@ -19919,7 +19942,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}
Expand Down Expand Up @@ -19968,12 +19991,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}
Expand All @@ -19993,7 +20010,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}
Expand All @@ -20009,7 +20026,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<unsigned char>(value)}.
Expand Down Expand Up @@ -20087,12 +20104,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}
Expand Down