Skip to content

Commit c703bd9

Browse files
authored
Merge 2020-02 LWG Motion 14
P1868R2 🦄 width: clarifying units of width and precision in std::format
2 parents c091aa5 + 9ce9b23 commit c703bd9

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

source/intro.tex

Lines changed: 8 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
@@ -681,5 +682,8 @@
681682
\pnum
682683
ECMAScript\textregistered\ is a registered trademark of Ecma International.
683684

685+
\pnum
686+
Unicode\textregistered\ is a registered trademark of Unicode, Inc.
687+
684688
\pnum
685689
All rights in these originals are reserved.

source/utilities.tex

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19371,6 +19371,53 @@
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 UAX \#29.
19399+
The estimated width of the following code points is 2:
19400+
\begin{itemize}
19401+
\item \tcode{U+1100-U+115F}
19402+
\item \tcode{U+2329-U+232A}
19403+
\item \tcode{U+2E80-U+303E}
19404+
\item \tcode{U+3040-U+A4CF}
19405+
\item \tcode{U+AC00-U+D7A3}
19406+
\item \tcode{U+F900-U+FAFF}
19407+
\item \tcode{U+FE10-U+FE19}
19408+
\item \tcode{U+FE30-U+FE6F}
19409+
\item \tcode{U+FF00-U+FF60}
19410+
\item \tcode{U+FFE0-U+FFE6}
19411+
\item \tcode{U+1F300-U+1F64F}
19412+
\item \tcode{U+1F900-U+1F9FF}
19413+
\item \tcode{U+20000-U+2FFFD}
19414+
\item \tcode{U+30000-U+3FFFD}
19415+
\end{itemize}
19416+
The estimated width of other code points is 1.
19417+
19418+
\pnum
19419+
For a string in a non-Unicode encoding, the width of a string is unspecified.
19420+
1937419421
\pnum
1937519422
A zero (\tcode{0}) character
1937619423
preceding the \fmtgrammarterm{width} field
@@ -19398,7 +19445,13 @@
1939819445
the precision or maximum field size.
1939919446
It can only be used with floating-point and string types.
1940019447
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.
19448+
For string types, this field provides an upper bound
19449+
for the estimated width of the prefix of
19450+
the input string that is copied into the output.
19451+
For a string in a Unicode encoding,
19452+
the formatter copies to the output
19453+
the longest prefix of whole extended grapheme clusters
19454+
whose estimated width is no greater than the precision.
1940219455

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

0 commit comments

Comments
 (0)