Skip to content

Commit 045da83

Browse files
Dawn Perchikzygoloid
authored andcommitted
P1868R2 width: clarifying units of width and precision in std::format
Also fixes NB US 228 (C++20 CD) and LWG3290.
1 parent c091aa5 commit 045da83

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

source/intro.tex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
\begin{itemize}
3636
\item Ecma International, \doccite{ECMAScript Language Specification},
3737
Standard Ecma-262, third edition, 1999.
38-
% FIXME: Is the following comment refering to the entry above or
39-
% the entry removed in LWG3319? I.e. is it still valid?
40-
%%% Format for this entry is based on that specified at
41-
%%% http://www.iec.ch/standardsdev/resources/draftingpublications/directives/principles/referencing.htm
4238
\item ISO/IEC 2382 (all parts), \doccite{Information technology ---
4339
Vocabulary}
4440
\item ISO 8601:2004, \doccite{Data elements and interchange formats ---
@@ -56,6 +52,11 @@
5652
\item ISO 80000-2:2009, \doccite{Quantities and units ---
5753
Part 2: Mathematical signs and symbols
5854
to be used in the natural sciences and technology}
55+
%%% Format for the following entry is based on that specified at
56+
%%% http://www.iec.ch/standardsdev/resources/draftingpublications/directives/principles/referencing.htm
57+
\item The Unicode Consortium. Unicode Standard Annex, UAX \#29, \doccite{Unicode Text Segmentation} [online].
58+
Edited by Mark Davis. Revision 35; issued for Unicode 12.0.0. 2019-02-15 [viewed 2020-02-23].
59+
Available at \url{http://www.unicode.org/reports/tr29/tr29-35.html}
5960
\end{itemize}
6061

6162
\pnum

source/utilities.tex

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19371,6 +19371,55 @@
1937119371
there is no minimum field width, and
1937219372
the field width is determined based on the content of the field.
1937319373

19374+
\pnum
19375+
\indextext{string!width}%
19376+
The \defn{width} of a string is defined as
19377+
the estimated number of column positions appropriate
19378+
for displaying it in a terminal.
19379+
\begin{note}
19380+
This is similar to the semantics of the POSIX \tcode{wcswidth} function.
19381+
\end{note}
19382+
19383+
\pnum
19384+
For the purposes of width computation,
19385+
a string is assumed to be in
19386+
a locale-independent, implementation-defined encoding.
19387+
Implementations should use a Unicode encoding
19388+
on platforms capable of displaying Unicode text in a terminal.
19389+
\begin{note}
19390+
This is the case for Windows-based and many POSIX-based operating systems.
19391+
\end{note}
19392+
19393+
\pnum
19394+
For a string in a Unicode encoding,
19395+
implementations should estimate the width of a string
19396+
as the sum of estimated widths of
19397+
the first code points in its extended grapheme clusters
19398+
as defined by
19399+
Unicode Standard Annex \#29 Unicode Text Segmentation.
19400+
The estimated width of the following code points is 2:
19401+
\begin{itemize}
19402+
\item \tcode{U+1100-U+115F}
19403+
\item \tcode{U+2329}
19404+
\item \tcode{U+232A}
19405+
\item \tcode{U+2E80-U+303E}
19406+
\item \tcode{U+3040-U+A4CF}
19407+
\item \tcode{U+AC00-U+D7A3}
19408+
\item \tcode{U+F900-U+FAFF}
19409+
\item \tcode{U+FE10-U+FE19}
19410+
\item \tcode{U+FE30-U+FE6F}
19411+
\item \tcode{U+FF00-U+FF60}
19412+
\item \tcode{U+FFE0-U+FFE6}
19413+
\item \tcode{U+20000-U+2FFFD}
19414+
\item \tcode{U+30000-U+3FFFD}
19415+
\item \tcode{U+1F300-U+1F64F}
19416+
\item \tcode{U+1F900-U+1F9FF}
19417+
\end{itemize}
19418+
The estimated width of other code points is 1.
19419+
19420+
\pnum
19421+
For a string in a non-Unicode encoding, the width of a string is unspecified.
19422+
1937419423
\pnum
1937519424
A zero (\tcode{0}) character
1937619425
preceding the \fmtgrammarterm{width} field
@@ -19398,7 +19447,13 @@
1939819447
the precision or maximum field size.
1939919448
It can only be used with floating-point and string types.
1940019449
For floating-point types this field specifies the formatting precision.
19401-
For string types it specifies how many characters will be used from the string.
19450+
For string types, this field provides an upper bound
19451+
for the estimated width of the prefix of
19452+
the input string that is copied into the output.
19453+
For a string in a Unicode encoding,
19454+
the formatter copies to the output
19455+
the longest prefix of whole extended grapheme clusters
19456+
whose estimated width is no greater than the precision.
1940219457

1940319458
\pnum
1940419459
When the \tcode{L} option is used, the form used for the conversion is called

0 commit comments

Comments
 (0)