<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><a moz-do-not-send="true"
href="http://eel.is/c++draft/format#string.std-7">[format.string.std]p7</a>
states:</p>
<p>
<blockquote type="cite">
<p>The <i>positive-integer</i> in <i>width</i> is a decimal
integer defining the minimum field width. If <i>width</i> is
not specified, there is no minimum field width, and the field
width is determined based on the content of the field.</p>
</blockquote>
</p>
<p>Is field width measured in code units, code points, or something
else?</p>
<p>Consider the following example assuming a UTF-8 locale:<br>
</p>
<p><tt>std::format("{}", "\xC3\x81"); // U+00C1</tt><tt>
{ </tt><tt>LATIN CAPITAL LETTER A WITH ACUTE }</tt><br>
<tt>std::format("{}", "\x41\xCC\x81"); // U+0041 U+0301 { </tt><tt>LATIN
CAPITAL LETTER A } { </tt><tt>COMBINING ACUTE ACCENT }<br>
</tt></p>
<p>In both cases, the arguments encode the same user-perceived
character (Á). The first uses two UTF-8 code units to encode a
single code point that represents a single glyph using a composed
Unicode normalization form. The second uses three code units to
encode two code points that represent the same glyph using a
decomposed Unicode normalization form.</p>
<p>How is the field width determined? If measured in code units,
the first has a width of 2 and the second of 3. If measured in
code points, the first has a width of 1 and the second of 2. If
measured in grapheme clusters, both have a width of 1. Is the
determination locale dependent?</p>
<p><b>Proposed resolution:</b></p>
<p>Field widths are measured in code units and are not locale
dependent. Modify <a moz-do-not-send="true"
href="http://eel.is/c++draft/format#string.std-7">[format.string.std]p7</a>
as follows:</p>
<p> </p>
<blockquote type="cite">
<p>The <i>positive-integer</i> in <i>width</i> is a decimal
integer defining the minimum field width. If <i>width</i> is
not specified, there is no minimum field width, and the field
width is determined based on the content of the field. <b><font
color="#33cc00">Field width is measured in code units. Each
byte of a multibyte character contributes to the field
width.</font></b><br>
</p>
</blockquote>
<p>(<i>code unit</i> is not formally defined in the standard. Most
uses occur in UTF-8 and UTF-16 specific contexts, but <a
moz-do-not-send="true" href="http://eel.is/c++draft/lex.ext#5">[lex.ext]p5</a>
uses it in an encoding agnostic context.)<br>
</p>
<p>Tom.<br>
</p>
</body>
</html>