Skip to content

Commit e30b8a6

Browse files
committed
[format.string] Separate out the general (type-independent) description
of formatting from the format specifiers for arithmetic and string types, and make the presentation of the latter consistent with the presentation for chrono types.
1 parent d17fd4d commit e30b8a6

File tree

2 files changed

+60
-36
lines changed

2 files changed

+60
-36
lines changed

source/time.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10165,7 +10165,9 @@
1016510165
in the chrono library\iref{time.syn}
1016610166
meets the \newoldconcept{Formatter} requirements\iref{formatter.requirements}.
1016710167
The \tcode{parse} member functions of these formatters
10168-
interpret the format specification according to the following syntax:
10168+
interpret the format specification
10169+
as a \fmtgrammarterm{chrono-format-spec}
10170+
according to the following syntax:
1016910171

1017010172
\begin{ncbnf}
1017110173
\fmtnontermdef{chrono-format-spec}\br

source/utilities.tex

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19618,6 +19618,8 @@
1961819618

1961919619
\rSec2[format.string]{Format string}
1962019620

19621+
\rSec3[format.string.general]{In general}
19622+
1962119623
% FIXME: For now, keep the format grammar productions out of the index, since
1962219624
% they conflict with the main grammar.
1962319625
% Consider renaming these en masse (to fmt-* ?) to avoid this problem.
@@ -19639,7 +19641,7 @@
1963919641

1964019642
\begin{ncbnf}
1964119643
\fmtnontermdef{replacement-field}\br
19642-
\terminal{\{} \opt{arg-id} \opt{format-spec} \terminal{\}}
19644+
\terminal{\{} \opt{arg-id} \opt{format-specifier} \terminal{\}}
1964319645
\end{ncbnf}
1964419646

1964519647
\begin{ncbnf}
@@ -19671,13 +19673,23 @@
1967119673
\terminal{0 1 2 3 4 5 6 7 8 9}
1967219674
\end{ncbnf}
1967319675

19676+
\begin{ncbnf}
19677+
\fmtnontermdef{format-specifier}\br
19678+
\terminal{:} format-spec
19679+
\end{ncbnf}
19680+
19681+
\begin{ncbnf}
19682+
\fmtnontermdef{format-spec}\br
19683+
\textnormal{as specified by the \tcode{formatter} specialization for the argument type}
19684+
\end{ncbnf}
19685+
1967419686
\pnum
1967519687
The \fmtgrammarterm{arg-id} field specifies the index of
1967619688
% FIXME: "args" hasn't been introduced yet!
1967719689
the argument in \tcode{args}
1967819690
whose value is to be formatted and inserted into the output
1967919691
instead of the replacement field.
19680-
The optional \fmtgrammarterm{format-spec} field
19692+
The optional \fmtgrammarterm{format-specifier} field
1968119693
explicitly specifies a format for the replacement value.
1968219694

1968319695
\pnum
@@ -19688,7 +19700,9 @@
1968819700
\end{example}
1968919701

1969019702
\pnum
19691-
If all \fmtgrammarterm{arg-id}s in a format string are omitted,
19703+
If all \fmtgrammarterm{arg-id}s in a format string are omitted
19704+
(including those in the \fmtgrammarterm{format-spec},
19705+
as interpreted by the corresponding \tcode{formatter} specialization),
1969219706
argument indexes 0, 1, 2, \ldots{} will automatically be used in that order.
1969319707
If some \fmtgrammarterm{arg-id}s are omitted and some are present,
1969419708
the string is not a format string.
@@ -19710,27 +19724,44 @@
1971019724
\pnum
1971119725
The \fmtgrammarterm{format-spec} field contains
1971219726
\defnx{format specifications}{format specification!format string}
19713-
that define how the value should be presented,
19714-
including such details as
19715-
field width, alignment, padding, and decimal precision.
19727+
that define how the value should be presented.
1971619728
Each type can define its own
19717-
formatting mini-language or
1971819729
interpretation of the \fmtgrammarterm{format-spec} field.
19719-
The syntax of format specifications is as follows:
19730+
\begin{example}
19731+
\begin{itemize}
19732+
\item
19733+
For arithmetic, pointer, and string types
19734+
the \fmtgrammarterm{format-spec}
19735+
is interpreted as a \fmtgrammarterm{std-format-spec}
19736+
as described in \iref{format.string.std}.
19737+
\item
19738+
For chrono types
19739+
the \fmtgrammarterm{format-spec}
19740+
is interpreted as a \fmtgrammarterm{chrono-format-spec}
19741+
as described in \iref{time.format}.
19742+
\item
19743+
For user-defined \tcode{formatter} specializations,
19744+
the behavior of the \tcode{parse} member function
19745+
determines how the \fmtgrammarterm{format-spec}
19746+
is interpreted.
19747+
\end{itemize}
19748+
\end{example}
1972019749

