- tmp/tmpj7c7ybwl/{from.md → to.md} +138 -97
tmp/tmpj7c7ybwl/{from.md → to.md}
RENAMED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
#### Standard format specifiers <a id="format.string.std">[[format.string.std]]</a>
|
| 2 |
|
| 3 |
-
Each `formatter`
|
| 4 |
for fundamental and string types interprets *format-spec* as a
|
| 5 |
*std-format-spec*.
|
| 6 |
|
| 7 |
[*Note 1*: The format specification can be used to specify such details
|
| 8 |
-
as field width, alignment, padding, and decimal precision. Some
|
| 9 |
-
formatting options are only supported for arithmetic
|
| 10 |
types. — *end note*]
|
| 11 |
|
| 12 |
The syntax of format specifications is as follows:
|
| 13 |
|
| 14 |
``` bnf
|
|
@@ -48,21 +48,40 @@ precision
|
|
| 48 |
'.' '{' arg-idₒₚₜ '}'
|
| 49 |
```
|
| 50 |
|
| 51 |
``` bnf
|
| 52 |
type one of
|
| 53 |
-
'a A b B c d e E f F g G o p s x X'
|
| 54 |
```
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
following it, which must be one of the alignment options. If the second
|
| 59 |
character of *std-format-spec* is not a valid alignment option, then it
|
| 60 |
-
is assumed that
|
| 61 |
absent. — *end note*]
|
| 62 |
|
| 63 |
-
The *align*
|
| 64 |
various alignment options is as specified in [[format.align]].
|
| 65 |
|
| 66 |
[*Example 1*:
|
| 67 |
|
| 68 |
``` cpp
|
|
@@ -72,34 +91,49 @@ string s1 = format("{:6}", 'x'); // value of s1 is "x\ \ \ \ \ "
|
|
| 72 |
string s2 = format("{:*<6}", 'x'); // value of s2 is "x*****"
|
| 73 |
string s3 = format("{:*>6}", 'x'); // value of s3 is "*****x"
|
| 74 |
string s4 = format("{:*^6}", 'x'); // value of s4 is "**x***"
|
| 75 |
string s5 = format("{:6d}", c); // value of s5 is "\ \ \ 120"
|
| 76 |
string s6 = format("{:6}", true); // value of s6 is "true\ \ "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
```
|
| 78 |
|
| 79 |
— *end example*]
|
| 80 |
|
| 81 |
-
[*Note
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
**Table: Meaning of align options** <a id="format.align">[format.align]</a>
|
| 86 |
|
| 87 |
| Option | Meaning |
|
| 88 |
-
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 89 |
-
| `<` | Forces the
|
| 90 |
-
| % `>` | Forces the
|
| 91 |
-
| % `^` | Forces the
|
| 92 |
|
| 93 |
|
| 94 |
The *sign* option is only valid for arithmetic types other than `charT`
|
| 95 |
and `bool` or when an integer presentation type is specified. The
|
| 96 |
meaning of the various options is as specified in [[format.sign]].
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
The *sign* option applies to floating-point infinity and NaN.
|
| 103 |
|
| 104 |
[*Example 2*:
|
| 105 |
|
|
@@ -125,88 +159,82 @@ form causes the result of the conversion of finite values to always
|
|
| 125 |
contain a decimal-point character, even if no digits follow it.
|
| 126 |
Normally, a decimal-point character appears in the result of these
|
| 127 |
conversions only if a digit follows it. In addition, for `g` and `G`
|
| 128 |
conversions, trailing zeros are not removed from the result.
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
The *positive-integer* in *width* is a decimal integer defining the
|
| 137 |
-
minimum field width. If *width* is not specified, there is no minimum
|
| 138 |
-
field width, and the field width is determined based on the content of
|
| 139 |
-
the field.
|
| 140 |
-
|
| 141 |
-
The *width* of a string is defined as the estimated number of column
|
| 142 |
-
positions appropriate for displaying it in a terminal.
|
| 143 |
-
|
| 144 |
-
[*Note 5*: This is similar to the semantics of the POSIX `wcswidth`
|
| 145 |
-
function. — *end note*]
|
| 146 |
-
|
| 147 |
-
For the purposes of width computation, a string is assumed to be in a
|
| 148 |
-
locale-independent, implementation-defined encoding. Implementations
|
| 149 |
-
should use a Unicode encoding on platforms capable of displaying Unicode
|
| 150 |
-
text in a terminal.
|
| 151 |
-
|
| 152 |
-
[*Note 6*: This is the case for Windows-based and many POSIX-based
|
| 153 |
-
operating systems. — *end note*]
|
| 154 |
-
|
| 155 |
-
For a string in a Unicode encoding, implementations should estimate the
|
| 156 |
-
width of a string as the sum of estimated widths of the first code
|
| 157 |
-
points in its extended grapheme clusters. The extended grapheme clusters
|
| 158 |
-
of a string are defined by UAX \#29. The estimated width of the
|
| 159 |
-
following code points is 2:
|
| 160 |
-
|
| 161 |
-
- `U+1100-U+115F`
|
| 162 |
-
- `U+2329-U+232A`
|
| 163 |
-
- `U+2E80-U+303E`
|
| 164 |
-
- `U+3040-U+A4CF`
|
| 165 |
-
- `U+AC00-U+D7A3`
|
| 166 |
-
- `U+F900-U+FAFF`
|
| 167 |
-
- `U+FE10-U+FE19`
|
| 168 |
-
- `U+FE30-U+FE6F`
|
| 169 |
-
- `U+FF00-U+FF60`
|
| 170 |
-
- `U+FFE0-U+FFE6`
|
| 171 |
-
- `U+1F300-U+1F64F`
|
| 172 |
-
- `U+1F900-U+1F9FF`
|
| 173 |
-
- `U+20000-U+2FFFD`
|
| 174 |
-
- `U+30000-U+3FFFD`
|
| 175 |
-
|
| 176 |
-
The estimated width of other code points is 1.
|
| 177 |
-
|
| 178 |
-
For a string in a non-Unicode encoding, the width of a string is
|
| 179 |
-
unspecified.
|
| 180 |
-
|
| 181 |
-
A zero (`0`) character preceding the *width* field pads the field with
|
| 182 |
-
leading zeros (following any indication of sign or base) to the field
|
| 183 |
-
width, except when applied to an infinity or NaN. This option is only
|
| 184 |
-
valid for arithmetic types other than `charT` and `bool` or when an
|
| 185 |
-
integer presentation type is specified. If the `0` character and an
|
| 186 |
-
*align* option both appear, the `0` character is ignored.
|
| 187 |
|
| 188 |
[*Example 3*:
|
| 189 |
|
| 190 |
``` cpp
|
| 191 |
char c = 120;
|
| 192 |
string s1 = format("{:+06d}", c); // value of s1 is "+00120"
|
| 193 |
string s2 = format("{:#06x}", 0xa); // value of s2 is "0x000a"
|
| 194 |
-
string s3 = format("{:<06}", -42); // value of s3 is "-42\ \ \ " (0
|
|
|
|
| 195 |
```
|
| 196 |
|
| 197 |
— *end example*]
|
| 198 |
|
| 199 |
-
The *
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
When the `L` option is used, the form used for the conversion is called
|
| 210 |
the *locale-specific form*. The `L` option is only valid for arithmetic
|
| 211 |
types, and its effect depends upon the type.
|
| 212 |
|
|
@@ -227,22 +255,23 @@ The available string presentation types are specified in
|
|
| 227 |
[[format.type.string]].
|
| 228 |
|
| 229 |
**Table: Meaning of type options for strings** <a id="format.type.string">[format.type.string]</a>
|
| 230 |
|
| 231 |
| Type | Meaning |
|
| 232 |
-
| --------- | -------------------------------- |
|
| 233 |
| none, `s` | Copies the string to the output. |
|
|
|
|
| 234 |
|
| 235 |
|
| 236 |
The meaning of some non-string presentation types is defined in terms of
|
| 237 |
a call to `to_chars`. In such cases, let \[`first`, `last`) be a range
|
| 238 |
large enough to hold the `to_chars` output and `value` be the formatting
|
| 239 |
argument value. Formatting is done as if by calling `to_chars` as
|
| 240 |
specified and copying the output through the output iterator of the
|
| 241 |
format context.
|
| 242 |
|
| 243 |
-
[*Note
|
| 244 |
copying the output through the output iterator as specified by the
|
| 245 |
format specifiers. — *end note*]
|
| 246 |
|
| 247 |
The available integer presentation types for integral types other than
|
| 248 |
`bool` and `charT` are specified in [[format.type.int]].
|
|
@@ -251,49 +280,61 @@ The available integer presentation types for integral types other than
|
|
| 251 |
|
| 252 |
``` cpp
|
| 253 |
string s0 = format("{}", 42); // value of s0 is "42"
|
| 254 |
string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // value of s1 is "101010 42 52 2a"
|
| 255 |
string s2 = format("{0:#x} {0:#X}", 42); // value of s2 is "0x2a 0X2A"
|
| 256 |
-
string s3 = format("{:L}", 1234); // value of s3
|
| 257 |
// (depending on the locale)
|
| 258 |
```
|
| 259 |
|
| 260 |
— *end example*]
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
The available `charT` presentation types are specified in
|
| 266 |
[[format.type.char]].
|
| 267 |
|
| 268 |
**Table: Meaning of type options for `charT`** <a id="format.type.char">[format.type.char]</a>
|
| 269 |
|
| 270 |
| Type | Meaning |
|
| 271 |
-
| ------------------------------ | ------------------------------------ |
|
| 272 |
| none, `c` | Copies the character to the output. |
|
| 273 |
| % `b`, `B`, `d`, `o`, `x`, `X` | As specified in [[format.type.int]]. |
|
|
|
|
| 274 |
|
| 275 |
|
| 276 |
The available `bool` presentation types are specified in
|
| 277 |
[[format.type.bool]].
|
| 278 |
|
| 279 |
**Table: Meaning of type options for `bool`** <a id="format.type.bool">[format.type.bool]</a>
|
| 280 |
|
| 281 |
| Type | Meaning |
|
| 282 |
-
| ------------------------------
|
| 283 |
| none, `s` | Copies textual representation, either `true` or `false`, to the output. |
|
| 284 |
-
| % `b`, `B`, `
|
| 285 |
|
| 286 |
|
| 287 |
The available floating-point presentation types and their meanings for
|
| 288 |
values other than infinity and NaN are specified in
|
| 289 |
[[format.type.float]]. For lower-case presentation types, infinity and
|
| 290 |
NaN are formatted as `inf` and `nan`, respectively. For upper-case
|
| 291 |
presentation types, infinity and NaN are formatted as `INF` and `NAN`,
|
| 292 |
respectively.
|
| 293 |
|
| 294 |
-
[*Note
|
| 295 |
*sign* option. — *end note*]
|
| 296 |
|
| 297 |
**Table: Meaning of type options for floating-point types** <a id="format.type.float">[format.type.float]</a>
|
| 298 |
|
| 299 |
| Type | Meaning |
|
|
@@ -309,15 +350,15 @@ respectively.
|
|
| 309 |
|
| 310 |
|
| 311 |
The available pointer presentation types and their mapping to `to_chars`
|
| 312 |
are specified in [[format.type.ptr]].
|
| 313 |
|
| 314 |
-
[*Note
|
| 315 |
`nullptr_t`. — *end note*]
|
| 316 |
|
| 317 |
**Table: Meaning of type options for pointer types** <a id="format.type.ptr">[format.type.ptr]</a>
|
| 318 |
|
| 319 |
| Type | Meaning |
|
| 320 |
-
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 321 |
-
| none, `p` | If `uintptr_t` is defined, \begin{codeblock} to_chars(first, last, reinterpret_cast<uintptr_t>(value), 16) \end{codeblock} with the prefix `0x`
|
| 322 |
|
| 323 |
|
|
|
|
| 1 |
#### Standard format specifiers <a id="format.string.std">[[format.string.std]]</a>
|
| 2 |
|
| 3 |
+
Each `formatter` specialization described in [[format.formatter.spec]]
|
| 4 |
for fundamental and string types interprets *format-spec* as a
|
| 5 |
*std-format-spec*.
|
| 6 |
|
| 7 |
[*Note 1*: The format specification can be used to specify such details
|
| 8 |
+
as minimum field width, alignment, padding, and decimal precision. Some
|
| 9 |
+
of the formatting options are only supported for arithmetic
|
| 10 |
types. — *end note*]
|
| 11 |
|
| 12 |
The syntax of format specifications is as follows:
|
| 13 |
|
| 14 |
``` bnf
|
|
|
|
| 48 |
'.' '{' arg-idₒₚₜ '}'
|
| 49 |
```
|
| 50 |
|
| 51 |
``` bnf
|
| 52 |
type one of
|
| 53 |
+
'a A b B c d e E f F g G o p s x X ?'
|
| 54 |
```
|
| 55 |
|
| 56 |
+
Field widths are specified in *field width units*; the number of column
|
| 57 |
+
positions required to display a sequence of characters in a terminal.
|
| 58 |
+
The *minimum field width* is the number of field width units a
|
| 59 |
+
replacement field minimally requires of the formatted sequence of
|
| 60 |
+
characters produced for a format argument. The *estimated field width*
|
| 61 |
+
is the number of field width units that are required for the formatted
|
| 62 |
+
sequence of characters produced for a format argument independent of the
|
| 63 |
+
effects of the *width* option. The *padding width* is the greater of `0`
|
| 64 |
+
and the difference of the minimum field width and the estimated field
|
| 65 |
+
width.
|
| 66 |
+
|
| 67 |
+
[*Note 2*: The POSIX `wcswidth` function is an example of a function
|
| 68 |
+
that, given a string, returns the number of column positions required by
|
| 69 |
+
a terminal to display the string. — *end note*]
|
| 70 |
+
|
| 71 |
+
The *fill character* is the character denoted by the *fill* option or,
|
| 72 |
+
if the *fill* option is absent, the space character. For a format
|
| 73 |
+
specification in UTF-8, UTF-16, or UTF-32, the fill character
|
| 74 |
+
corresponds to a single Unicode scalar value.
|
| 75 |
+
|
| 76 |
+
[*Note 3*: The presence of a *fill* option is signaled by the character
|
| 77 |
following it, which must be one of the alignment options. If the second
|
| 78 |
character of *std-format-spec* is not a valid alignment option, then it
|
| 79 |
+
is assumed that the *fill* and *align* options are both
|
| 80 |
absent. — *end note*]
|
| 81 |
|
| 82 |
+
The *align* option applies to all argument types. The meaning of the
|
| 83 |
various alignment options is as specified in [[format.align]].
|
| 84 |
|
| 85 |
[*Example 1*:
|
| 86 |
|
| 87 |
``` cpp
|
|
|
|
| 91 |
string s2 = format("{:*<6}", 'x'); // value of s2 is "x*****"
|
| 92 |
string s3 = format("{:*>6}", 'x'); // value of s3 is "*****x"
|
| 93 |
string s4 = format("{:*^6}", 'x'); // value of s4 is "**x***"
|
| 94 |
string s5 = format("{:6d}", c); // value of s5 is "\ \ \ 120"
|
| 95 |
string s6 = format("{:6}", true); // value of s6 is "true\ \ "
|
| 96 |
+
string s7 = format("{:*<6.3}", "123456"); // value of s7 is "123***"
|
| 97 |
+
string s8 = format("{:02}", 1234); // value of s8 is "1234"
|
| 98 |
+
string s9 = format("{:*<}", "12"); // value of s9 is "12"
|
| 99 |
+
string sA = format("{:*<6}", "12345678"); // value of sA is "12345678"
|
| 100 |
```
|
| 101 |
|
| 102 |
— *end example*]
|
| 103 |
|
| 104 |
+
[*Note 4*: The *fill*, *align*, and `0` options have no effect when the
|
| 105 |
+
minimum field width is not greater than the estimated field width
|
| 106 |
+
because padding width is `0` in that case. Since fill characters are
|
| 107 |
+
assumed to have a field width of `1`, use of a character with a
|
| 108 |
+
different field width can produce misaligned output. The
|
| 109 |
+
U+1f921 (clown face) character has a field width of `2`. The examples
|
| 110 |
+
above that include that character illustrate the effect of the field
|
| 111 |
+
width when that character is used as a fill character as opposed to when
|
| 112 |
+
it is used as a formatting argument. — *end note*]
|
| 113 |
|
| 114 |
**Table: Meaning of align options** <a id="format.align">[format.align]</a>
|
| 115 |
|
| 116 |
| Option | Meaning |
|
| 117 |
+
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| 118 |
+
| `<` | Forces the formatted argument to be aligned to the start of the field by inserting $n$ fill characters after the formatted argument where $n$ is the padding width. This is the default for non-arithmetic non-pointer types, `charT`, and `bool`, unless an integer presentation type is specified. |
|
| 119 |
+
| % `>` | Forces the formatted argument to be aligned to the end of the field by inserting $n$ fill characters before the formatted argument where $n$ is the padding width. This is the default for arithmetic types other than `charT` and `bool`, pointer types, or when an integer presentation type is specified. |
|
| 120 |
+
| % `^` | Forces the formatted argument to be centered within the field by inserting $\bigl\lfloor \frac{n}{2} \bigr\rfloor$ fill characters before and $\bigl\lceil \frac{n}{2} \bigr\rceil$ fill characters after the formatted argument, where $n$ is the padding width. |
|
| 121 |
|
| 122 |
|
| 123 |
The *sign* option is only valid for arithmetic types other than `charT`
|
| 124 |
and `bool` or when an integer presentation type is specified. The
|
| 125 |
meaning of the various options is as specified in [[format.sign]].
|
| 126 |
|
| 127 |
+
**Table: Meaning of sign options** <a id="format.sign">[format.sign]</a>
|
| 128 |
+
|
| 129 |
+
| Option | Meaning |
|
| 130 |
+
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| 131 |
+
| `+` | Indicates that a sign should be used for both non-negative and negative numbers. The `+` sign is inserted before the output of `to_chars` for non-negative numbers other than negative zero. *For negative numbers and negative zero the output of `to_chars` will already contain the sign so no additional transformation is performed.* |
|
| 132 |
+
| % `-` | Indicates that a sign should be used for negative numbers and negative zero only (this is the default behavior). |
|
| 133 |
+
| % space | Indicates that a leading space should be used for non-negative numbers other than negative zero, and a minus sign for negative numbers and negative zero. |
|
| 134 |
+
|
| 135 |
|
| 136 |
The *sign* option applies to floating-point infinity and NaN.
|
| 137 |
|
| 138 |
[*Example 2*:
|
| 139 |
|
|
|
|
| 159 |
contain a decimal-point character, even if no digits follow it.
|
| 160 |
Normally, a decimal-point character appears in the result of these
|
| 161 |
conversions only if a digit follows it. In addition, for `g` and `G`
|
| 162 |
conversions, trailing zeros are not removed from the result.
|
| 163 |
|
| 164 |
+
The `0` option is valid for arithmetic types other than `charT` and
|
| 165 |
+
`bool` or when an integer presentation type is specified. For formatting
|
| 166 |
+
arguments that have a value other than an infinity or a NaN, this option
|
| 167 |
+
pads the formatted argument by inserting the `0` character n times
|
| 168 |
+
following the sign or base prefix indicators (if any) where n is `0` if
|
| 169 |
+
the *align* option is present and is the padding width otherwise.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
[*Example 3*:
|
| 172 |
|
| 173 |
``` cpp
|
| 174 |
char c = 120;
|
| 175 |
string s1 = format("{:+06d}", c); // value of s1 is "+00120"
|
| 176 |
string s2 = format("{:#06x}", 0xa); // value of s2 is "0x000a"
|
| 177 |
+
string s3 = format("{:<06}", -42); // value of s3 is "-42\ \ \ " (0 has no effect)
|
| 178 |
+
string s4 = format("{:06}", inf); // value of s4 is "\ \ \ inf" (0 has no effect)
|
| 179 |
```
|
| 180 |
|
| 181 |
— *end example*]
|
| 182 |
|
| 183 |
+
The *width* option specifies the minimum field width. If the *width*
|
| 184 |
+
option is absent, the minimum field width is `0`.
|
| 185 |
+
|
| 186 |
+
If `{ \opt{arg-id} }` is used in a *width* or *precision* option, the
|
| 187 |
+
value of the corresponding formatting argument is used as the value of
|
| 188 |
+
the option. If the corresponding formatting argument is not of standard
|
| 189 |
+
signed or unsigned integer type, or its value is negative, an exception
|
| 190 |
+
of type `format_error` is thrown.
|
| 191 |
+
|
| 192 |
+
If *positive-integer* is used in a *width* option, the value of the
|
| 193 |
+
*positive-integer* is interpreted as a decimal integer and used as the
|
| 194 |
+
value of the option.
|
| 195 |
+
|
| 196 |
+
For the purposes of width computation, a string is assumed to be in a
|
| 197 |
+
locale-independent, *implementation-defined* encoding. Implementations
|
| 198 |
+
should use either UTF-8, UTF-16, or UTF-32, on platforms capable of
|
| 199 |
+
displaying Unicode text in a terminal.
|
| 200 |
+
|
| 201 |
+
[*Note 5*:
|
| 202 |
+
|
| 203 |
+
This is the case for Windows[^2]
|
| 204 |
+
|
| 205 |
+
-based and many POSIX-based operating systems.
|
| 206 |
+
|
| 207 |
+
— *end note*]
|
| 208 |
+
|
| 209 |
+
For a sequence of characters in UTF-8, UTF-16, or UTF-32, an
|
| 210 |
+
implementation should use as its field width the sum of the field widths
|
| 211 |
+
of the first code point of each extended grapheme cluster. Extended
|
| 212 |
+
grapheme clusters are defined by UAX \#29 of the Unicode Standard. The
|
| 213 |
+
following code points have a field width of 2:
|
| 214 |
+
|
| 215 |
+
- any code point with the `East_Asian_Width="W"` or
|
| 216 |
+
`East_Asian_Width="F"` Derived Extracted Property as described by UAX
|
| 217 |
+
\#44 of the Unicode Standard
|
| 218 |
+
- `U+4dc0` – `U+4dff` (Yijing Hexagram Symbols)
|
| 219 |
+
- `U+1f300` – `U+1f5ff` (Miscellaneous Symbols and Pictographs)
|
| 220 |
+
- `U+1f900` – `U+1f9ff` (Supplemental Symbols and Pictographs)
|
| 221 |
+
|
| 222 |
+
The field width of all other code points is 1.
|
| 223 |
+
|
| 224 |
+
For a sequence of characters in neither UTF-8, UTF-16, nor UTF-32, the
|
| 225 |
+
field width is unspecified.
|
| 226 |
+
|
| 227 |
+
The *precision* option is valid for floating-point and string types. For
|
| 228 |
+
floating-point types, the value of this option specifies the precision
|
| 229 |
+
to be used for the floating-point presentation type. For string types,
|
| 230 |
+
this option specifies the longest prefix of the formatted argument to be
|
| 231 |
+
included in the replacement field such that the field width of the
|
| 232 |
+
prefix is no greater than the value of this option.
|
| 233 |
+
|
| 234 |
+
If *nonnegative-integer* is used in a *precision* option, the value of
|
| 235 |
+
the decimal integer is used as the value of the option.
|
| 236 |
|
| 237 |
When the `L` option is used, the form used for the conversion is called
|
| 238 |
the *locale-specific form*. The `L` option is only valid for arithmetic
|
| 239 |
types, and its effect depends upon the type.
|
| 240 |
|
|
|
|
| 255 |
[[format.type.string]].
|
| 256 |
|
| 257 |
**Table: Meaning of type options for strings** <a id="format.type.string">[format.type.string]</a>
|
| 258 |
|
| 259 |
| Type | Meaning |
|
| 260 |
+
| --------- | ------------------------------------------------------------------ |
|
| 261 |
| none, `s` | Copies the string to the output. |
|
| 262 |
+
| % `?` | Copies the escaped string [[format.string.escaped]] to the output. |
|
| 263 |
|
| 264 |
|
| 265 |
The meaning of some non-string presentation types is defined in terms of
|
| 266 |
a call to `to_chars`. In such cases, let \[`first`, `last`) be a range
|
| 267 |
large enough to hold the `to_chars` output and `value` be the formatting
|
| 268 |
argument value. Formatting is done as if by calling `to_chars` as
|
| 269 |
specified and copying the output through the output iterator of the
|
| 270 |
format context.
|
| 271 |
|
| 272 |
+
[*Note 6*: Additional padding and adjustments are performed prior to
|
| 273 |
copying the output through the output iterator as specified by the
|
| 274 |
format specifiers. — *end note*]
|
| 275 |
|
| 276 |
The available integer presentation types for integral types other than
|
| 277 |
`bool` and `charT` are specified in [[format.type.int]].
|
|
|
|
| 280 |
|
| 281 |
``` cpp
|
| 282 |
string s0 = format("{}", 42); // value of s0 is "42"
|
| 283 |
string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // value of s1 is "101010 42 52 2a"
|
| 284 |
string s2 = format("{0:#x} {0:#X}", 42); // value of s2 is "0x2a 0X2A"
|
| 285 |
+
string s3 = format("{:L}", 1234); // value of s3 can be "1,234"
|
| 286 |
// (depending on the locale)
|
| 287 |
```
|
| 288 |
|
| 289 |
— *end example*]
|
| 290 |
|
| 291 |
+
**Table: Meaning of type options for integer types** <a id="format.type.int">[format.type.int]</a>
|
| 292 |
+
|
| 293 |
+
| Type | Meaning |
|
| 294 |
+
| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 295 |
+
| `b` | `to_chars(first, last, value, 2)`; \indextext{base prefix}% the base prefix is `0b`. |
|
| 296 |
+
| % `B` | The same as `b`, except that \indextext{base prefix}% the base prefix is `0B`. |
|
| 297 |
+
| % `c` | Copies the character `static_cast<charT>(value)` to the output. Throws `format_error` if `value` is not in the range of representable values for `charT`. |
|
| 298 |
+
| % `d` | `to_chars(first, last, value)`. |
|
| 299 |
+
| % `o` | `to_chars(first, last, value, 8)`; \indextext{base prefix}% the base prefix is `0` if `value` is nonzero and is empty otherwise. |
|
| 300 |
+
| % `x` | `to_chars(first, last, value, 16)`; \indextext{base prefix}% the base prefix is `0x`. |
|
| 301 |
+
| % `X` | The same as `x`, except that it uses uppercase letters for digits above 9 and \indextext{base prefix}% the base prefix is `0X`. |
|
| 302 |
+
| % none | The same as `d`. *If the formatting argument type is `charT` or `bool`, the default is instead `c` or `s`, respectively.* |
|
| 303 |
+
|
| 304 |
|
| 305 |
The available `charT` presentation types are specified in
|
| 306 |
[[format.type.char]].
|
| 307 |
|
| 308 |
**Table: Meaning of type options for `charT`** <a id="format.type.char">[format.type.char]</a>
|
| 309 |
|
| 310 |
| Type | Meaning |
|
| 311 |
+
| ------------------------------ | --------------------------------------------------------------------- |
|
| 312 |
| none, `c` | Copies the character to the output. |
|
| 313 |
| % `b`, `B`, `d`, `o`, `x`, `X` | As specified in [[format.type.int]]. |
|
| 314 |
+
| % `?` | Copies the escaped character [[format.string.escaped]] to the output. |
|
| 315 |
|
| 316 |
|
| 317 |
The available `bool` presentation types are specified in
|
| 318 |
[[format.type.bool]].
|
| 319 |
|
| 320 |
**Table: Meaning of type options for `bool`** <a id="format.type.bool">[format.type.bool]</a>
|
| 321 |
|
| 322 |
| Type | Meaning |
|
| 323 |
+
| ------------------------------ | -------------------------------------------------------------------------------------- |
|
| 324 |
| none, `s` | Copies textual representation, either `true` or `false`, to the output. |
|
| 325 |
+
| % `b`, `B`, `d`, `o`, `x`, `X` | As specified in [[format.type.int]] for the value `static_cast<unsigned char>(value)`. |
|
| 326 |
|
| 327 |
|
| 328 |
The available floating-point presentation types and their meanings for
|
| 329 |
values other than infinity and NaN are specified in
|
| 330 |
[[format.type.float]]. For lower-case presentation types, infinity and
|
| 331 |
NaN are formatted as `inf` and `nan`, respectively. For upper-case
|
| 332 |
presentation types, infinity and NaN are formatted as `INF` and `NAN`,
|
| 333 |
respectively.
|
| 334 |
|
| 335 |
+
[*Note 7*: In either case, a sign is included if indicated by the
|
| 336 |
*sign* option. — *end note*]
|
| 337 |
|
| 338 |
**Table: Meaning of type options for floating-point types** <a id="format.type.float">[format.type.float]</a>
|
| 339 |
|
| 340 |
| Type | Meaning |
|
|
|
|
| 350 |
|
| 351 |
|
| 352 |
The available pointer presentation types and their mapping to `to_chars`
|
| 353 |
are specified in [[format.type.ptr]].
|
| 354 |
|
| 355 |
+
[*Note 8*: Pointer presentation types also apply to
|
| 356 |
`nullptr_t`. — *end note*]
|
| 357 |
|
| 358 |
**Table: Meaning of type options for pointer types** <a id="format.type.ptr">[format.type.ptr]</a>
|
| 359 |
|
| 360 |
| Type | Meaning |
|
| 361 |
+
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 362 |
+
| none, `p` | If `uintptr_t` is defined, \begin{codeblock} to_chars(first, last, reinterpret_cast<uintptr_t>(value), 16) \end{codeblock} with the prefix `0x` inserted immediately before the output of `to_chars`; otherwise, implementation-defined. |
|
| 363 |
|
| 364 |
|