19721-
% FIXME: Listing chrono-format-spec here is a mistake. We should have a clean
19722-
% separation between the extensibility mechanism and the extensions to it.
19723-
\begin{ncbnf}
19724-
\fmtnontermdef{format-spec}\br
19725-
\terminal{:} std-format-spec\br
19726-
\terminal{:} chrono-format-spec\br
19727-
\terminal{:} custom-format-spec
19728-
\end{ncbnf}
19750+
\rSec3[format.string.std]{Standard format specifiers}
1972919751

19730-
\begin{ncbnf}
19731-
\fmtnontermdef{custom-format-spec}\br
19732-
\textnormal{user-defined syntax dependent on the type of the argument}
19733-
\end{ncbnf}
19752+
\pnum
19753+
Each \tcode{formatter} specializations
19754+
described in \ref{format.formatter.spec}
19755+
for fundamental and string types
19756+
interprets \fmtgrammarterm{format-spec} as a
19757+
\fmtgrammarterm{std-format-spec}.
19758+
\begin{note}
19759+
The format specification can be used to specify such details as
19760+
field width, alignment, padding, and decimal precision.
19761+
Some of the formatting options
19762+
are only supported for arithmetic types.
19763+
\end{note}
19764+
The syntax of format specifications is as follows:
1973419765

1973519766
\begin{ncbnf}
1973619767
\fmtnontermdef{std-format-spec}\br
@@ -19774,19 +19805,6 @@
1977419805
\terminal{a A b B c d e E f F g G n o p s x X}
1977519806
\end{ncbnf}
1977619807

19777-
where
19778-
\fmtgrammarterm{std-format-spec}
19779-
defines a common formatting mini-language
19780-
supported by fundamental and string types,
19781-
\fmtgrammarterm{chrono-format-spec}
19782-
defines a mini-language for chrono types\iref{time.format}, and
19783-
\fmtgrammarterm{custom-format-spec}
19784-
is a placeholder for user-defined mini-languages.
19785-
\begin{note}
19786-
Some of the formatting options
19787-
are only supported for arithmetic types.
19788-
\end{note}
19789-
1979019808
\pnum
1979119809
\begin{note}
1979219810
The \fmtgrammarterm{fill} character can be any character
@@ -20514,10 +20532,14 @@
2051420532
\item a floating-point type.
2051520533
\end{itemize}
2051620534
\end{itemize}
20517-
20535+
The \tcode{parse} member functions of these formatters
20536+
interpret the format specification
20537+
as a \fmtgrammarterm{std-format-spec}
20538+
as described in \ref{format.string.std}.
2051820539
\begin{note}
2051920540
Specializations such as \tcode{formatter<wchar_t, char>}
20520-
and \tcode{formatter<const char*, wchar_t>} that require implicit
20541+
and \tcode{formatter<const char*, wchar_t>}
20542+
that would require implicit
2052120543
multibyte / wide string or character conversion are disabled.
2052220544
\end{note}
2052320545

0 commit comments

Comments
 (0)