- tmp/tmpb4frfnd_/{from.md → to.md} +276 -439
tmp/tmpb4frfnd_/{from.md → to.md}
RENAMED
|
@@ -3,17 +3,17 @@
|
|
| 3 |
Each of the standard categories includes a family of facets. Some of
|
| 4 |
these implement formatting or parsing of a datum, for use by standard or
|
| 5 |
users’ iostream operators `<<` and `>>`, as members `put()` and `get()`,
|
| 6 |
respectively. Each such member function takes an `ios_base&` argument
|
| 7 |
whose members `flags()`, `precision()`, and `width()`, specify the
|
| 8 |
-
format of the corresponding datum
|
| 9 |
need to use other facets call its member `getloc()` to retrieve the
|
| 10 |
locale imbued there. Formatting facets use the character argument `fill`
|
| 11 |
to fill out the specified width where necessary.
|
| 12 |
|
| 13 |
The `put()` members make no provision for error reporting. (Any failures
|
| 14 |
-
of the OutputIterator argument
|
| 15 |
iterator.) The `get()` members take an `ios_base::iostate&` argument
|
| 16 |
whose value they ignore, but set to `ios_base::failbit` in case of a
|
| 17 |
parse error.
|
| 18 |
|
| 19 |
Within this clause it is unspecified whether one virtual function calls
|
|
@@ -23,11 +23,11 @@ another virtual function.
|
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
namespace std {
|
| 26 |
class ctype_base {
|
| 27 |
public:
|
| 28 |
-
using mask =
|
| 29 |
|
| 30 |
// numeric values are for exposition only.
|
| 31 |
static const mask space = 1 << 0;
|
| 32 |
static const mask print = 1 << 1;
|
| 33 |
static const mask cntrl = 1 << 2;
|
|
@@ -42,11 +42,11 @@ namespace std {
|
|
| 42 |
static const mask graph = alnum | punct;
|
| 43 |
};
|
| 44 |
}
|
| 45 |
```
|
| 46 |
|
| 47 |
-
The type `mask` is a bitmask type
|
| 48 |
|
| 49 |
#### Class template `ctype` <a id="locale.ctype">[[locale.ctype]]</a>
|
| 50 |
|
| 51 |
``` cpp
|
| 52 |
namespace std {
|
|
@@ -94,35 +94,32 @@ namespace std {
|
|
| 94 |
|
| 95 |
Class `ctype` encapsulates the C library `<cctype>` features. `istream`
|
| 96 |
members are required to use `ctype<>` for character classing during
|
| 97 |
input parsing.
|
| 98 |
|
| 99 |
-
The specializations required in
|
| 100 |
-
[[
|
| 101 |
-
|
| 102 |
-
|
| 103 |
|
| 104 |
##### `ctype` members <a id="locale.ctype.members">[[locale.ctype.members]]</a>
|
| 105 |
|
| 106 |
``` cpp
|
| 107 |
bool is(mask m, charT c) const;
|
| 108 |
-
const charT* is(const charT* low, const charT* high,
|
| 109 |
-
mask* vec) const;
|
| 110 |
```
|
| 111 |
|
| 112 |
*Returns:* `do_is(m, c)` or `do_is(low, high, vec)`.
|
| 113 |
|
| 114 |
``` cpp
|
| 115 |
-
const charT* scan_is(mask m,
|
| 116 |
-
const charT* low, const charT* high) const;
|
| 117 |
```
|
| 118 |
|
| 119 |
*Returns:* `do_scan_is(m, low, high)`.
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
-
const charT* scan_not(mask m,
|
| 123 |
-
const charT* low, const charT* high) const;
|
| 124 |
```
|
| 125 |
|
| 126 |
*Returns:* `do_scan_not(m, low, high)`.
|
| 127 |
|
| 128 |
``` cpp
|
|
@@ -146,22 +143,20 @@ const char* widen(const char* low, const char* high, charT* to) const;
|
|
| 146 |
|
| 147 |
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`.
|
| 148 |
|
| 149 |
``` cpp
|
| 150 |
char narrow(charT c, char dfault) const;
|
| 151 |
-
const charT* narrow(const charT* low, const charT* high, char dfault,
|
| 152 |
-
char* to) const;
|
| 153 |
```
|
| 154 |
|
| 155 |
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`.
|
| 156 |
|
| 157 |
##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
|
| 158 |
|
| 159 |
``` cpp
|
| 160 |
bool do_is(mask m, charT c) const;
|
| 161 |
-
const charT* do_is(const charT* low, const charT* high,
|
| 162 |
-
mask* vec) const;
|
| 163 |
```
|
| 164 |
|
| 165 |
*Effects:* Classifies a character or sequence of characters. For each
|
| 166 |
argument character, identifies a value `M` of type `ctype_base::mask`.
|
| 167 |
The second form identifies a value `M` of type `ctype_base::mask` for
|
|
@@ -219,18 +214,17 @@ which a corresponding lower-case character exists, with that character.
|
|
| 219 |
if it is known to exist, or its argument if not. The second form returns
|
| 220 |
`high`.
|
| 221 |
|
| 222 |
``` cpp
|
| 223 |
charT do_widen(char c) const;
|
| 224 |
-
const char* do_widen(const char* low, const char* high,
|
| 225 |
-
charT* dest) const;
|
| 226 |
```
|
| 227 |
|
| 228 |
*Effects:* Applies the simplest reasonable transformation from a `char`
|
| 229 |
value or sequence of `char` values to the corresponding `charT` value or
|
| 230 |
values.[^5] The only characters for which unique transformations are
|
| 231 |
-
required are those in the basic source character set
|
| 232 |
|
| 233 |
For any named `ctype` category with a `ctype <charT>` facet `ctc` and
|
| 234 |
valid `ctype_base::mask` value `M`,
|
| 235 |
`(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^6]
|
| 236 |
|
|
@@ -240,20 +234,19 @@ The second form transforms each character `*p` in the range \[`low`,
|
|
| 240 |
*Returns:* The first form returns the transformed value. The second form
|
| 241 |
returns `high`.
|
| 242 |
|
| 243 |
``` cpp
|
| 244 |
char do_narrow(charT c, char dfault) const;
|
| 245 |
-
const charT* do_narrow(const charT* low, const charT* high,
|
| 246 |
-
char dfault, char* dest) const;
|
| 247 |
```
|
| 248 |
|
| 249 |
*Effects:* Applies the simplest reasonable transformation from a `charT`
|
| 250 |
value or sequence of `charT` values to the corresponding `char` value or
|
| 251 |
values.
|
| 252 |
|
| 253 |
-
For any character `c` in the basic source character
|
| 254 |
-
|
| 255 |
|
| 256 |
``` cpp
|
| 257 |
do_widen(do_narrow(c, 0)) == c
|
| 258 |
```
|
| 259 |
|
|
@@ -282,45 +275,42 @@ namespace std {
|
|
| 282 |
class ctype_byname : public ctype<charT> {
|
| 283 |
public:
|
| 284 |
using mask = typename ctype<charT>::mask;
|
| 285 |
explicit ctype_byname(const char*, size_t refs = 0);
|
| 286 |
explicit ctype_byname(const string&, size_t refs = 0);
|
|
|
|
| 287 |
protected:
|
| 288 |
~ctype_byname();
|
| 289 |
};
|
| 290 |
}
|
| 291 |
```
|
| 292 |
|
| 293 |
-
#### `ctype`
|
| 294 |
|
| 295 |
``` cpp
|
| 296 |
namespace std {
|
| 297 |
template<>
|
| 298 |
class ctype<char> : public locale::facet, public ctype_base {
|
| 299 |
public:
|
| 300 |
using char_type = char;
|
| 301 |
|
| 302 |
-
explicit ctype(const mask* tab =
|
| 303 |
-
size_t refs = 0);
|
| 304 |
|
| 305 |
bool is(mask m, char c) const;
|
| 306 |
const char* is(const char* low, const char* high, mask* vec) const;
|
| 307 |
-
const char* scan_is (mask m,
|
| 308 |
-
|
| 309 |
-
const char* scan_not(mask m,
|
| 310 |
-
const char* low, const char* high) const;
|
| 311 |
|
| 312 |
char toupper(char c) const;
|
| 313 |
const char* toupper(char* low, const char* high) const;
|
| 314 |
char tolower(char c) const;
|
| 315 |
const char* tolower(char* low, const char* high) const;
|
| 316 |
|
| 317 |
char widen(char c) const;
|
| 318 |
const char* widen(const char* low, const char* high, char* to) const;
|
| 319 |
char narrow(char c, char dfault) const;
|
| 320 |
-
const char* narrow(const char* low, const char* high, char dfault,
|
| 321 |
-
char* to) const;
|
| 322 |
|
| 323 |
static locale::id id;
|
| 324 |
static const size_t table_size = implementation-defined;
|
| 325 |
|
| 326 |
const mask* table() const noexcept;
|
|
@@ -332,66 +322,60 @@ namespace std {
|
|
| 332 |
virtual const char* do_toupper(char* low, const char* high) const;
|
| 333 |
virtual char do_tolower(char c) const;
|
| 334 |
virtual const char* do_tolower(char* low, const char* high) const;
|
| 335 |
|
| 336 |
virtual char do_widen(char c) const;
|
| 337 |
-
virtual const char* do_widen(const char* low,
|
| 338 |
-
const char* high,
|
| 339 |
-
char* to) const;
|
| 340 |
virtual char do_narrow(char c, char dfault) const;
|
| 341 |
-
virtual const char* do_narrow(const char* low,
|
| 342 |
-
const char* high,
|
| 343 |
char dfault, char* to) const;
|
| 344 |
};
|
| 345 |
}
|
| 346 |
```
|
| 347 |
|
| 348 |
A specialization `ctype<char>` is provided so that the member functions
|
| 349 |
-
on type `char` can be implemented
|
| 350 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 351 |
|
| 352 |
-
#####
|
| 353 |
|
| 354 |
``` cpp
|
| 355 |
~ctype();
|
| 356 |
```
|
| 357 |
|
| 358 |
*Effects:* If the constructor’s first argument was nonzero, and its
|
| 359 |
second argument was `true`, does `delete [] table()`.
|
| 360 |
|
| 361 |
-
#####
|
| 362 |
|
| 363 |
In the following member descriptions, for `unsigned char` values `v`
|
| 364 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
| 365 |
implementation-specific value (possibly different for each such value
|
| 366 |
`v`) without performing the array lookup.
|
| 367 |
|
| 368 |
``` cpp
|
| 369 |
-
explicit ctype(const mask* tbl =
|
| 370 |
-
size_t refs = 0);
|
| 371 |
```
|
| 372 |
|
| 373 |
-
*
|
| 374 |
-
|
| 375 |
|
| 376 |
*Effects:* Passes its `refs` argument to its base class constructor.
|
| 377 |
|
| 378 |
``` cpp
|
| 379 |
bool is(mask m, char c) const;
|
| 380 |
-
const char* is(const char* low, const char* high,
|
| 381 |
-
mask* vec) const;
|
| 382 |
```
|
| 383 |
|
| 384 |
*Effects:* The second form, for all `*p` in the range \[`low`, `high`),
|
| 385 |
assigns into `vec[p - low]` the value `table()[(unsigned char)*p]`.
|
| 386 |
|
| 387 |
*Returns:* The first form returns `table()[(unsigned char)c] & m`; the
|
| 388 |
second form returns `high`.
|
| 389 |
|
| 390 |
``` cpp
|
| 391 |
-
const char* scan_is(mask m,
|
| 392 |
-
const char* low, const char* high) const;
|
| 393 |
```
|
| 394 |
|
| 395 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 396 |
|
| 397 |
``` cpp
|
|
@@ -399,12 +383,11 @@ table()[(unsigned char) *p] & m
|
|
| 399 |
```
|
| 400 |
|
| 401 |
is `true`.
|
| 402 |
|
| 403 |
``` cpp
|
| 404 |
-
const char* scan_not(mask m,
|
| 405 |
-
const char* low, const char* high) const;
|
| 406 |
```
|
| 407 |
|
| 408 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 409 |
|
| 410 |
``` cpp
|
|
@@ -427,20 +410,18 @@ const char* tolower(char* low, const char* high) const;
|
|
| 427 |
|
| 428 |
*Returns:* `do_tolower(c)` or `do_tolower(low, high)`, respectively.
|
| 429 |
|
| 430 |
``` cpp
|
| 431 |
char widen(char c) const;
|
| 432 |
-
const char* widen(const char* low, const char* high,
|
| 433 |
-
char* to) const;
|
| 434 |
```
|
| 435 |
|
| 436 |
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`, respectively.
|
| 437 |
|
| 438 |
``` cpp
|
| 439 |
char narrow(char c, char dfault) const;
|
| 440 |
-
const char* narrow(const char* low, const char* high,
|
| 441 |
-
char dfault, char* to) const;
|
| 442 |
```
|
| 443 |
|
| 444 |
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`,
|
| 445 |
respectively.
|
| 446 |
|
|
@@ -449,40 +430,37 @@ const mask* table() const noexcept;
|
|
| 449 |
```
|
| 450 |
|
| 451 |
*Returns:* The first constructor argument, if it was nonzero, otherwise
|
| 452 |
`classic_table()`.
|
| 453 |
|
| 454 |
-
#####
|
| 455 |
|
| 456 |
``` cpp
|
| 457 |
static const mask* classic_table() noexcept;
|
| 458 |
```
|
| 459 |
|
| 460 |
*Returns:* A pointer to the initial element of an array of size
|
| 461 |
`table_size` which represents the classifications of characters in the
|
| 462 |
`"C"` locale.
|
| 463 |
|
| 464 |
-
#####
|
| 465 |
|
| 466 |
``` cpp
|
| 467 |
char do_toupper(char) const;
|
| 468 |
const char* do_toupper(char* low, const char* high) const;
|
| 469 |
char do_tolower(char) const;
|
| 470 |
const char* do_tolower(char* low, const char* high) const;
|
| 471 |
|
| 472 |
virtual char do_widen(char c) const;
|
| 473 |
-
virtual const char* do_widen(const char* low,
|
| 474 |
-
const char* high,
|
| 475 |
-
char* to) const;
|
| 476 |
virtual char do_narrow(char c, char dfault) const;
|
| 477 |
-
virtual const char* do_narrow(const char* low,
|
| 478 |
-
const char* high,
|
| 479 |
char dfault, char* to) const;
|
| 480 |
```
|
| 481 |
|
| 482 |
These functions are described identically as those members of the same
|
| 483 |
-
name in the `ctype` class template
|
| 484 |
|
| 485 |
#### Class template `codecvt` <a id="locale.codecvt">[[locale.codecvt]]</a>
|
| 486 |
|
| 487 |
``` cpp
|
| 488 |
namespace std {
|
|
@@ -543,33 +521,32 @@ namespace std {
|
|
| 543 |
}
|
| 544 |
```
|
| 545 |
|
| 546 |
The class `codecvt<internT, externT, stateT>` is for use when converting
|
| 547 |
from one character encoding to another, such as from wide characters to
|
| 548 |
-
multibyte characters or between wide character encodings such as
|
| 549 |
and EUC.
|
| 550 |
|
| 551 |
The `stateT` argument selects the pair of character encodings being
|
| 552 |
mapped between.
|
| 553 |
|
| 554 |
-
The specializations required in
|
| 555 |
-
[[
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
`codecvt<char16_t, char, mbstate_t>` converts between the UTF-16 and
|
| 560 |
UTF-8 encoding forms, and the specialization `codecvt`
|
| 561 |
-
`<char32_t,
|
| 562 |
encoding forms. `codecvt<wchar_t, char, mbstate_t>` converts between the
|
| 563 |
-
native character sets for
|
| 564 |
-
`mbstate_t` perform conversion between encodings known to the library
|
| 565 |
implementer. Other encodings can be converted by specializing on a
|
| 566 |
-
|
| 567 |
state that is useful to communicate to or from the specialized `do_in`
|
| 568 |
or `do_out` members.
|
| 569 |
|
| 570 |
-
#####
|
| 571 |
|
| 572 |
``` cpp
|
| 573 |
result out(
|
| 574 |
stateT& state,
|
| 575 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
@@ -617,11 +594,11 @@ int length(stateT& state, const externT* from, const externT* from_end, size_t m
|
|
| 617 |
int max_length() const noexcept;
|
| 618 |
```
|
| 619 |
|
| 620 |
*Returns:* `do_max_length()`.
|
| 621 |
|
| 622 |
-
#####
|
| 623 |
|
| 624 |
``` cpp
|
| 625 |
result do_out(
|
| 626 |
stateT& state,
|
| 627 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
@@ -631,14 +608,14 @@ result do_in(
|
|
| 631 |
stateT& state,
|
| 632 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 633 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 634 |
```
|
| 635 |
|
| 636 |
-
*
|
| 637 |
-
`true`; `state` initialized, if at the beginning of a sequence,
|
| 638 |
-
equal to the result of converting the preceding characters in
|
| 639 |
-
sequence.
|
| 640 |
|
| 641 |
*Effects:* Translates characters in the source range \[`from`,
|
| 642 |
`from_end`), placing the results in sequential positions starting at
|
| 643 |
destination `to`. Converts no more than `(from_end - from)` source
|
| 644 |
elements, and stores no more than `(to_end - to)` destination elements.
|
|
@@ -649,12 +626,12 @@ element successfully converted. If returns `noconv`, `internT` and
|
|
| 649 |
`externT` are the same type and the converted sequence is identical to
|
| 650 |
the input sequence \[`from`, `from``next`). `to_next` is set equal to
|
| 651 |
`to`, the value of `state` is unchanged, and there are no changes to the
|
| 652 |
values in \[`to`, `to_end`).
|
| 653 |
|
| 654 |
-
A `codecvt` facet that is used by `basic_filebuf`
|
| 655 |
-
|
| 656 |
|
| 657 |
``` cpp
|
| 658 |
do_out(state, from, from_end, from_next, to, to_end, to_next)
|
| 659 |
```
|
| 660 |
|
|
@@ -687,13 +664,13 @@ shall also return `ok`.[^8]
|
|
| 687 |
[*Note 2*: This argument can be used, for example, to maintain shift
|
| 688 |
state, to specify conversion options (such as count only), or to
|
| 689 |
identify a cache of seek offsets. — *end note*]
|
| 690 |
|
| 691 |
*Returns:* An enumeration value, as summarized in
|
| 692 |
-
|
| 693 |
|
| 694 |
-
**Table: `do_in/do_out` result values** <a id="
|
| 695 |
|
| 696 |
| Value | Meaning |
|
| 697 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 698 |
| `ok` | completed the conversion |
|
| 699 |
| `partial` | not all source characters converted |
|
|
@@ -708,24 +685,24 @@ before another destination element can be produced.
|
|
| 708 |
|
| 709 |
``` cpp
|
| 710 |
result do_unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
|
| 711 |
```
|
| 712 |
|
| 713 |
-
*
|
| 714 |
-
if at the beginning of a sequence, or else equal to the
|
| 715 |
-
converting the preceding characters in the sequence.
|
| 716 |
|
| 717 |
*Effects:* Places characters starting at `to` that should be appended to
|
| 718 |
terminate a sequence when the current `stateT` is given by `state`.[^9]
|
| 719 |
Stores no more than `(to_end - to)` destination elements, and leaves the
|
| 720 |
`to_next` pointer pointing one beyond the last element successfully
|
| 721 |
stored.
|
| 722 |
|
| 723 |
*Returns:* An enumeration value, as summarized in
|
| 724 |
-
|
| 725 |
|
| 726 |
-
**Table: `do_unshift` result values** <a id="
|
| 727 |
|
| 728 |
| Value | Meaning |
|
| 729 |
| --------- | -------------------------------------------------------------------------------------------------------------------- |
|
| 730 |
| `ok` | completed the sequence |
|
| 731 |
| `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
|
|
@@ -750,15 +727,16 @@ valid argument values. `codecvt<char, char, mbstate_t>` returns `true`.
|
|
| 750 |
|
| 751 |
``` cpp
|
| 752 |
int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
|
| 753 |
```
|
| 754 |
|
| 755 |
-
*
|
| 756 |
-
initialized, if at the beginning of a sequence, or else
|
| 757 |
-
result of converting the preceding characters in the
|
|
|
|
| 758 |
|
| 759 |
-
*Effects:* The effect on the `state` argument is
|
| 760 |
`do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
|
| 761 |
to a buffer of at least `max` elements.
|
| 762 |
|
| 763 |
*Returns:* `(from_next-from)` where `from_next` is the largest value in
|
| 764 |
the range \[`from`, `from_end`\] such that the sequence of values in the
|
|
@@ -783,10 +761,11 @@ namespace std {
|
|
| 783 |
template<class internT, class externT, class stateT>
|
| 784 |
class codecvt_byname : public codecvt<internT, externT, stateT> {
|
| 785 |
public:
|
| 786 |
explicit codecvt_byname(const char*, size_t refs = 0);
|
| 787 |
explicit codecvt_byname(const string&, size_t refs = 0);
|
|
|
|
| 788 |
protected:
|
| 789 |
~codecvt_byname();
|
| 790 |
};
|
| 791 |
}
|
| 792 |
```
|
|
@@ -798,19 +777,18 @@ parsing. Virtual functions are provided for several numeric types.
|
|
| 798 |
Implementations may (but are not required to) delegate extraction of
|
| 799 |
smaller types to extractors for larger types.[^11]
|
| 800 |
|
| 801 |
All specifications of member functions for `num_put` and `num_get` in
|
| 802 |
the subclauses of [[category.numeric]] only apply to the
|
| 803 |
-
specializations required in Tables [[tab:
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
`
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
`ctype<>` facet to perform character classification.
|
| 812 |
|
| 813 |
Extractor and inserter members of the standard iostreams use `num_get<>`
|
| 814 |
and `num_put<>` member functions for formatting and parsing numeric
|
| 815 |
values ([[istream.formatted.reqmts]], [[ostream.formatted.reqmts]]).
|
| 816 |
|
|
@@ -880,11 +858,11 @@ namespace std {
|
|
| 880 |
```
|
| 881 |
|
| 882 |
The facet `num_get` is used to parse numeric values from an input
|
| 883 |
sequence such as an istream.
|
| 884 |
|
| 885 |
-
#####
|
| 886 |
|
| 887 |
``` cpp
|
| 888 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
| 889 |
ios_base::iostate& err, bool& val) const;
|
| 890 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
|
@@ -909,11 +887,11 @@ iter_type get(iter_type in, iter_type end, ios_base& str,
|
|
| 909 |
ios_base::iostate& err, void*& val) const;
|
| 910 |
```
|
| 911 |
|
| 912 |
*Returns:* `do_get(in, end, str, err, val)`.
|
| 913 |
|
| 914 |
-
#####
|
| 915 |
|
| 916 |
``` cpp
|
| 917 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 918 |
ios_base::iostate& err, long& val) const;
|
| 919 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
|
@@ -960,32 +938,32 @@ fmtflags basefield = (flags & ios_base::basefield);
|
|
| 960 |
fmtflags uppercase = (flags & ios_base::uppercase);
|
| 961 |
fmtflags boolalpha = (flags & ios_base::boolalpha);
|
| 962 |
```
|
| 963 |
|
| 964 |
For conversion to an integral type, the function determines the integral
|
| 965 |
-
conversion specifier as indicated in
|
| 966 |
-
|
| 967 |
-
|
| 968 |
|
| 969 |
-
**Table: Integer conversions** <a id="
|
| 970 |
|
| 971 |
| State | `stdio` equivalent |
|
| 972 |
| ------------------------ | ------------------ |
|
| 973 |
| `basefield == oct` | `%o` |
|
| 974 |
| `basefield == hex` | `%X` |
|
| 975 |
| `basefield == 0` | `%i` `signed` integral type | `%d` |
|
| 976 |
| `unsigned` integral type | `%u` |
|
| 977 |
|
| 978 |
|
| 979 |
-
For conversions to a floating type the specifier is `%g`.
|
| 980 |
|
| 981 |
For conversions to `void*` the specifier is `%p`.
|
| 982 |
|
| 983 |
A length modifier is added to the conversion specification, if needed,
|
| 984 |
-
as indicated in
|
| 985 |
|
| 986 |
-
**Table: Length modifier** <a id="
|
| 987 |
|
| 988 |
| Type | Length modifier |
|
| 989 |
| -------------------- | --------------- |
|
| 990 |
| `short` | `h` |
|
| 991 |
| `unsigned short` | `h` |
|
|
@@ -1153,11 +1131,11 @@ namespace std {
|
|
| 1153 |
```
|
| 1154 |
|
| 1155 |
The facet `num_put` is used to format numeric values to a character
|
| 1156 |
sequence such as an ostream.
|
| 1157 |
|
| 1158 |
-
#####
|
| 1159 |
|
| 1160 |
``` cpp
|
| 1161 |
iter_type put(iter_type out, ios_base& str, char_type fill, bool val) const;
|
| 1162 |
iter_type put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1163 |
iter_type put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
|
@@ -1168,11 +1146,11 @@ iter_type put(iter_type out, ios_base& str, char_type fill, long double val) con
|
|
| 1168 |
iter_type put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
| 1169 |
```
|
| 1170 |
|
| 1171 |
*Returns:* `do_put(out, str, fill, val)`.
|
| 1172 |
|
| 1173 |
-
#####
|
| 1174 |
|
| 1175 |
``` cpp
|
| 1176 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1177 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
| 1178 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
|
|
@@ -1181,30 +1159,30 @@ iter_type do_put(iter_type out, ios_base& str, char_type fill, double val) const
|
|
| 1181 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long double val) const;
|
| 1182 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
| 1183 |
```
|
| 1184 |
|
| 1185 |
*Effects:* Writes characters to the sequence `out`, formatting `val` as
|
| 1186 |
-
desired. In the following description, a local variable
|
| 1187 |
-
|
| 1188 |
|
| 1189 |
``` cpp
|
| 1190 |
locale loc = str.getloc();
|
| 1191 |
```
|
| 1192 |
|
| 1193 |
The details of this operation occur in several stages:
|
| 1194 |
|
| 1195 |
- Stage 1: Determine a printf conversion specifier `spec` and determine
|
| 1196 |
-
the characters that would be printed by `printf`
|
| 1197 |
this conversion specifier for
|
| 1198 |
``` cpp
|
| 1199 |
printf(spec, val)
|
| 1200 |
```
|
| 1201 |
|
| 1202 |
assuming that the current locale is the `"C"` locale.
|
| 1203 |
- Stage 2: Adjust the representation by converting each `char`
|
| 1204 |
determined by stage 1 to a `charT` using a conversion and values
|
| 1205 |
-
returned by members of `use_facet<numpunct<charT>>(
|
| 1206 |
- Stage 3: Determine where padding is required.
|
| 1207 |
- Stage 4: Insert the sequence into the `out`.
|
| 1208 |
|
| 1209 |
Detailed descriptions of each stage follow.
|
| 1210 |
|
|
@@ -1230,13 +1208,13 @@ All tables used in describing stage 1 are ordered. That is, the first
|
|
| 1230 |
line whose condition is true applies. A line without a condition is the
|
| 1231 |
default behavior when none of the earlier lines apply.
|
| 1232 |
|
| 1233 |
For conversion from an integral type other than a character type, the
|
| 1234 |
function determines the integral conversion specifier as indicated in
|
| 1235 |
-
|
| 1236 |
|
| 1237 |
-
**Table: Integer conversions** <a id="
|
| 1238 |
|
| 1239 |
| State | `stdio` equivalent |
|
| 1240 |
| -------------------------------------------- | ------------------ |
|
| 1241 |
| `basefield == ios_base::oct` | `%o` |
|
| 1242 |
| `(basefield == ios_base::hex) && !uppercase` | `%x` |
|
|
@@ -1245,13 +1223,13 @@ Table [[tab:localization.integer.conversions.out]].
|
|
| 1245 |
| for an `unsigned` integral type | `%u` |
|
| 1246 |
|
| 1247 |
|
| 1248 |
For conversion from a floating-point type, the function determines the
|
| 1249 |
floating-point conversion specifier as indicated in
|
| 1250 |
-
|
| 1251 |
|
| 1252 |
-
**Table: Floating-point conversions** <a id="
|
| 1253 |
|
| 1254 |
| State | `stdio` equivalent |
|
| 1255 |
| ---------------------------------------------------------------------- | ------------------ |
|
| 1256 |
| `floatfield == ios_base::fixed` | `%f` |
|
| 1257 |
| `floatfield == ios_base::scientific && !uppercase` | `%e` |
|
|
@@ -1262,13 +1240,13 @@ Table [[tab:localization.fp.conversions.out]].
|
|
| 1262 |
| otherwise | `%G` |
|
| 1263 |
|
| 1264 |
|
| 1265 |
For conversions from an integral or floating-point type a length
|
| 1266 |
modifier is added to the conversion specifier as indicated in
|
| 1267 |
-
|
| 1268 |
|
| 1269 |
-
**Table: Length modifier** <a id="
|
| 1270 |
|
| 1271 |
| Type | Length modifier |
|
| 1272 |
| -------------------- | --------------- |
|
| 1273 |
| `long` | `l` |
|
| 1274 |
| `long long` | `ll` |
|
|
@@ -1277,14 +1255,13 @@ Table [[tab:localization.length.modifier.out]].
|
|
| 1277 |
| `long double` | `L` |
|
| 1278 |
| otherwise | none |
|
| 1279 |
|
| 1280 |
|
| 1281 |
The conversion specifier has the following optional additional
|
| 1282 |
-
qualifiers prepended as indicated in
|
| 1283 |
-
Table [[tab:localization.numeric.conversions]].
|
| 1284 |
|
| 1285 |
-
**Table: Numeric conversions** <a id="
|
| 1286 |
|
| 1287 |
| Type(s) | State | `stdio` equivalent |
|
| 1288 |
| --------------------- | ----------- | ------------------ |
|
| 1289 |
| an integral type | `showpos` | `+` |
|
| 1290 |
| | `showbase` | `#` |
|
|
@@ -1304,16 +1281,20 @@ would be printed by a call of `printf(s, val)` where `s` is the
|
|
| 1304 |
conversion specifier determined above.
|
| 1305 |
|
| 1306 |
- **Stage 2:**
|
| 1307 |
|
| 1308 |
Any character `c` other than a decimal point(.) is converted to a
|
| 1309 |
-
`charT` via
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1310 |
|
| 1311 |
A local variable `punct` is initialized via
|
| 1312 |
|
| 1313 |
``` cpp
|
| 1314 |
-
const numpunct<charT>& punct = use_facet<numpunct<charT>>(
|
| 1315 |
```
|
| 1316 |
|
| 1317 |
For arithmetic types, `punct.thousands_sep()` characters are inserted
|
| 1318 |
into the sequence as determined by the value returned by
|
| 1319 |
`punct.do_grouping()` using the method described
|
|
@@ -1328,13 +1309,13 @@ A local variable is initialized as
|
|
| 1328 |
``` cpp
|
| 1329 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 1330 |
```
|
| 1331 |
|
| 1332 |
The location of any padding[^12] is determined according to
|
| 1333 |
-
|
| 1334 |
|
| 1335 |
-
**Table: Fill padding** <a id="
|
| 1336 |
|
| 1337 |
| State | Location |
|
| 1338 |
| ------------------------------------------------------------------------------ | ------------------ |
|
| 1339 |
| `adjustfield == ios_base::left` | pad after |
|
| 1340 |
| `adjustfield == ios_base::right` | pad before |
|
|
@@ -1408,43 +1389,73 @@ namespace std {
|
|
| 1408 |
}
|
| 1409 |
```
|
| 1410 |
|
| 1411 |
`numpunct<>`
|
| 1412 |
|
| 1413 |
-
specifies numeric punctuation. The specializations required in
|
| 1414 |
-
[[
|
| 1415 |
`numpunct<{}wchar_t>` and `numpunct<char>`, provide classic `"C"`
|
| 1416 |
numeric formats, i.e., they contain information equivalent to that
|
| 1417 |
contained in the `"C"` locale or their wide character counterparts as if
|
| 1418 |
obtained by a call to `widen`.
|
| 1419 |
|
| 1420 |
-
The syntax for number formats is as follows, where
|
| 1421 |
-
|
| 1422 |
-
|
| 1423 |
-
|
| 1424 |
-
|
| 1425 |
-
```
|
| 1426 |
-
|
| 1427 |
-
sign
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1431 |
```
|
| 1432 |
|
| 1433 |
and floating-point values have:
|
| 1434 |
|
| 1435 |
-
```
|
| 1436 |
-
floatval
|
| 1437 |
-
|
| 1438 |
-
|
| 1439 |
```
|
| 1440 |
|
| 1441 |
-
|
| 1442 |
-
|
| 1443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1444 |
|
| 1445 |
-
#####
|
| 1446 |
|
| 1447 |
``` cpp
|
| 1448 |
char_type decimal_point() const;
|
| 1449 |
```
|
| 1450 |
|
|
@@ -1467,11 +1478,11 @@ string_type truename() const;
|
|
| 1467 |
string_type falsename() const;
|
| 1468 |
```
|
| 1469 |
|
| 1470 |
*Returns:* `do_truename()` or `do_falsename()`, respectively.
|
| 1471 |
|
| 1472 |
-
#####
|
| 1473 |
|
| 1474 |
``` cpp
|
| 1475 |
char_type do_decimal_point() const;
|
| 1476 |
```
|
| 1477 |
|
|
@@ -1487,16 +1498,16 @@ required specializations return `’,’` or `L’,’`.
|
|
| 1487 |
|
| 1488 |
``` cpp
|
| 1489 |
string do_grouping() const;
|
| 1490 |
```
|
| 1491 |
|
| 1492 |
-
*Returns:* A
|
| 1493 |
-
|
| 1494 |
-
|
| 1495 |
-
|
| 1496 |
-
|
| 1497 |
-
|
| 1498 |
|
| 1499 |
The required specializations return the empty string, indicating no
|
| 1500 |
grouping.
|
| 1501 |
|
| 1502 |
``` cpp
|
|
@@ -1521,10 +1532,11 @@ namespace std {
|
|
| 1521 |
using char_type = charT;
|
| 1522 |
using string_type = basic_string<charT>;
|
| 1523 |
|
| 1524 |
explicit numpunct_byname(const char*, size_t refs = 0);
|
| 1525 |
explicit numpunct_byname(const string&, size_t refs = 0);
|
|
|
|
| 1526 |
protected:
|
| 1527 |
~numpunct_byname();
|
| 1528 |
};
|
| 1529 |
}
|
| 1530 |
```
|
|
@@ -1561,20 +1573,20 @@ namespace std {
|
|
| 1561 |
```
|
| 1562 |
|
| 1563 |
The class `collate<charT>` provides features for use in the collation
|
| 1564 |
(comparison) and hashing of strings. A locale member function template,
|
| 1565 |
`operator()`, uses the collate facet to allow a locale to act directly
|
| 1566 |
-
as the predicate argument for standard algorithms
|
| 1567 |
-
|
| 1568 |
-
|
| 1569 |
-
|
| 1570 |
-
|
| 1571 |
|
| 1572 |
Each function compares a string of characters `*p` in the range \[`low`,
|
| 1573 |
`high`).
|
| 1574 |
|
| 1575 |
-
#####
|
| 1576 |
|
| 1577 |
``` cpp
|
| 1578 |
int compare(const charT* low1, const charT* high1,
|
| 1579 |
const charT* low2, const charT* high2) const;
|
| 1580 |
```
|
|
@@ -1591,22 +1603,22 @@ string_type transform(const charT* low, const charT* high) const;
|
|
| 1591 |
long hash(const charT* low, const charT* high) const;
|
| 1592 |
```
|
| 1593 |
|
| 1594 |
*Returns:* `do_hash(low, high)`.
|
| 1595 |
|
| 1596 |
-
#####
|
| 1597 |
|
| 1598 |
``` cpp
|
| 1599 |
int do_compare(const charT* low1, const charT* high1,
|
| 1600 |
const charT* low2, const charT* high2) const;
|
| 1601 |
```
|
| 1602 |
|
| 1603 |
*Returns:* `1` if the first string is greater than the second, `-1` if
|
| 1604 |
less, zero otherwise. The specializations required in
|
| 1605 |
-
|
| 1606 |
-
|
| 1607 |
-
|
| 1608 |
|
| 1609 |
``` cpp
|
| 1610 |
string_type do_transform(const charT* low, const charT* high) const;
|
| 1611 |
```
|
| 1612 |
|
|
@@ -1636,10 +1648,11 @@ namespace std {
|
|
| 1636 |
public:
|
| 1637 |
using string_type = basic_string<charT>;
|
| 1638 |
|
| 1639 |
explicit collate_byname(const char*, size_t refs = 0);
|
| 1640 |
explicit collate_byname(const string&, size_t refs = 0);
|
|
|
|
| 1641 |
protected:
|
| 1642 |
~collate_byname();
|
| 1643 |
};
|
| 1644 |
}
|
| 1645 |
```
|
|
@@ -1648,14 +1661,13 @@ namespace std {
|
|
| 1648 |
|
| 1649 |
Templates `time_get<charT, InputIterator>` and
|
| 1650 |
`time_put<charT, OutputIterator>` provide date and time formatting and
|
| 1651 |
parsing. All specifications of member functions for `time_put` and
|
| 1652 |
`time_get` in the subclauses of [[category.time]] only apply to the
|
| 1653 |
-
specializations required in Tables [[tab:
|
| 1654 |
-
|
| 1655 |
-
|
| 1656 |
-
`ios_base::iostate&`, and `fill` arguments as described in
|
| 1657 |
[[locale.categories]], and the `ctype<>` facet, to determine formatting
|
| 1658 |
details.
|
| 1659 |
|
| 1660 |
#### Class template `time_get` <a id="locale.time.get">[[locale.time.get]]</a>
|
| 1661 |
|
|
@@ -1723,11 +1735,11 @@ produce the sequence; otherwise either an error is reported or
|
|
| 1723 |
unspecified values are assigned.[^15]
|
| 1724 |
|
| 1725 |
If the end iterator is reached during parsing by any of the `get()`
|
| 1726 |
member functions, the member sets `ios_base::eofbit` in `err`.
|
| 1727 |
|
| 1728 |
-
#####
|
| 1729 |
|
| 1730 |
``` cpp
|
| 1731 |
dateorder date_order() const;
|
| 1732 |
```
|
| 1733 |
|
|
@@ -1774,11 +1786,11 @@ iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
|
| 1774 |
``` cpp
|
| 1775 |
iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
| 1776 |
tm* t, const char_type* fmt, const char_type* fmtend) const;
|
| 1777 |
```
|
| 1778 |
|
| 1779 |
-
*
|
| 1780 |
|
| 1781 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 1782 |
It then enters a loop, reading zero or more characters from `s` at each
|
| 1783 |
iteration. Unless otherwise specified below, the loop terminates when
|
| 1784 |
the first of the following conditions holds:
|
|
@@ -1816,11 +1828,11 @@ by what means the function performs case-insensitive comparison or
|
|
| 1816 |
whether multi-character sequences are considered while doing
|
| 1817 |
so. — *end note*]
|
| 1818 |
|
| 1819 |
*Returns:* `s`.
|
| 1820 |
|
| 1821 |
-
#####
|
| 1822 |
|
| 1823 |
``` cpp
|
| 1824 |
dateorder do_date_order() const;
|
| 1825 |
```
|
| 1826 |
|
|
@@ -1850,14 +1862,13 @@ iter_type do_get_date(iter_type s, iter_type end, ios_base& str,
|
|
| 1850 |
|
| 1851 |
*Effects:* Reads characters starting at `s` until it has extracted those
|
| 1852 |
`struct tm` members and remaining format characters used by
|
| 1853 |
`time_put<>::put` to produce one of the following formats, or until it
|
| 1854 |
encounters an error. The format depends on the value returned by
|
| 1855 |
-
`date_order()` as shown in
|
| 1856 |
-
Table [[tab:lib.locale.time.get.virtuals.dogetdate]].
|
| 1857 |
|
| 1858 |
-
**Table: `do_get_date` effects** <a id="
|
| 1859 |
|
| 1860 |
| `date_order()` | Format |
|
| 1861 |
| -------------- | ---------- |
|
| 1862 |
| `no_order` | `"%m%d%y"` |
|
| 1863 |
| `dmy` | `"%d%m%y"` |
|
|
@@ -1904,11 +1915,11 @@ recognized as part of a valid year identifier.
|
|
| 1904 |
``` cpp
|
| 1905 |
iter_type do_get(iter_type s, iter_type end, ios_base& f,
|
| 1906 |
ios_base::iostate& err, tm* t, char format, char modifier) const;
|
| 1907 |
```
|
| 1908 |
|
| 1909 |
-
*
|
| 1910 |
|
| 1911 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 1912 |
It then reads characters starting at `s` until it encounters an error,
|
| 1913 |
or until it has extracted and assigned those `struct tm` members, and
|
| 1914 |
any remaining format characters, corresponding to a conversion directive
|
|
@@ -1928,11 +1939,11 @@ members from the input sequence \[`s`, `end`), it evaluates
|
|
| 1928 |
members are unspecified and may be outside their valid range.
|
| 1929 |
|
| 1930 |
*Remarks:* It is unspecified whether multiple calls to `do_get()` with
|
| 1931 |
the address of the same `struct tm` object will update the current
|
| 1932 |
contents of the object or simply overwrite its members. Portable
|
| 1933 |
-
programs
|
| 1934 |
|
| 1935 |
*Returns:* An iterator pointing immediately beyond the last character
|
| 1936 |
recognized as possibly part of a valid input sequence for the given
|
| 1937 |
`format` and `modifier`.
|
| 1938 |
|
|
@@ -1946,10 +1957,11 @@ namespace std {
|
|
| 1946 |
using dateorder = time_base::dateorder;
|
| 1947 |
using iter_type = InputIterator;
|
| 1948 |
|
| 1949 |
explicit time_get_byname(const char*, size_t refs = 0);
|
| 1950 |
explicit time_get_byname(const string&, size_t refs = 0);
|
|
|
|
| 1951 |
protected:
|
| 1952 |
~time_get_byname();
|
| 1953 |
};
|
| 1954 |
}
|
| 1955 |
```
|
|
@@ -1980,11 +1992,11 @@ namespace std {
|
|
| 1980 |
char format, char modifier) const;
|
| 1981 |
};
|
| 1982 |
}
|
| 1983 |
```
|
| 1984 |
|
| 1985 |
-
#####
|
| 1986 |
|
| 1987 |
``` cpp
|
| 1988 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
| 1989 |
const charT* pattern, const charT* pat_end) const;
|
| 1990 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
|
@@ -2013,11 +2025,11 @@ implementation-defined formats or by derivations. A space character is a
|
|
| 2013 |
reasonable default for this argument. — *end note*]
|
| 2014 |
|
| 2015 |
*Returns:* An iterator pointing immediately after the last character
|
| 2016 |
produced.
|
| 2017 |
|
| 2018 |
-
#####
|
| 2019 |
|
| 2020 |
``` cpp
|
| 2021 |
iter_type do_put(iter_type s, ios_base&, char_type fill, const tm* t,
|
| 2022 |
char format, char modifier) const;
|
| 2023 |
```
|
|
@@ -2040,18 +2052,18 @@ reasonable default for this argument. — *end note*]
|
|
| 2040 |
#### Class template `time_put_byname` <a id="locale.time.put.byname">[[locale.time.put.byname]]</a>
|
| 2041 |
|
| 2042 |
``` cpp
|
| 2043 |
namespace std {
|
| 2044 |
template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2045 |
-
|
| 2046 |
-
{
|
| 2047 |
public:
|
| 2048 |
using char_type = charT;
|
| 2049 |
using iter_type = OutputIterator;
|
| 2050 |
|
| 2051 |
explicit time_put_byname(const char*, size_t refs = 0);
|
| 2052 |
explicit time_put_byname(const string&, size_t refs = 0);
|
|
|
|
| 2053 |
protected:
|
| 2054 |
~time_put_byname();
|
| 2055 |
};
|
| 2056 |
}
|
| 2057 |
```
|
|
@@ -2061,14 +2073,13 @@ namespace std {
|
|
| 2061 |
These templates handle monetary formats. A template parameter indicates
|
| 2062 |
whether local or international monetary formats are to be used.
|
| 2063 |
|
| 2064 |
All specifications of member functions for `money_put` and `money_get`
|
| 2065 |
in the subclauses of [[category.monetary]] only apply to the
|
| 2066 |
-
specializations required in Tables [[tab:
|
| 2067 |
-
|
| 2068 |
-
|
| 2069 |
-
`ios_base::iostate&`, and `fill` arguments as described in
|
| 2070 |
[[locale.categories]], and the `moneypunct<>` and `ctype<>` facets, to
|
| 2071 |
determine formatting details.
|
| 2072 |
|
| 2073 |
#### Class template `money_get` <a id="locale.money.get">[[locale.money.get]]</a>
|
| 2074 |
|
|
@@ -2100,31 +2111,28 @@ namespace std {
|
|
| 2100 |
ios_base::iostate& err, string_type& digits) const;
|
| 2101 |
};
|
| 2102 |
}
|
| 2103 |
```
|
| 2104 |
|
| 2105 |
-
#####
|
| 2106 |
|
| 2107 |
``` cpp
|
| 2108 |
-
iter_type get(iter_type s, iter_type end, bool intl,
|
| 2109 |
-
ios_base
|
| 2110 |
-
|
| 2111 |
-
iter_type get(s, iter_type end, bool intl, ios_base&f,
|
| 2112 |
ios_base::iostate& err, string_type& quant) const;
|
| 2113 |
```
|
| 2114 |
|
| 2115 |
*Returns:* `do_get(s, end, intl, f, err, quant)`.
|
| 2116 |
|
| 2117 |
-
#####
|
| 2118 |
|
| 2119 |
``` cpp
|
| 2120 |
-
iter_type do_get(iter_type s, iter_type end, bool intl,
|
| 2121 |
-
ios_base
|
| 2122 |
-
|
| 2123 |
-
|
| 2124 |
-
ios_base& str, ios_base::iostate& err,
|
| 2125 |
-
string_type& digits) const;
|
| 2126 |
```
|
| 2127 |
|
| 2128 |
*Effects:* Reads characters from `s` to parse and construct a monetary
|
| 2129 |
value according to the format specified by a `moneypunct<charT, Intl>`
|
| 2130 |
facet reference `mp` and the character mapping specified by a
|
|
@@ -2134,11 +2142,11 @@ does not change `err`; otherwise, sets `err` to `(err|str.failbit)`, or
|
|
| 2134 |
`(err|str.failbit|str.eofbit)` if no more characters are available, and
|
| 2135 |
does not change `units` or `digits`. Uses the pattern returned by
|
| 2136 |
`mp.neg_format()` to parse all values. The result is returned as an
|
| 2137 |
integral value stored in `units` or as a sequence of digits possibly
|
| 2138 |
preceded by a minus sign (as produced by `ct.widen(c)` where `c` is
|
| 2139 |
-
`’-’` or in the range from `’0’` through `’9’`
|
| 2140 |
`digits`.
|
| 2141 |
|
| 2142 |
[*Example 1*: The sequence `$1,056.23` in a common United States locale
|
| 2143 |
would yield, for `units`, `105623`, or, for `digits`,
|
| 2144 |
`"105623"`. — *end example*]
|
|
@@ -2153,13 +2161,13 @@ Where `money_base::space` or `money_base::none` appears as the last
|
|
| 2153 |
element in the format pattern, no white space is consumed. Otherwise,
|
| 2154 |
where `money_base::space` appears in any of the initial elements of the
|
| 2155 |
format pattern, at least one white space character is required. Where
|
| 2156 |
`money_base::none` appears in any of the initial elements of the format
|
| 2157 |
pattern, white space is allowed but not required. If
|
| 2158 |
-
`(str.flags() & str.showbase)` is false, the currency symbol is
|
| 2159 |
-
and is consumed only if other characters are needed to complete
|
| 2160 |
-
format; otherwise, the currency symbol is required.
|
| 2161 |
|
| 2162 |
If the first character (if any) in the string `pos` returned by
|
| 2163 |
`mp.positive_sign()` or the string `neg` returned by
|
| 2164 |
`mp.negative_sign()` is recognized in the position indicated by `sign`
|
| 2165 |
in the format pattern, it is consumed and any remaining characters in
|
|
@@ -2231,22 +2239,20 @@ namespace std {
|
|
| 2231 |
const string_type& digits) const;
|
| 2232 |
};
|
| 2233 |
}
|
| 2234 |
```
|
| 2235 |
|
| 2236 |
-
#####
|
| 2237 |
|
| 2238 |
``` cpp
|
| 2239 |
-
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
| 2240 |
-
|
| 2241 |
-
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
| 2242 |
-
const string_type& quant) const;
|
| 2243 |
```
|
| 2244 |
|
| 2245 |
*Returns:* `do_put(s, intl, f, loc, quant)`.
|
| 2246 |
|
| 2247 |
-
#####
|
| 2248 |
|
| 2249 |
``` cpp
|
| 2250 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
| 2251 |
char_type fill, long double units) const;
|
| 2252 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
@@ -2340,11 +2346,11 @@ namespace std {
|
|
| 2340 |
```
|
| 2341 |
|
| 2342 |
The `moneypunct<>` facet defines monetary formatting parameters used by
|
| 2343 |
`money_get<>` and `money_put<>`. A monetary format is a sequence of four
|
| 2344 |
components, specified by a `pattern` value `p`, such that the `part`
|
| 2345 |
-
value `static_cast<part>(p.field[i])` determines the `i`
|
| 2346 |
the format[^21] In the `field` member of a `pattern` object, each value
|
| 2347 |
`symbol`, `sign`, `value`, and either `space` or `none` appears exactly
|
| 2348 |
once. The value `none`, if present, is not first; the value `space`, if
|
| 2349 |
present, is neither first nor last.
|
| 2350 |
|
|
@@ -2360,44 +2366,57 @@ required. Any remaining characters of the sign sequence are required
|
|
| 2360 |
after all other format components. Where `value` appears, the absolute
|
| 2361 |
numeric monetary value is required.
|
| 2362 |
|
| 2363 |
The format of the numeric monetary value is a decimal number:
|
| 2364 |
|
| 2365 |
-
```
|
| 2366 |
-
value
|
|
|
|
| 2367 |
decimal-point digits
|
| 2368 |
```
|
| 2369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2370 |
if `frac_digits()` returns a positive value, or
|
| 2371 |
|
| 2372 |
-
```
|
| 2373 |
-
value
|
|
|
|
| 2374 |
```
|
| 2375 |
|
| 2376 |
-
otherwise. The symbol
|
| 2377 |
-
|
| 2378 |
|
| 2379 |
-
```
|
| 2380 |
-
units
|
| 2381 |
-
digits
|
|
|
|
| 2382 |
```
|
| 2383 |
|
| 2384 |
-
|
| 2385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2386 |
`ct` is a reference of type `const ctype<charT>&` obtained as described
|
| 2387 |
-
in the definitions of `money_get<>` and `money_put<>`. The symbol
|
| 2388 |
-
|
| 2389 |
-
|
| 2390 |
-
|
| 2391 |
-
|
| 2392 |
-
|
| 2393 |
|
| 2394 |
The placement of thousands-separator characters (if any) is determined
|
| 2395 |
by the value returned by `grouping()`, defined identically as the member
|
| 2396 |
`numpunct<>::do_grouping()`.
|
| 2397 |
|
| 2398 |
-
#####
|
| 2399 |
|
| 2400 |
``` cpp
|
| 2401 |
charT decimal_point() const;
|
| 2402 |
charT thousands_sep() const;
|
| 2403 |
string grouping() const;
|
|
@@ -2410,11 +2429,11 @@ pattern neg_format() const;
|
|
| 2410 |
```
|
| 2411 |
|
| 2412 |
Each of these functions `F` returns the result of calling the
|
| 2413 |
corresponding virtual member function `do_F()`.
|
| 2414 |
|
| 2415 |
-
#####
|
| 2416 |
|
| 2417 |
``` cpp
|
| 2418 |
charT do_decimal_point() const;
|
| 2419 |
```
|
| 2420 |
|
|
@@ -2437,39 +2456,47 @@ to, the result of `numpunct<charT>::do_grouping()`.[^24]
|
|
| 2437 |
|
| 2438 |
``` cpp
|
| 2439 |
string_type do_curr_symbol() const;
|
| 2440 |
```
|
| 2441 |
|
| 2442 |
-
*Returns:* A string to use as the currency identifier symbol.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2443 |
|
| 2444 |
``` cpp
|
| 2445 |
string_type do_positive_sign() const;
|
| 2446 |
string_type do_negative_sign() const;
|
| 2447 |
```
|
| 2448 |
|
| 2449 |
*Returns:* `do_positive_sign()` returns the string to use to indicate a
|
| 2450 |
-
positive monetary value;[^
|
| 2451 |
use to indicate a negative value.
|
| 2452 |
|
| 2453 |
``` cpp
|
| 2454 |
int do_frac_digits() const;
|
| 2455 |
```
|
| 2456 |
|
| 2457 |
*Returns:* The number of digits after the decimal radix separator, if
|
| 2458 |
-
any.[^
|
| 2459 |
|
| 2460 |
``` cpp
|
| 2461 |
pattern do_pos_format() const;
|
| 2462 |
pattern do_neg_format() const;
|
| 2463 |
```
|
| 2464 |
|
| 2465 |
*Returns:* The specializations required in
|
| 2466 |
-
|
| 2467 |
-
|
| 2468 |
-
`moneypunct<char
|
| 2469 |
-
|
| 2470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2471 |
|
| 2472 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 2473 |
|
| 2474 |
``` cpp
|
| 2475 |
namespace std {
|
|
@@ -2479,10 +2506,11 @@ namespace std {
|
|
| 2479 |
using pattern = money_base::pattern;
|
| 2480 |
using string_type = basic_string<charT>;
|
| 2481 |
|
| 2482 |
explicit moneypunct_byname(const char*, size_t refs = 0);
|
| 2483 |
explicit moneypunct_byname(const string&, size_t refs = 0);
|
|
|
|
| 2484 |
protected:
|
| 2485 |
~moneypunct_byname();
|
| 2486 |
};
|
| 2487 |
}
|
| 2488 |
```
|
|
@@ -2507,34 +2535,34 @@ namespace std {
|
|
| 2507 |
using char_type = charT;
|
| 2508 |
using string_type = basic_string<charT>;
|
| 2509 |
|
| 2510 |
explicit messages(size_t refs = 0);
|
| 2511 |
|
| 2512 |
-
catalog open(const
|
| 2513 |
string_type get(catalog c, int set, int msgid,
|
| 2514 |
const string_type& dfault) const;
|
| 2515 |
void close(catalog c) const;
|
| 2516 |
|
| 2517 |
static locale::id id;
|
| 2518 |
|
| 2519 |
protected:
|
| 2520 |
~messages();
|
| 2521 |
-
virtual catalog do_open(const
|
| 2522 |
virtual string_type do_get(catalog, int set, int msgid,
|
| 2523 |
const string_type& dfault) const;
|
| 2524 |
virtual void do_close(catalog) const;
|
| 2525 |
};
|
| 2526 |
}
|
| 2527 |
```
|
| 2528 |
|
| 2529 |
Values of type `messages_base::catalog` usable as arguments to members
|
| 2530 |
`get` and `close` can be obtained only by calling member `open`.
|
| 2531 |
|
| 2532 |
-
#####
|
| 2533 |
|
| 2534 |
``` cpp
|
| 2535 |
-
catalog open(const
|
| 2536 |
```
|
| 2537 |
|
| 2538 |
*Returns:* `do_open(name, loc)`.
|
| 2539 |
|
| 2540 |
``` cpp
|
|
@@ -2547,14 +2575,14 @@ string_type get(catalog cat, int set, int msgid, const string_type& dfault) cons
|
|
| 2547 |
void close(catalog cat) const;
|
| 2548 |
```
|
| 2549 |
|
| 2550 |
*Effects:* Calls `do_close(cat)`.
|
| 2551 |
|
| 2552 |
-
#####
|
| 2553 |
|
| 2554 |
``` cpp
|
| 2555 |
-
catalog do_open(const
|
| 2556 |
```
|
| 2557 |
|
| 2558 |
*Returns:* A value that may be passed to `get()` to retrieve a message
|
| 2559 |
from the message catalog identified by the string `name` according to an
|
| 2560 |
*implementation-defined* mapping. The result can be used until it is
|
|
@@ -2567,22 +2595,22 @@ conversion when retrieving messages, if needed.
|
|
| 2567 |
|
| 2568 |
``` cpp
|
| 2569 |
string_type do_get(catalog cat, int set, int msgid, const string_type& dfault) const;
|
| 2570 |
```
|
| 2571 |
|
| 2572 |
-
*
|
| 2573 |
closed.
|
| 2574 |
|
| 2575 |
*Returns:* A message identified by arguments `set`, `msgid`, and
|
| 2576 |
`dfault`, according to an *implementation-defined* mapping. If no such
|
| 2577 |
message can be found, returns `dfault`.
|
| 2578 |
|
| 2579 |
``` cpp
|
| 2580 |
void do_close(catalog cat) const;
|
| 2581 |
```
|
| 2582 |
|
| 2583 |
-
*
|
| 2584 |
closed.
|
| 2585 |
|
| 2586 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 2587 |
|
| 2588 |
*Remarks:* The limit on such resources, if any, is
|
|
@@ -2598,203 +2626,12 @@ namespace std {
|
|
| 2598 |
using catalog = messages_base::catalog;
|
| 2599 |
using string_type = basic_string<charT>;
|
| 2600 |
|
| 2601 |
explicit messages_byname(const char*, size_t refs = 0);
|
| 2602 |
explicit messages_byname(const string&, size_t refs = 0);
|
|
|
|
| 2603 |
protected:
|
| 2604 |
~messages_byname();
|
| 2605 |
};
|
| 2606 |
}
|
| 2607 |
```
|
| 2608 |
|
| 2609 |
-
### Program-defined facets <a id="facets.examples">[[facets.examples]]</a>
|
| 2610 |
-
|
| 2611 |
-
A C++program may define facets to be added to a locale and used
|
| 2612 |
-
identically as the built-in facets. To create a new facet interface,
|
| 2613 |
-
C++programs simply derive from `locale::facet` a class containing a
|
| 2614 |
-
static member: `static locale::id id`.
|
| 2615 |
-
|
| 2616 |
-
[*Note 1*: The locale member function templates verify its type and
|
| 2617 |
-
storage class. — *end note*]
|
| 2618 |
-
|
| 2619 |
-
[*Example 1*:
|
| 2620 |
-
|
| 2621 |
-
Traditional global localization is still easy:
|
| 2622 |
-
|
| 2623 |
-
``` cpp
|
| 2624 |
-
#include <iostream>
|
| 2625 |
-
#include <locale>
|
| 2626 |
-
int main(int argc, char** argv) {
|
| 2627 |
-
using namespace std;
|
| 2628 |
-
locale::global(locale("")); // set the global locale
|
| 2629 |
-
// imbue it on all the std streams
|
| 2630 |
-
cin.imbue(locale());
|
| 2631 |
-
cout.imbue(locale());
|
| 2632 |
-
cerr.imbue(locale());
|
| 2633 |
-
wcin.imbue(locale());
|
| 2634 |
-
wcout.imbue(locale());
|
| 2635 |
-
wcerr.imbue(locale());
|
| 2636 |
-
|
| 2637 |
-
return MyObject(argc, argv).doit();
|
| 2638 |
-
}
|
| 2639 |
-
```
|
| 2640 |
-
|
| 2641 |
-
— *end example*]
|
| 2642 |
-
|
| 2643 |
-
[*Example 2*:
|
| 2644 |
-
|
| 2645 |
-
Greater flexibility is possible:
|
| 2646 |
-
|
| 2647 |
-
``` cpp
|
| 2648 |
-
#include <iostream>
|
| 2649 |
-
#include <locale>
|
| 2650 |
-
int main() {
|
| 2651 |
-
using namespace std;
|
| 2652 |
-
cin.imbue(locale("")); // the user's preferred locale
|
| 2653 |
-
cout.imbue(locale::classic());
|
| 2654 |
-
double f;
|
| 2655 |
-
while (cin >> f) cout << f << endl;
|
| 2656 |
-
return (cin.fail() != 0);
|
| 2657 |
-
}
|
| 2658 |
-
```
|
| 2659 |
-
|
| 2660 |
-
In a European locale, with input `3.456,78`, output is `3456.78`.
|
| 2661 |
-
|
| 2662 |
-
— *end example*]
|
| 2663 |
-
|
| 2664 |
-
This can be important even for simple programs, which may need to write
|
| 2665 |
-
a data file in a fixed format, regardless of a user’s preference.
|
| 2666 |
-
|
| 2667 |
-
[*Example 3*:
|
| 2668 |
-
|
| 2669 |
-
Here is an example of the use of locales in a library interface.
|
| 2670 |
-
|
| 2671 |
-
``` cpp
|
| 2672 |
-
// file: Date.h
|
| 2673 |
-
#include <iosfwd>
|
| 2674 |
-
#include <string>
|
| 2675 |
-
#include <locale>
|
| 2676 |
-
|
| 2677 |
-
class Date {
|
| 2678 |
-
public:
|
| 2679 |
-
Date(unsigned day, unsigned month, unsigned year);
|
| 2680 |
-
std::string asString(const std::locale& = std::locale());
|
| 2681 |
-
};
|
| 2682 |
-
|
| 2683 |
-
std::istream& operator>>(std::istream& s, Date& d);
|
| 2684 |
-
std::ostream& operator<<(std::ostream& s, Date d);
|
| 2685 |
-
```
|
| 2686 |
-
|
| 2687 |
-
This example illustrates two architectural uses of class `locale`.
|
| 2688 |
-
|
| 2689 |
-
The first is as a default argument in `Date::asString()`, where the
|
| 2690 |
-
default is the global (presumably user-preferred) locale.
|
| 2691 |
-
|
| 2692 |
-
The second is in the operators `<<` and `>>`, where a locale
|
| 2693 |
-
“hitchhikes” on another object, in this case a stream, to the point
|
| 2694 |
-
where it is needed.
|
| 2695 |
-
|
| 2696 |
-
``` cpp
|
| 2697 |
-
// file: Date.C
|
| 2698 |
-
#include "Date" // includes <ctime>
|
| 2699 |
-
#include <sstream>
|
| 2700 |
-
std::string Date::asString(const std::locale& l) {
|
| 2701 |
-
using namespace std;
|
| 2702 |
-
ostringstream s; s.imbue(l);
|
| 2703 |
-
s << *this; return s.str();
|
| 2704 |
-
}
|
| 2705 |
-
|
| 2706 |
-
std::istream& operator>>(std::istream& s, Date& d) {
|
| 2707 |
-
using namespace std;
|
| 2708 |
-
istream::sentry cerberos(s);
|
| 2709 |
-
if (cerberos) {
|
| 2710 |
-
ios_base::iostate err = goodbit;
|
| 2711 |
-
struct tm t;
|
| 2712 |
-
use_facet<time_get<char>>(s.getloc()).get_date(s, 0, s, err, &t);
|
| 2713 |
-
if (!err) d = Date(t.tm_day, t.tm_mon + 1, t.tm_year + 1900);
|
| 2714 |
-
s.setstate(err);
|
| 2715 |
-
}
|
| 2716 |
-
return s;
|
| 2717 |
-
}
|
| 2718 |
-
```
|
| 2719 |
-
|
| 2720 |
-
— *end example*]
|
| 2721 |
-
|
| 2722 |
-
A locale object may be extended with a new facet simply by constructing
|
| 2723 |
-
it with an instance of a class derived from `locale::facet`. The only
|
| 2724 |
-
member a C++program must define is the static member `id`, which
|
| 2725 |
-
identifies your class interface as a new facet.
|
| 2726 |
-
|
| 2727 |
-
[*Example 4*:
|
| 2728 |
-
|
| 2729 |
-
Classifying Japanese characters:
|
| 2730 |
-
|
| 2731 |
-
``` cpp
|
| 2732 |
-
// file: <jctype>
|
| 2733 |
-
#include <locale>
|
| 2734 |
-
namespace My {
|
| 2735 |
-
using namespace std;
|
| 2736 |
-
class JCtype : public locale::facet {
|
| 2737 |
-
public:
|
| 2738 |
-
static locale::id id; // required for use as a new locale facet
|
| 2739 |
-
bool is_kanji (wchar_t c) const;
|
| 2740 |
-
JCtype() { }
|
| 2741 |
-
protected:
|
| 2742 |
-
~JCtype() { }
|
| 2743 |
-
};
|
| 2744 |
-
}
|
| 2745 |
-
|
| 2746 |
-
// file: filt.C
|
| 2747 |
-
#include <iostream>
|
| 2748 |
-
#include <locale>
|
| 2749 |
-
#include "jctype" // above
|
| 2750 |
-
std::locale::id My::JCtype::id; // the static JCtype member declared above.
|
| 2751 |
-
|
| 2752 |
-
int main() {
|
| 2753 |
-
using namespace std;
|
| 2754 |
-
using wctype = ctype<wchar_t>;
|
| 2755 |
-
locale loc(locale(""), // the user's preferred locale ...
|
| 2756 |
-
new My::JCtype); // and a new feature ...
|
| 2757 |
-
wchar_t c = use_facet<wctype>(loc).widen('!');
|
| 2758 |
-
if (!use_facet<My::JCtype>(loc).is_kanji(c))
|
| 2759 |
-
cout << "no it isn't!" << endl;
|
| 2760 |
-
}
|
| 2761 |
-
```
|
| 2762 |
-
|
| 2763 |
-
The new facet is used exactly like the built-in facets.
|
| 2764 |
-
|
| 2765 |
-
— *end example*]
|
| 2766 |
-
|
| 2767 |
-
[*Example 5*:
|
| 2768 |
-
|
| 2769 |
-
Replacing an existing facet is even easier. The code does not define a
|
| 2770 |
-
member `id` because it is reusing the `numpunct<charT>` facet interface:
|
| 2771 |
-
|
| 2772 |
-
``` cpp
|
| 2773 |
-
// file: my_bool.C
|
| 2774 |
-
#include <iostream>
|
| 2775 |
-
#include <locale>
|
| 2776 |
-
#include <string>
|
| 2777 |
-
namespace My {
|
| 2778 |
-
using namespace std;
|
| 2779 |
-
using cnumpunct = numpunct_byname<char>;
|
| 2780 |
-
class BoolNames : public cnumpunct {
|
| 2781 |
-
protected:
|
| 2782 |
-
string do_truename() const { return "Oui Oui!"; }
|
| 2783 |
-
string do_falsename() const { return "Mais Non!"; }
|
| 2784 |
-
~BoolNames() { }
|
| 2785 |
-
public:
|
| 2786 |
-
BoolNames(const char* name) : cnumpunct(name) { }
|
| 2787 |
-
};
|
| 2788 |
-
}
|
| 2789 |
-
|
| 2790 |
-
int main(int argc, char** argv) {
|
| 2791 |
-
using namespace std;
|
| 2792 |
-
// make the user's preferred locale, except for...
|
| 2793 |
-
locale loc(locale(""), new My::BoolNames(""));
|
| 2794 |
-
cout.imbue(loc);
|
| 2795 |
-
cout << boolalpha << "Any arguments today? " << (argc > 1) << endl;
|
| 2796 |
-
}
|
| 2797 |
-
```
|
| 2798 |
-
|
| 2799 |
-
— *end example*]
|
| 2800 |
-
|
|
|
|
| 3 |
Each of the standard categories includes a family of facets. Some of
|
| 4 |
these implement formatting or parsing of a datum, for use by standard or
|
| 5 |
users’ iostream operators `<<` and `>>`, as members `put()` and `get()`,
|
| 6 |
respectively. Each such member function takes an `ios_base&` argument
|
| 7 |
whose members `flags()`, `precision()`, and `width()`, specify the
|
| 8 |
+
format of the corresponding datum [[ios.base]]. Those functions which
|
| 9 |
need to use other facets call its member `getloc()` to retrieve the
|
| 10 |
locale imbued there. Formatting facets use the character argument `fill`
|
| 11 |
to fill out the specified width where necessary.
|
| 12 |
|
| 13 |
The `put()` members make no provision for error reporting. (Any failures
|
| 14 |
+
of the OutputIterator argument can be extracted from the returned
|
| 15 |
iterator.) The `get()` members take an `ios_base::iostate&` argument
|
| 16 |
whose value they ignore, but set to `ios_base::failbit` in case of a
|
| 17 |
parse error.
|
| 18 |
|
| 19 |
Within this clause it is unspecified whether one virtual function calls
|
|
|
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
namespace std {
|
| 26 |
class ctype_base {
|
| 27 |
public:
|
| 28 |
+
using mask = see below;
|
| 29 |
|
| 30 |
// numeric values are for exposition only.
|
| 31 |
static const mask space = 1 << 0;
|
| 32 |
static const mask print = 1 << 1;
|
| 33 |
static const mask cntrl = 1 << 2;
|
|
|
|
| 42 |
static const mask graph = alnum | punct;
|
| 43 |
};
|
| 44 |
}
|
| 45 |
```
|
| 46 |
|
| 47 |
+
The type `mask` is a bitmask type [[bitmask.types]].
|
| 48 |
|
| 49 |
#### Class template `ctype` <a id="locale.ctype">[[locale.ctype]]</a>
|
| 50 |
|
| 51 |
``` cpp
|
| 52 |
namespace std {
|
|
|
|
| 94 |
|
| 95 |
Class `ctype` encapsulates the C library `<cctype>` features. `istream`
|
| 96 |
members are required to use `ctype<>` for character classing during
|
| 97 |
input parsing.
|
| 98 |
|
| 99 |
+
The specializations required in [[locale.category.facets]]
|
| 100 |
+
[[locale.category]], namely `ctype<char>` and `ctype<wchar_t>`,
|
| 101 |
+
implement character classing appropriate to the implementation’s native
|
| 102 |
+
character set.
|
| 103 |
|
| 104 |
##### `ctype` members <a id="locale.ctype.members">[[locale.ctype.members]]</a>
|
| 105 |
|
| 106 |
``` cpp
|
| 107 |
bool is(mask m, charT c) const;
|
| 108 |
+
const charT* is(const charT* low, const charT* high, mask* vec) const;
|
|
|
|
| 109 |
```
|
| 110 |
|
| 111 |
*Returns:* `do_is(m, c)` or `do_is(low, high, vec)`.
|
| 112 |
|
| 113 |
``` cpp
|
| 114 |
+
const charT* scan_is(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 115 |
```
|
| 116 |
|
| 117 |
*Returns:* `do_scan_is(m, low, high)`.
|
| 118 |
|
| 119 |
``` cpp
|
| 120 |
+
const charT* scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 121 |
```
|
| 122 |
|
| 123 |
*Returns:* `do_scan_not(m, low, high)`.
|
| 124 |
|
| 125 |
``` cpp
|
|
|
|
| 143 |
|
| 144 |
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`.
|
| 145 |
|
| 146 |
``` cpp
|
| 147 |
char narrow(charT c, char dfault) const;
|
| 148 |
+
const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
|
|
|
|
| 149 |
```
|
| 150 |
|
| 151 |
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`.
|
| 152 |
|
| 153 |
##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
|
| 154 |
|
| 155 |
``` cpp
|
| 156 |
bool do_is(mask m, charT c) const;
|
| 157 |
+
const charT* do_is(const charT* low, const charT* high, mask* vec) const;
|
|
|
|
| 158 |
```
|
| 159 |
|
| 160 |
*Effects:* Classifies a character or sequence of characters. For each
|
| 161 |
argument character, identifies a value `M` of type `ctype_base::mask`.
|
| 162 |
The second form identifies a value `M` of type `ctype_base::mask` for
|
|
|
|
| 214 |
if it is known to exist, or its argument if not. The second form returns
|
| 215 |
`high`.
|
| 216 |
|
| 217 |
``` cpp
|
| 218 |
charT do_widen(char c) const;
|
| 219 |
+
const char* do_widen(const char* low, const char* high, charT* dest) const;
|
|
|
|
| 220 |
```
|
| 221 |
|
| 222 |
*Effects:* Applies the simplest reasonable transformation from a `char`
|
| 223 |
value or sequence of `char` values to the corresponding `charT` value or
|
| 224 |
values.[^5] The only characters for which unique transformations are
|
| 225 |
+
required are those in the basic source character set [[lex.charset]].
|
| 226 |
|
| 227 |
For any named `ctype` category with a `ctype <charT>` facet `ctc` and
|
| 228 |
valid `ctype_base::mask` value `M`,
|
| 229 |
`(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^6]
|
| 230 |
|
|
|
|
| 234 |
*Returns:* The first form returns the transformed value. The second form
|
| 235 |
returns `high`.
|
| 236 |
|
| 237 |
``` cpp
|
| 238 |
char do_narrow(charT c, char dfault) const;
|
| 239 |
+
const charT* do_narrow(const charT* low, const charT* high, char dfault, char* dest) const;
|
|
|
|
| 240 |
```
|
| 241 |
|
| 242 |
*Effects:* Applies the simplest reasonable transformation from a `charT`
|
| 243 |
value or sequence of `charT` values to the corresponding `char` value or
|
| 244 |
values.
|
| 245 |
|
| 246 |
+
For any character `c` in the basic source character set [[lex.charset]]
|
| 247 |
+
the transformation is such that
|
| 248 |
|
| 249 |
``` cpp
|
| 250 |
do_widen(do_narrow(c, 0)) == c
|
| 251 |
```
|
| 252 |
|
|
|
|
| 275 |
class ctype_byname : public ctype<charT> {
|
| 276 |
public:
|
| 277 |
using mask = typename ctype<charT>::mask;
|
| 278 |
explicit ctype_byname(const char*, size_t refs = 0);
|
| 279 |
explicit ctype_byname(const string&, size_t refs = 0);
|
| 280 |
+
|
| 281 |
protected:
|
| 282 |
~ctype_byname();
|
| 283 |
};
|
| 284 |
}
|
| 285 |
```
|
| 286 |
|
| 287 |
+
#### `ctype<char>` specialization <a id="facet.ctype.special">[[facet.ctype.special]]</a>
|
| 288 |
|
| 289 |
``` cpp
|
| 290 |
namespace std {
|
| 291 |
template<>
|
| 292 |
class ctype<char> : public locale::facet, public ctype_base {
|
| 293 |
public:
|
| 294 |
using char_type = char;
|
| 295 |
|
| 296 |
+
explicit ctype(const mask* tab = nullptr, bool del = false, size_t refs = 0);
|
|
|
|
| 297 |
|
| 298 |
bool is(mask m, char c) const;
|
| 299 |
const char* is(const char* low, const char* high, mask* vec) const;
|
| 300 |
+
const char* scan_is (mask m, const char* low, const char* high) const;
|
| 301 |
+
const char* scan_not(mask m, const char* low, const char* high) const;
|
|
|
|
|
|
|
| 302 |
|
| 303 |
char toupper(char c) const;
|
| 304 |
const char* toupper(char* low, const char* high) const;
|
| 305 |
char tolower(char c) const;
|
| 306 |
const char* tolower(char* low, const char* high) const;
|
| 307 |
|
| 308 |
char widen(char c) const;
|
| 309 |
const char* widen(const char* low, const char* high, char* to) const;
|
| 310 |
char narrow(char c, char dfault) const;
|
| 311 |
+
const char* narrow(const char* low, const char* high, char dfault, char* to) const;
|
|
|
|
| 312 |
|
| 313 |
static locale::id id;
|
| 314 |
static const size_t table_size = implementation-defined;
|
| 315 |
|
| 316 |
const mask* table() const noexcept;
|
|
|
|
| 322 |
virtual const char* do_toupper(char* low, const char* high) const;
|
| 323 |
virtual char do_tolower(char c) const;
|
| 324 |
virtual const char* do_tolower(char* low, const char* high) const;
|
| 325 |
|
| 326 |
virtual char do_widen(char c) const;
|
| 327 |
+
virtual const char* do_widen(const char* low, const char* high, char* to) const;
|
|
|
|
|
|
|
| 328 |
virtual char do_narrow(char c, char dfault) const;
|
| 329 |
+
virtual const char* do_narrow(const char* low, const char* high,
|
|
|
|
| 330 |
char dfault, char* to) const;
|
| 331 |
};
|
| 332 |
}
|
| 333 |
```
|
| 334 |
|
| 335 |
A specialization `ctype<char>` is provided so that the member functions
|
| 336 |
+
on type `char` can be implemented inline.[^7] The
|
| 337 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 338 |
|
| 339 |
+
##### Destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
|
| 340 |
|
| 341 |
``` cpp
|
| 342 |
~ctype();
|
| 343 |
```
|
| 344 |
|
| 345 |
*Effects:* If the constructor’s first argument was nonzero, and its
|
| 346 |
second argument was `true`, does `delete [] table()`.
|
| 347 |
|
| 348 |
+
##### Members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
|
| 349 |
|
| 350 |
In the following member descriptions, for `unsigned char` values `v`
|
| 351 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
| 352 |
implementation-specific value (possibly different for each such value
|
| 353 |
`v`) without performing the array lookup.
|
| 354 |
|
| 355 |
``` cpp
|
| 356 |
+
explicit ctype(const mask* tbl = nullptr, bool del = false, size_t refs = 0);
|
|
|
|
| 357 |
```
|
| 358 |
|
| 359 |
+
*Preconditions:* Either `tbl == nullptr` is `true` or \[`tbl`,
|
| 360 |
+
`tbl+table_size`) is a valid range.
|
| 361 |
|
| 362 |
*Effects:* Passes its `refs` argument to its base class constructor.
|
| 363 |
|
| 364 |
``` cpp
|
| 365 |
bool is(mask m, char c) const;
|
| 366 |
+
const char* is(const char* low, const char* high, mask* vec) const;
|
|
|
|
| 367 |
```
|
| 368 |
|
| 369 |
*Effects:* The second form, for all `*p` in the range \[`low`, `high`),
|
| 370 |
assigns into `vec[p - low]` the value `table()[(unsigned char)*p]`.
|
| 371 |
|
| 372 |
*Returns:* The first form returns `table()[(unsigned char)c] & m`; the
|
| 373 |
second form returns `high`.
|
| 374 |
|
| 375 |
``` cpp
|
| 376 |
+
const char* scan_is(mask m, const char* low, const char* high) const;
|
|
|
|
| 377 |
```
|
| 378 |
|
| 379 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 380 |
|
| 381 |
``` cpp
|
|
|
|
| 383 |
```
|
| 384 |
|
| 385 |
is `true`.
|
| 386 |
|
| 387 |
``` cpp
|
| 388 |
+
const char* scan_not(mask m, const char* low, const char* high) const;
|
|
|
|
| 389 |
```
|
| 390 |
|
| 391 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 392 |
|
| 393 |
``` cpp
|
|
|
|
| 410 |
|
| 411 |
*Returns:* `do_tolower(c)` or `do_tolower(low, high)`, respectively.
|
| 412 |
|
| 413 |
``` cpp
|
| 414 |
char widen(char c) const;
|
| 415 |
+
const char* widen(const char* low, const char* high, char* to) const;
|
|
|
|
| 416 |
```
|
| 417 |
|
| 418 |
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`, respectively.
|
| 419 |
|
| 420 |
``` cpp
|
| 421 |
char narrow(char c, char dfault) const;
|
| 422 |
+
const char* narrow(const char* low, const char* high, char dfault, char* to) const;
|
|
|
|
| 423 |
```
|
| 424 |
|
| 425 |
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`,
|
| 426 |
respectively.
|
| 427 |
|
|
|
|
| 430 |
```
|
| 431 |
|
| 432 |
*Returns:* The first constructor argument, if it was nonzero, otherwise
|
| 433 |
`classic_table()`.
|
| 434 |
|
| 435 |
+
##### Static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
|
| 436 |
|
| 437 |
``` cpp
|
| 438 |
static const mask* classic_table() noexcept;
|
| 439 |
```
|
| 440 |
|
| 441 |
*Returns:* A pointer to the initial element of an array of size
|
| 442 |
`table_size` which represents the classifications of characters in the
|
| 443 |
`"C"` locale.
|
| 444 |
|
| 445 |
+
##### Virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
|
| 446 |
|
| 447 |
``` cpp
|
| 448 |
char do_toupper(char) const;
|
| 449 |
const char* do_toupper(char* low, const char* high) const;
|
| 450 |
char do_tolower(char) const;
|
| 451 |
const char* do_tolower(char* low, const char* high) const;
|
| 452 |
|
| 453 |
virtual char do_widen(char c) const;
|
| 454 |
+
virtual const char* do_widen(const char* low, const char* high, char* to) const;
|
|
|
|
|
|
|
| 455 |
virtual char do_narrow(char c, char dfault) const;
|
| 456 |
+
virtual const char* do_narrow(const char* low, const char* high,
|
|
|
|
| 457 |
char dfault, char* to) const;
|
| 458 |
```
|
| 459 |
|
| 460 |
These functions are described identically as those members of the same
|
| 461 |
+
name in the `ctype` class template [[locale.ctype.members]].
|
| 462 |
|
| 463 |
#### Class template `codecvt` <a id="locale.codecvt">[[locale.codecvt]]</a>
|
| 464 |
|
| 465 |
``` cpp
|
| 466 |
namespace std {
|
|
|
|
| 521 |
}
|
| 522 |
```
|
| 523 |
|
| 524 |
The class `codecvt<internT, externT, stateT>` is for use when converting
|
| 525 |
from one character encoding to another, such as from wide characters to
|
| 526 |
+
multibyte characters or between wide character encodings such as UTF-32
|
| 527 |
and EUC.
|
| 528 |
|
| 529 |
The `stateT` argument selects the pair of character encodings being
|
| 530 |
mapped between.
|
| 531 |
|
| 532 |
+
The specializations required in [[locale.category.facets]]
|
| 533 |
+
[[locale.category]] convert the implementation-defined native character
|
| 534 |
+
set. `codecvt<char, char, mbstate_t>` implements a degenerate
|
| 535 |
+
conversion; it does not convert at all. The specialization
|
| 536 |
+
`codecvt<char16_t, char8_t, mbstate_t>` converts between the UTF-16 and
|
|
|
|
| 537 |
UTF-8 encoding forms, and the specialization `codecvt`
|
| 538 |
+
`<char32_t, char8_t, mbstate_t>` converts between the UTF-32 and UTF-8
|
| 539 |
encoding forms. `codecvt<wchar_t, char, mbstate_t>` converts between the
|
| 540 |
+
native character sets for ordinary and wide characters. Specializations
|
| 541 |
+
on `mbstate_t` perform conversion between encodings known to the library
|
| 542 |
implementer. Other encodings can be converted by specializing on a
|
| 543 |
+
program-defined `stateT` type. Objects of type `stateT` can contain any
|
| 544 |
state that is useful to communicate to or from the specialized `do_in`
|
| 545 |
or `do_out` members.
|
| 546 |
|
| 547 |
+
##### Members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
|
| 548 |
|
| 549 |
``` cpp
|
| 550 |
result out(
|
| 551 |
stateT& state,
|
| 552 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
|
|
| 594 |
int max_length() const noexcept;
|
| 595 |
```
|
| 596 |
|
| 597 |
*Returns:* `do_max_length()`.
|
| 598 |
|
| 599 |
+
##### Virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
|
| 600 |
|
| 601 |
``` cpp
|
| 602 |
result do_out(
|
| 603 |
stateT& state,
|
| 604 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
|
|
| 608 |
stateT& state,
|
| 609 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 610 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 611 |
```
|
| 612 |
|
| 613 |
+
*Preconditions:* `(from <= from_end && to <= to_end)` is well-defined
|
| 614 |
+
and `true`; `state` is initialized, if at the beginning of a sequence,
|
| 615 |
+
or else is equal to the result of converting the preceding characters in
|
| 616 |
+
the sequence.
|
| 617 |
|
| 618 |
*Effects:* Translates characters in the source range \[`from`,
|
| 619 |
`from_end`), placing the results in sequential positions starting at
|
| 620 |
destination `to`. Converts no more than `(from_end - from)` source
|
| 621 |
elements, and stores no more than `(to_end - to)` destination elements.
|
|
|
|
| 626 |
`externT` are the same type and the converted sequence is identical to
|
| 627 |
the input sequence \[`from`, `from``next`). `to_next` is set equal to
|
| 628 |
`to`, the value of `state` is unchanged, and there are no changes to the
|
| 629 |
values in \[`to`, `to_end`).
|
| 630 |
|
| 631 |
+
A `codecvt` facet that is used by `basic_filebuf` [[file.streams]] shall
|
| 632 |
+
have the property that if
|
| 633 |
|
| 634 |
``` cpp
|
| 635 |
do_out(state, from, from_end, from_next, to, to_end, to_next)
|
| 636 |
```
|
| 637 |
|
|
|
|
| 664 |
[*Note 2*: This argument can be used, for example, to maintain shift
|
| 665 |
state, to specify conversion options (such as count only), or to
|
| 666 |
identify a cache of seek offsets. — *end note*]
|
| 667 |
|
| 668 |
*Returns:* An enumeration value, as summarized in
|
| 669 |
+
[[locale.codecvt.inout]].
|
| 670 |
|
| 671 |
+
**Table: `do_in/do_out` result values** <a id="locale.codecvt.inout">[locale.codecvt.inout]</a>
|
| 672 |
|
| 673 |
| Value | Meaning |
|
| 674 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 675 |
| `ok` | completed the conversion |
|
| 676 |
| `partial` | not all source characters converted |
|
|
|
|
| 685 |
|
| 686 |
``` cpp
|
| 687 |
result do_unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
|
| 688 |
```
|
| 689 |
|
| 690 |
+
*Preconditions:* `(to <= to_end)` is well-defined and `true`; `state` is
|
| 691 |
+
initialized, if at the beginning of a sequence, or else is equal to the
|
| 692 |
+
result of converting the preceding characters in the sequence.
|
| 693 |
|
| 694 |
*Effects:* Places characters starting at `to` that should be appended to
|
| 695 |
terminate a sequence when the current `stateT` is given by `state`.[^9]
|
| 696 |
Stores no more than `(to_end - to)` destination elements, and leaves the
|
| 697 |
`to_next` pointer pointing one beyond the last element successfully
|
| 698 |
stored.
|
| 699 |
|
| 700 |
*Returns:* An enumeration value, as summarized in
|
| 701 |
+
[[locale.codecvt.unshift]].
|
| 702 |
|
| 703 |
+
**Table: `do_unshift` result values** <a id="locale.codecvt.unshift">[locale.codecvt.unshift]</a>
|
| 704 |
|
| 705 |
| Value | Meaning |
|
| 706 |
| --------- | -------------------------------------------------------------------------------------------------------------------- |
|
| 707 |
| `ok` | completed the sequence |
|
| 708 |
| `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
|
|
|
|
| 727 |
|
| 728 |
``` cpp
|
| 729 |
int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
|
| 730 |
```
|
| 731 |
|
| 732 |
+
*Preconditions:* `(from <= from_end)` is well-defined and `true`;
|
| 733 |
+
`state` is initialized, if at the beginning of a sequence, or else is
|
| 734 |
+
equal to the result of converting the preceding characters in the
|
| 735 |
+
sequence.
|
| 736 |
|
| 737 |
+
*Effects:* The effect on the `state` argument is as if it called
|
| 738 |
`do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
|
| 739 |
to a buffer of at least `max` elements.
|
| 740 |
|
| 741 |
*Returns:* `(from_next-from)` where `from_next` is the largest value in
|
| 742 |
the range \[`from`, `from_end`\] such that the sequence of values in the
|
|
|
|
| 761 |
template<class internT, class externT, class stateT>
|
| 762 |
class codecvt_byname : public codecvt<internT, externT, stateT> {
|
| 763 |
public:
|
| 764 |
explicit codecvt_byname(const char*, size_t refs = 0);
|
| 765 |
explicit codecvt_byname(const string&, size_t refs = 0);
|
| 766 |
+
|
| 767 |
protected:
|
| 768 |
~codecvt_byname();
|
| 769 |
};
|
| 770 |
}
|
| 771 |
```
|
|
|
|
| 777 |
Implementations may (but are not required to) delegate extraction of
|
| 778 |
smaller types to extractors for larger types.[^11]
|
| 779 |
|
| 780 |
All specifications of member functions for `num_put` and `num_get` in
|
| 781 |
the subclauses of [[category.numeric]] only apply to the
|
| 782 |
+
specializations required in Tables [[tab:locale.category.facets]] and
|
| 783 |
+
[[tab:locale.spec]] [[locale.category]], namely `num_get<char>`,
|
| 784 |
+
`num_get<wchar_t>`, `num_get<C, InputIterator>`, `num_put<char>`,
|
| 785 |
+
`num_put<wchar_t>`, and `num_put<C, OutputIterator>`. These
|
| 786 |
+
specializations refer to the `ios_base&` argument for formatting
|
| 787 |
+
specifications [[locale.categories]], and to its imbued locale for the
|
| 788 |
+
`numpunct<>` facet to identify all numeric punctuation preferences, and
|
| 789 |
+
also for the `ctype<>` facet to perform character classification.
|
|
|
|
| 790 |
|
| 791 |
Extractor and inserter members of the standard iostreams use `num_get<>`
|
| 792 |
and `num_put<>` member functions for formatting and parsing numeric
|
| 793 |
values ([[istream.formatted.reqmts]], [[ostream.formatted.reqmts]]).
|
| 794 |
|
|
|
|
| 858 |
```
|
| 859 |
|
| 860 |
The facet `num_get` is used to parse numeric values from an input
|
| 861 |
sequence such as an istream.
|
| 862 |
|
| 863 |
+
##### Members <a id="facet.num.get.members">[[facet.num.get.members]]</a>
|
| 864 |
|
| 865 |
``` cpp
|
| 866 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
| 867 |
ios_base::iostate& err, bool& val) const;
|
| 868 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
|
|
|
| 887 |
ios_base::iostate& err, void*& val) const;
|
| 888 |
```
|
| 889 |
|
| 890 |
*Returns:* `do_get(in, end, str, err, val)`.
|
| 891 |
|
| 892 |
+
##### Virtual functions <a id="facet.num.get.virtuals">[[facet.num.get.virtuals]]</a>
|
| 893 |
|
| 894 |
``` cpp
|
| 895 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 896 |
ios_base::iostate& err, long& val) const;
|
| 897 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
|
|
|
| 938 |
fmtflags uppercase = (flags & ios_base::uppercase);
|
| 939 |
fmtflags boolalpha = (flags & ios_base::boolalpha);
|
| 940 |
```
|
| 941 |
|
| 942 |
For conversion to an integral type, the function determines the integral
|
| 943 |
+
conversion specifier as indicated in [[facet.num.get.int]]. The
|
| 944 |
+
table is ordered. That is, the first line whose condition is true
|
| 945 |
+
applies.
|
| 946 |
|
| 947 |
+
**Table: Integer conversions** <a id="facet.num.get.int">[facet.num.get.int]</a>
|
| 948 |
|
| 949 |
| State | `stdio` equivalent |
|
| 950 |
| ------------------------ | ------------------ |
|
| 951 |
| `basefield == oct` | `%o` |
|
| 952 |
| `basefield == hex` | `%X` |
|
| 953 |
| `basefield == 0` | `%i` `signed` integral type | `%d` |
|
| 954 |
| `unsigned` integral type | `%u` |
|
| 955 |
|
| 956 |
|
| 957 |
+
For conversions to a floating-point type the specifier is `%g`.
|
| 958 |
|
| 959 |
For conversions to `void*` the specifier is `%p`.
|
| 960 |
|
| 961 |
A length modifier is added to the conversion specification, if needed,
|
| 962 |
+
as indicated in [[facet.num.get.length]].
|
| 963 |
|
| 964 |
+
**Table: Length modifier** <a id="facet.num.get.length">[facet.num.get.length]</a>
|
| 965 |
|
| 966 |
| Type | Length modifier |
|
| 967 |
| -------------------- | --------------- |
|
| 968 |
| `short` | `h` |
|
| 969 |
| `unsigned short` | `h` |
|
|
|
|
| 1131 |
```
|
| 1132 |
|
| 1133 |
The facet `num_put` is used to format numeric values to a character
|
| 1134 |
sequence such as an ostream.
|
| 1135 |
|
| 1136 |
+
##### Members <a id="facet.num.put.members">[[facet.num.put.members]]</a>
|
| 1137 |
|
| 1138 |
``` cpp
|
| 1139 |
iter_type put(iter_type out, ios_base& str, char_type fill, bool val) const;
|
| 1140 |
iter_type put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1141 |
iter_type put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
|
|
|
| 1146 |
iter_type put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
| 1147 |
```
|
| 1148 |
|
| 1149 |
*Returns:* `do_put(out, str, fill, val)`.
|
| 1150 |
|
| 1151 |
+
##### Virtual functions <a id="facet.num.put.virtuals">[[facet.num.put.virtuals]]</a>
|
| 1152 |
|
| 1153 |
``` cpp
|
| 1154 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1155 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
| 1156 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
|
|
|
|
| 1159 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long double val) const;
|
| 1160 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
| 1161 |
```
|
| 1162 |
|
| 1163 |
*Effects:* Writes characters to the sequence `out`, formatting `val` as
|
| 1164 |
+
desired. In the following description, `loc` names a local variable
|
| 1165 |
+
initialized as
|
| 1166 |
|
| 1167 |
``` cpp
|
| 1168 |
locale loc = str.getloc();
|
| 1169 |
```
|
| 1170 |
|
| 1171 |
The details of this operation occur in several stages:
|
| 1172 |
|
| 1173 |
- Stage 1: Determine a printf conversion specifier `spec` and determine
|
| 1174 |
+
the characters that would be printed by `printf` [[c.files]] given
|
| 1175 |
this conversion specifier for
|
| 1176 |
``` cpp
|
| 1177 |
printf(spec, val)
|
| 1178 |
```
|
| 1179 |
|
| 1180 |
assuming that the current locale is the `"C"` locale.
|
| 1181 |
- Stage 2: Adjust the representation by converting each `char`
|
| 1182 |
determined by stage 1 to a `charT` using a conversion and values
|
| 1183 |
+
returned by members of `use_facet<numpunct<charT>>(loc)`.
|
| 1184 |
- Stage 3: Determine where padding is required.
|
| 1185 |
- Stage 4: Insert the sequence into the `out`.
|
| 1186 |
|
| 1187 |
Detailed descriptions of each stage follow.
|
| 1188 |
|
|
|
|
| 1208 |
line whose condition is true applies. A line without a condition is the
|
| 1209 |
default behavior when none of the earlier lines apply.
|
| 1210 |
|
| 1211 |
For conversion from an integral type other than a character type, the
|
| 1212 |
function determines the integral conversion specifier as indicated in
|
| 1213 |
+
[[facet.num.put.int]].
|
| 1214 |
|
| 1215 |
+
**Table: Integer conversions** <a id="facet.num.put.int">[facet.num.put.int]</a>
|
| 1216 |
|
| 1217 |
| State | `stdio` equivalent |
|
| 1218 |
| -------------------------------------------- | ------------------ |
|
| 1219 |
| `basefield == ios_base::oct` | `%o` |
|
| 1220 |
| `(basefield == ios_base::hex) && !uppercase` | `%x` |
|
|
|
|
| 1223 |
| for an `unsigned` integral type | `%u` |
|
| 1224 |
|
| 1225 |
|
| 1226 |
For conversion from a floating-point type, the function determines the
|
| 1227 |
floating-point conversion specifier as indicated in
|
| 1228 |
+
[[facet.num.put.fp]].
|
| 1229 |
|
| 1230 |
+
**Table: Floating-point conversions** <a id="facet.num.put.fp">[facet.num.put.fp]</a>
|
| 1231 |
|
| 1232 |
| State | `stdio` equivalent |
|
| 1233 |
| ---------------------------------------------------------------------- | ------------------ |
|
| 1234 |
| `floatfield == ios_base::fixed` | `%f` |
|
| 1235 |
| `floatfield == ios_base::scientific && !uppercase` | `%e` |
|
|
|
|
| 1240 |
| otherwise | `%G` |
|
| 1241 |
|
| 1242 |
|
| 1243 |
For conversions from an integral or floating-point type a length
|
| 1244 |
modifier is added to the conversion specifier as indicated in
|
| 1245 |
+
[[facet.num.put.length]].
|
| 1246 |
|
| 1247 |
+
**Table: Length modifier** <a id="facet.num.put.length">[facet.num.put.length]</a>
|
| 1248 |
|
| 1249 |
| Type | Length modifier |
|
| 1250 |
| -------------------- | --------------- |
|
| 1251 |
| `long` | `l` |
|
| 1252 |
| `long long` | `ll` |
|
|
|
|
| 1255 |
| `long double` | `L` |
|
| 1256 |
| otherwise | none |
|
| 1257 |
|
| 1258 |
|
| 1259 |
The conversion specifier has the following optional additional
|
| 1260 |
+
qualifiers prepended as indicated in [[facet.num.put.conv]].
|
|
|
|
| 1261 |
|
| 1262 |
+
**Table: Numeric conversions** <a id="facet.num.put.conv">[facet.num.put.conv]</a>
|
| 1263 |
|
| 1264 |
| Type(s) | State | `stdio` equivalent |
|
| 1265 |
| --------------------- | ----------- | ------------------ |
|
| 1266 |
| an integral type | `showpos` | `+` |
|
| 1267 |
| | `showbase` | `#` |
|
|
|
|
| 1281 |
conversion specifier determined above.
|
| 1282 |
|
| 1283 |
- **Stage 2:**
|
| 1284 |
|
| 1285 |
Any character `c` other than a decimal point(.) is converted to a
|
| 1286 |
+
`charT` via
|
| 1287 |
+
|
| 1288 |
+
``` cpp
|
| 1289 |
+
use_facet<ctype<charT>>(loc).widen(c)
|
| 1290 |
+
```
|
| 1291 |
|
| 1292 |
A local variable `punct` is initialized via
|
| 1293 |
|
| 1294 |
``` cpp
|
| 1295 |
+
const numpunct<charT>& punct = use_facet<numpunct<charT>>(loc);
|
| 1296 |
```
|
| 1297 |
|
| 1298 |
For arithmetic types, `punct.thousands_sep()` characters are inserted
|
| 1299 |
into the sequence as determined by the value returned by
|
| 1300 |
`punct.do_grouping()` using the method described
|
|
|
|
| 1309 |
``` cpp
|
| 1310 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 1311 |
```
|
| 1312 |
|
| 1313 |
The location of any padding[^12] is determined according to
|
| 1314 |
+
[[facet.num.put.fill]].
|
| 1315 |
|
| 1316 |
+
**Table: Fill padding** <a id="facet.num.put.fill">[facet.num.put.fill]</a>
|
| 1317 |
|
| 1318 |
| State | Location |
|
| 1319 |
| ------------------------------------------------------------------------------ | ------------------ |
|
| 1320 |
| `adjustfield == ios_base::left` | pad after |
|
| 1321 |
| `adjustfield == ios_base::right` | pad before |
|
|
|
|
| 1389 |
}
|
| 1390 |
```
|
| 1391 |
|
| 1392 |
`numpunct<>`
|
| 1393 |
|
| 1394 |
+
specifies numeric punctuation. The specializations required in
|
| 1395 |
+
[[locale.category.facets]] [[locale.category]], namely
|
| 1396 |
`numpunct<{}wchar_t>` and `numpunct<char>`, provide classic `"C"`
|
| 1397 |
numeric formats, i.e., they contain information equivalent to that
|
| 1398 |
contained in the `"C"` locale or their wide character counterparts as if
|
| 1399 |
obtained by a call to `widen`.
|
| 1400 |
|
| 1401 |
+
The syntax for number formats is as follows, where represents the radix
|
| 1402 |
+
set specified by the `fmtflags` argument value, and and are the results
|
| 1403 |
+
of corresponding `numpunct<charT>` members. Integer values have the
|
| 1404 |
+
format:
|
| 1405 |
+
|
| 1406 |
+
``` bnf
|
| 1407 |
+
intval:
|
| 1408 |
+
signₒₚₜ units
|
| 1409 |
+
```
|
| 1410 |
+
|
| 1411 |
+
``` bnf
|
| 1412 |
+
sign:
|
| 1413 |
+
'+'
|
| 1414 |
+
'-'
|
| 1415 |
+
```
|
| 1416 |
+
|
| 1417 |
+
``` bnf
|
| 1418 |
+
units:
|
| 1419 |
+
digits
|
| 1420 |
+
digits thousands-sep units
|
| 1421 |
+
```
|
| 1422 |
+
|
| 1423 |
+
``` bnf
|
| 1424 |
+
digits:
|
| 1425 |
+
digit digitsₒₚₜ
|
| 1426 |
```
|
| 1427 |
|
| 1428 |
and floating-point values have:
|
| 1429 |
|
| 1430 |
+
``` bnf
|
| 1431 |
+
floatval:
|
| 1432 |
+
signₒₚₜ units fractionalₒₚₜ exponentₒₚₜ
|
| 1433 |
+
signₒₚₜ decimal-point digits exponentₒₚₜ
|
| 1434 |
```
|
| 1435 |
|
| 1436 |
+
``` bnf
|
| 1437 |
+
fractional:
|
| 1438 |
+
decimal-point digitsₒₚₜ
|
| 1439 |
+
```
|
| 1440 |
+
|
| 1441 |
+
``` bnf
|
| 1442 |
+
exponent:
|
| 1443 |
+
e signₒₚₜ digits
|
| 1444 |
+
```
|
| 1445 |
+
|
| 1446 |
+
``` bnf
|
| 1447 |
+
e:
|
| 1448 |
+
'e'
|
| 1449 |
+
'E'
|
| 1450 |
+
```
|
| 1451 |
+
|
| 1452 |
+
where the number of digits between is as specified by `do_grouping()`.
|
| 1453 |
+
For parsing, if the portion contains no thousands-separators, no
|
| 1454 |
+
grouping constraint is applied.
|
| 1455 |
|
| 1456 |
+
##### Members <a id="facet.numpunct.members">[[facet.numpunct.members]]</a>
|
| 1457 |
|
| 1458 |
``` cpp
|
| 1459 |
char_type decimal_point() const;
|
| 1460 |
```
|
| 1461 |
|
|
|
|
| 1478 |
string_type falsename() const;
|
| 1479 |
```
|
| 1480 |
|
| 1481 |
*Returns:* `do_truename()` or `do_falsename()`, respectively.
|
| 1482 |
|
| 1483 |
+
##### Virtual functions <a id="facet.numpunct.virtuals">[[facet.numpunct.virtuals]]</a>
|
| 1484 |
|
| 1485 |
``` cpp
|
| 1486 |
char_type do_decimal_point() const;
|
| 1487 |
```
|
| 1488 |
|
|
|
|
| 1498 |
|
| 1499 |
``` cpp
|
| 1500 |
string do_grouping() const;
|
| 1501 |
```
|
| 1502 |
|
| 1503 |
+
*Returns:* A `string` `vec` used as a vector of integer values, in which
|
| 1504 |
+
each element `vec[i]` represents the number of digits[^13] in the group
|
| 1505 |
+
at position `i`, starting with position 0 as the rightmost group. If
|
| 1506 |
+
`vec.size() <= i`, the number is the same as group `(i - 1)`; if
|
| 1507 |
+
`(i < 0 || vec[i] <= 0 || vec[i] == CHAR_MAX)`, the size of the digit
|
| 1508 |
+
group is unlimited.
|
| 1509 |
|
| 1510 |
The required specializations return the empty string, indicating no
|
| 1511 |
grouping.
|
| 1512 |
|
| 1513 |
``` cpp
|
|
|
|
| 1532 |
using char_type = charT;
|
| 1533 |
using string_type = basic_string<charT>;
|
| 1534 |
|
| 1535 |
explicit numpunct_byname(const char*, size_t refs = 0);
|
| 1536 |
explicit numpunct_byname(const string&, size_t refs = 0);
|
| 1537 |
+
|
| 1538 |
protected:
|
| 1539 |
~numpunct_byname();
|
| 1540 |
};
|
| 1541 |
}
|
| 1542 |
```
|
|
|
|
| 1573 |
```
|
| 1574 |
|
| 1575 |
The class `collate<charT>` provides features for use in the collation
|
| 1576 |
(comparison) and hashing of strings. A locale member function template,
|
| 1577 |
`operator()`, uses the collate facet to allow a locale to act directly
|
| 1578 |
+
as the predicate argument for standard algorithms [[algorithms]] and
|
| 1579 |
+
containers operating on strings. The specializations required in
|
| 1580 |
+
[[locale.category.facets]] [[locale.category]], namely `collate<char>`
|
| 1581 |
+
and `collate<wchar_t>`, apply lexicographic ordering
|
| 1582 |
+
[[alg.lex.comparison]].
|
| 1583 |
|
| 1584 |
Each function compares a string of characters `*p` in the range \[`low`,
|
| 1585 |
`high`).
|
| 1586 |
|
| 1587 |
+
##### Members <a id="locale.collate.members">[[locale.collate.members]]</a>
|
| 1588 |
|
| 1589 |
``` cpp
|
| 1590 |
int compare(const charT* low1, const charT* high1,
|
| 1591 |
const charT* low2, const charT* high2) const;
|
| 1592 |
```
|
|
|
|
| 1603 |
long hash(const charT* low, const charT* high) const;
|
| 1604 |
```
|
| 1605 |
|
| 1606 |
*Returns:* `do_hash(low, high)`.
|
| 1607 |
|
| 1608 |
+
##### Virtual functions <a id="locale.collate.virtuals">[[locale.collate.virtuals]]</a>
|
| 1609 |
|
| 1610 |
``` cpp
|
| 1611 |
int do_compare(const charT* low1, const charT* high1,
|
| 1612 |
const charT* low2, const charT* high2) const;
|
| 1613 |
```
|
| 1614 |
|
| 1615 |
*Returns:* `1` if the first string is greater than the second, `-1` if
|
| 1616 |
less, zero otherwise. The specializations required in
|
| 1617 |
+
[[locale.category.facets]][[locale.category]], namely `collate<char>`
|
| 1618 |
+
and `collate<wchar_t>`, implement a lexicographical
|
| 1619 |
+
comparison [[alg.lex.comparison]].
|
| 1620 |
|
| 1621 |
``` cpp
|
| 1622 |
string_type do_transform(const charT* low, const charT* high) const;
|
| 1623 |
```
|
| 1624 |
|
|
|
|
| 1648 |
public:
|
| 1649 |
using string_type = basic_string<charT>;
|
| 1650 |
|
| 1651 |
explicit collate_byname(const char*, size_t refs = 0);
|
| 1652 |
explicit collate_byname(const string&, size_t refs = 0);
|
| 1653 |
+
|
| 1654 |
protected:
|
| 1655 |
~collate_byname();
|
| 1656 |
};
|
| 1657 |
}
|
| 1658 |
```
|
|
|
|
| 1661 |
|
| 1662 |
Templates `time_get<charT, InputIterator>` and
|
| 1663 |
`time_put<charT, OutputIterator>` provide date and time formatting and
|
| 1664 |
parsing. All specifications of member functions for `time_put` and
|
| 1665 |
`time_get` in the subclauses of [[category.time]] only apply to the
|
| 1666 |
+
specializations required in Tables [[tab:locale.category.facets]] and
|
| 1667 |
+
[[tab:locale.spec]] [[locale.category]]. Their members use their
|
| 1668 |
+
`ios_base&`, `ios_base::iostate&`, and `fill` arguments as described in
|
|
|
|
| 1669 |
[[locale.categories]], and the `ctype<>` facet, to determine formatting
|
| 1670 |
details.
|
| 1671 |
|
| 1672 |
#### Class template `time_get` <a id="locale.time.get">[[locale.time.get]]</a>
|
| 1673 |
|
|
|
|
| 1735 |
unspecified values are assigned.[^15]
|
| 1736 |
|
| 1737 |
If the end iterator is reached during parsing by any of the `get()`
|
| 1738 |
member functions, the member sets `ios_base::eofbit` in `err`.
|
| 1739 |
|
| 1740 |
+
##### Members <a id="locale.time.get.members">[[locale.time.get.members]]</a>
|
| 1741 |
|
| 1742 |
``` cpp
|
| 1743 |
dateorder date_order() const;
|
| 1744 |
```
|
| 1745 |
|
|
|
|
| 1786 |
``` cpp
|
| 1787 |
iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
| 1788 |
tm* t, const char_type* fmt, const char_type* fmtend) const;
|
| 1789 |
```
|
| 1790 |
|
| 1791 |
+
*Preconditions:* \[`fmt`, `fmtend`) is a valid range.
|
| 1792 |
|
| 1793 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 1794 |
It then enters a loop, reading zero or more characters from `s` at each
|
| 1795 |
iteration. Unless otherwise specified below, the loop terminates when
|
| 1796 |
the first of the following conditions holds:
|
|
|
|
| 1828 |
whether multi-character sequences are considered while doing
|
| 1829 |
so. — *end note*]
|
| 1830 |
|
| 1831 |
*Returns:* `s`.
|
| 1832 |
|
| 1833 |
+
##### Virtual functions <a id="locale.time.get.virtuals">[[locale.time.get.virtuals]]</a>
|
| 1834 |
|
| 1835 |
``` cpp
|
| 1836 |
dateorder do_date_order() const;
|
| 1837 |
```
|
| 1838 |
|
|
|
|
| 1862 |
|
| 1863 |
*Effects:* Reads characters starting at `s` until it has extracted those
|
| 1864 |
`struct tm` members and remaining format characters used by
|
| 1865 |
`time_put<>::put` to produce one of the following formats, or until it
|
| 1866 |
encounters an error. The format depends on the value returned by
|
| 1867 |
+
`date_order()` as shown in [[locale.time.get.dogetdate]].
|
|
|
|
| 1868 |
|
| 1869 |
+
**Table: `do_get_date` effects** <a id="locale.time.get.dogetdate">[locale.time.get.dogetdate]</a>
|
| 1870 |
|
| 1871 |
| `date_order()` | Format |
|
| 1872 |
| -------------- | ---------- |
|
| 1873 |
| `no_order` | `"%m%d%y"` |
|
| 1874 |
| `dmy` | `"%d%m%y"` |
|
|
|
|
| 1915 |
``` cpp
|
| 1916 |
iter_type do_get(iter_type s, iter_type end, ios_base& f,
|
| 1917 |
ios_base::iostate& err, tm* t, char format, char modifier) const;
|
| 1918 |
```
|
| 1919 |
|
| 1920 |
+
*Preconditions:* `t` points to an object.
|
| 1921 |
|
| 1922 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 1923 |
It then reads characters starting at `s` until it encounters an error,
|
| 1924 |
or until it has extracted and assigned those `struct tm` members, and
|
| 1925 |
any remaining format characters, corresponding to a conversion directive
|
|
|
|
| 1939 |
members are unspecified and may be outside their valid range.
|
| 1940 |
|
| 1941 |
*Remarks:* It is unspecified whether multiple calls to `do_get()` with
|
| 1942 |
the address of the same `struct tm` object will update the current
|
| 1943 |
contents of the object or simply overwrite its members. Portable
|
| 1944 |
+
programs should zero out the object before invoking the function.
|
| 1945 |
|
| 1946 |
*Returns:* An iterator pointing immediately beyond the last character
|
| 1947 |
recognized as possibly part of a valid input sequence for the given
|
| 1948 |
`format` and `modifier`.
|
| 1949 |
|
|
|
|
| 1957 |
using dateorder = time_base::dateorder;
|
| 1958 |
using iter_type = InputIterator;
|
| 1959 |
|
| 1960 |
explicit time_get_byname(const char*, size_t refs = 0);
|
| 1961 |
explicit time_get_byname(const string&, size_t refs = 0);
|
| 1962 |
+
|
| 1963 |
protected:
|
| 1964 |
~time_get_byname();
|
| 1965 |
};
|
| 1966 |
}
|
| 1967 |
```
|
|
|
|
| 1992 |
char format, char modifier) const;
|
| 1993 |
};
|
| 1994 |
}
|
| 1995 |
```
|
| 1996 |
|
| 1997 |
+
##### Members <a id="locale.time.put.members">[[locale.time.put.members]]</a>
|
| 1998 |
|
| 1999 |
``` cpp
|
| 2000 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
| 2001 |
const charT* pattern, const charT* pat_end) const;
|
| 2002 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
|
|
|
| 2025 |
reasonable default for this argument. — *end note*]
|
| 2026 |
|
| 2027 |
*Returns:* An iterator pointing immediately after the last character
|
| 2028 |
produced.
|
| 2029 |
|
| 2030 |
+
##### Virtual functions <a id="locale.time.put.virtuals">[[locale.time.put.virtuals]]</a>
|
| 2031 |
|
| 2032 |
``` cpp
|
| 2033 |
iter_type do_put(iter_type s, ios_base&, char_type fill, const tm* t,
|
| 2034 |
char format, char modifier) const;
|
| 2035 |
```
|
|
|
|
| 2052 |
#### Class template `time_put_byname` <a id="locale.time.put.byname">[[locale.time.put.byname]]</a>
|
| 2053 |
|
| 2054 |
``` cpp
|
| 2055 |
namespace std {
|
| 2056 |
template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2057 |
+
class time_put_byname : public time_put<charT, OutputIterator> {
|
|
|
|
| 2058 |
public:
|
| 2059 |
using char_type = charT;
|
| 2060 |
using iter_type = OutputIterator;
|
| 2061 |
|
| 2062 |
explicit time_put_byname(const char*, size_t refs = 0);
|
| 2063 |
explicit time_put_byname(const string&, size_t refs = 0);
|
| 2064 |
+
|
| 2065 |
protected:
|
| 2066 |
~time_put_byname();
|
| 2067 |
};
|
| 2068 |
}
|
| 2069 |
```
|
|
|
|
| 2073 |
These templates handle monetary formats. A template parameter indicates
|
| 2074 |
whether local or international monetary formats are to be used.
|
| 2075 |
|
| 2076 |
All specifications of member functions for `money_put` and `money_get`
|
| 2077 |
in the subclauses of [[category.monetary]] only apply to the
|
| 2078 |
+
specializations required in Tables [[tab:locale.category.facets]] and
|
| 2079 |
+
[[tab:locale.spec]] [[locale.category]]. Their members use their
|
| 2080 |
+
`ios_base&`, `ios_base::iostate&`, and `fill` arguments as described in
|
|
|
|
| 2081 |
[[locale.categories]], and the `moneypunct<>` and `ctype<>` facets, to
|
| 2082 |
determine formatting details.
|
| 2083 |
|
| 2084 |
#### Class template `money_get` <a id="locale.money.get">[[locale.money.get]]</a>
|
| 2085 |
|
|
|
|
| 2111 |
ios_base::iostate& err, string_type& digits) const;
|
| 2112 |
};
|
| 2113 |
}
|
| 2114 |
```
|
| 2115 |
|
| 2116 |
+
##### Members <a id="locale.money.get.members">[[locale.money.get.members]]</a>
|
| 2117 |
|
| 2118 |
``` cpp
|
| 2119 |
+
iter_type get(iter_type s, iter_type end, bool intl, ios_base& f,
|
| 2120 |
+
ios_base::iostate& err, long double& quant) const;
|
| 2121 |
+
iter_type get(iter_type s, iter_type end, bool intl, ios_base& f,
|
|
|
|
| 2122 |
ios_base::iostate& err, string_type& quant) const;
|
| 2123 |
```
|
| 2124 |
|
| 2125 |
*Returns:* `do_get(s, end, intl, f, err, quant)`.
|
| 2126 |
|
| 2127 |
+
##### Virtual functions <a id="locale.money.get.virtuals">[[locale.money.get.virtuals]]</a>
|
| 2128 |
|
| 2129 |
``` cpp
|
| 2130 |
+
iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
|
| 2131 |
+
ios_base::iostate& err, long double& units) const;
|
| 2132 |
+
iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
|
| 2133 |
+
ios_base::iostate& err, string_type& digits) const;
|
|
|
|
|
|
|
| 2134 |
```
|
| 2135 |
|
| 2136 |
*Effects:* Reads characters from `s` to parse and construct a monetary
|
| 2137 |
value according to the format specified by a `moneypunct<charT, Intl>`
|
| 2138 |
facet reference `mp` and the character mapping specified by a
|
|
|
|
| 2142 |
`(err|str.failbit|str.eofbit)` if no more characters are available, and
|
| 2143 |
does not change `units` or `digits`. Uses the pattern returned by
|
| 2144 |
`mp.neg_format()` to parse all values. The result is returned as an
|
| 2145 |
integral value stored in `units` or as a sequence of digits possibly
|
| 2146 |
preceded by a minus sign (as produced by `ct.widen(c)` where `c` is
|
| 2147 |
+
`’-’` or in the range from `’0’` through `’9’` (inclusive)) stored in
|
| 2148 |
`digits`.
|
| 2149 |
|
| 2150 |
[*Example 1*: The sequence `$1,056.23` in a common United States locale
|
| 2151 |
would yield, for `units`, `105623`, or, for `digits`,
|
| 2152 |
`"105623"`. — *end example*]
|
|
|
|
| 2161 |
element in the format pattern, no white space is consumed. Otherwise,
|
| 2162 |
where `money_base::space` appears in any of the initial elements of the
|
| 2163 |
format pattern, at least one white space character is required. Where
|
| 2164 |
`money_base::none` appears in any of the initial elements of the format
|
| 2165 |
pattern, white space is allowed but not required. If
|
| 2166 |
+
`(str.flags() & str.showbase)` is `false`, the currency symbol is
|
| 2167 |
+
optional and is consumed only if other characters are needed to complete
|
| 2168 |
+
the format; otherwise, the currency symbol is required.
|
| 2169 |
|
| 2170 |
If the first character (if any) in the string `pos` returned by
|
| 2171 |
`mp.positive_sign()` or the string `neg` returned by
|
| 2172 |
`mp.negative_sign()` is recognized in the position indicated by `sign`
|
| 2173 |
in the format pattern, it is consumed and any remaining characters in
|
|
|
|
| 2239 |
const string_type& digits) const;
|
| 2240 |
};
|
| 2241 |
}
|
| 2242 |
```
|
| 2243 |
|
| 2244 |
+
##### Members <a id="locale.money.put.members">[[locale.money.put.members]]</a>
|
| 2245 |
|
| 2246 |
``` cpp
|
| 2247 |
+
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, long double quant) const;
|
| 2248 |
+
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, const string_type& quant) const;
|
|
|
|
|
|
|
| 2249 |
```
|
| 2250 |
|
| 2251 |
*Returns:* `do_put(s, intl, f, loc, quant)`.
|
| 2252 |
|
| 2253 |
+
##### Virtual functions <a id="locale.money.put.virtuals">[[locale.money.put.virtuals]]</a>
|
| 2254 |
|
| 2255 |
``` cpp
|
| 2256 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
| 2257 |
char_type fill, long double units) const;
|
| 2258 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
|
|
| 2346 |
```
|
| 2347 |
|
| 2348 |
The `moneypunct<>` facet defines monetary formatting parameters used by
|
| 2349 |
`money_get<>` and `money_put<>`. A monetary format is a sequence of four
|
| 2350 |
components, specified by a `pattern` value `p`, such that the `part`
|
| 2351 |
+
value `static_cast<part>(p.field[i])` determines the `i`ᵗʰ component of
|
| 2352 |
the format[^21] In the `field` member of a `pattern` object, each value
|
| 2353 |
`symbol`, `sign`, `value`, and either `space` or `none` appears exactly
|
| 2354 |
once. The value `none`, if present, is not first; the value `space`, if
|
| 2355 |
present, is neither first nor last.
|
| 2356 |
|
|
|
|
| 2366 |
after all other format components. Where `value` appears, the absolute
|
| 2367 |
numeric monetary value is required.
|
| 2368 |
|
| 2369 |
The format of the numeric monetary value is a decimal number:
|
| 2370 |
|
| 2371 |
+
``` bnf
|
| 2372 |
+
value:
|
| 2373 |
+
units fractionalₒₚₜ
|
| 2374 |
decimal-point digits
|
| 2375 |
```
|
| 2376 |
|
| 2377 |
+
``` bnf
|
| 2378 |
+
fractional:
|
| 2379 |
+
decimal-point digitsₒₚₜ
|
| 2380 |
+
```
|
| 2381 |
+
|
| 2382 |
if `frac_digits()` returns a positive value, or
|
| 2383 |
|
| 2384 |
+
``` bnf
|
| 2385 |
+
value:
|
| 2386 |
+
units
|
| 2387 |
```
|
| 2388 |
|
| 2389 |
+
otherwise. The symbol indicates the character returned by
|
| 2390 |
+
`decimal_point()`. The other symbols are defined as follows:
|
| 2391 |
|
| 2392 |
+
``` bnf
|
| 2393 |
+
units:
|
| 2394 |
+
digits
|
| 2395 |
+
digits thousands-sep units
|
| 2396 |
```
|
| 2397 |
|
| 2398 |
+
``` bnf
|
| 2399 |
+
digits:
|
| 2400 |
+
adigit digitsₒₚₜ
|
| 2401 |
+
```
|
| 2402 |
+
|
| 2403 |
+
In the syntax specification, the symbol is any of the values
|
| 2404 |
+
`ct.widen(c)` for `c` in the range `'0'` through `'9'` (inclusive) and
|
| 2405 |
`ct` is a reference of type `const ctype<charT>&` obtained as described
|
| 2406 |
+
in the definitions of `money_get<>` and `money_put<>`. The symbol is the
|
| 2407 |
+
character returned by `thousands_sep()`. The space character used is the
|
| 2408 |
+
value `ct.widen(' ')`. White space characters are those characters `c`
|
| 2409 |
+
for which `ci.is(space, c)` returns `true`. The number of digits
|
| 2410 |
+
required after the decimal point (if any) is exactly the value returned
|
| 2411 |
+
by `frac_digits()`.
|
| 2412 |
|
| 2413 |
The placement of thousands-separator characters (if any) is determined
|
| 2414 |
by the value returned by `grouping()`, defined identically as the member
|
| 2415 |
`numpunct<>::do_grouping()`.
|
| 2416 |
|
| 2417 |
+
##### Members <a id="locale.moneypunct.members">[[locale.moneypunct.members]]</a>
|
| 2418 |
|
| 2419 |
``` cpp
|
| 2420 |
charT decimal_point() const;
|
| 2421 |
charT thousands_sep() const;
|
| 2422 |
string grouping() const;
|
|
|
|
| 2429 |
```
|
| 2430 |
|
| 2431 |
Each of these functions `F` returns the result of calling the
|
| 2432 |
corresponding virtual member function `do_F()`.
|
| 2433 |
|
| 2434 |
+
##### Virtual functions <a id="locale.moneypunct.virtuals">[[locale.moneypunct.virtuals]]</a>
|
| 2435 |
|
| 2436 |
``` cpp
|
| 2437 |
charT do_decimal_point() const;
|
| 2438 |
```
|
| 2439 |
|
|
|
|
| 2456 |
|
| 2457 |
``` cpp
|
| 2458 |
string_type do_curr_symbol() const;
|
| 2459 |
```
|
| 2460 |
|
| 2461 |
+
*Returns:* A string to use as the currency identifier symbol.
|
| 2462 |
+
|
| 2463 |
+
[*Note 1*: For specializations where the second template parameter is
|
| 2464 |
+
`true`, this is typically four characters long: a three-letter code as
|
| 2465 |
+
specified by ISO 4217 followed by a space. — *end note*]
|
| 2466 |
|
| 2467 |
``` cpp
|
| 2468 |
string_type do_positive_sign() const;
|
| 2469 |
string_type do_negative_sign() const;
|
| 2470 |
```
|
| 2471 |
|
| 2472 |
*Returns:* `do_positive_sign()` returns the string to use to indicate a
|
| 2473 |
+
positive monetary value;[^25] `do_negative_sign()` returns the string to
|
| 2474 |
use to indicate a negative value.
|
| 2475 |
|
| 2476 |
``` cpp
|
| 2477 |
int do_frac_digits() const;
|
| 2478 |
```
|
| 2479 |
|
| 2480 |
*Returns:* The number of digits after the decimal radix separator, if
|
| 2481 |
+
any.[^26]
|
| 2482 |
|
| 2483 |
``` cpp
|
| 2484 |
pattern do_pos_format() const;
|
| 2485 |
pattern do_neg_format() const;
|
| 2486 |
```
|
| 2487 |
|
| 2488 |
*Returns:* The specializations required in
|
| 2489 |
+
[[locale.spec]][[locale.category]], namely
|
| 2490 |
+
|
| 2491 |
+
- `moneypunct<char>`,
|
| 2492 |
+
- `moneypunct<wchar_t>`,
|
| 2493 |
+
- `moneypunct<char, true>`, and
|
| 2494 |
+
- `moneypunct<wchar_t, true>`,
|
| 2495 |
+
|
| 2496 |
+
return an object of type `pattern` initialized to
|
| 2497 |
+
`{ symbol, sign, none, value }`.[^27]
|
| 2498 |
|
| 2499 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 2500 |
|
| 2501 |
``` cpp
|
| 2502 |
namespace std {
|
|
|
|
| 2506 |
using pattern = money_base::pattern;
|
| 2507 |
using string_type = basic_string<charT>;
|
| 2508 |
|
| 2509 |
explicit moneypunct_byname(const char*, size_t refs = 0);
|
| 2510 |
explicit moneypunct_byname(const string&, size_t refs = 0);
|
| 2511 |
+
|
| 2512 |
protected:
|
| 2513 |
~moneypunct_byname();
|
| 2514 |
};
|
| 2515 |
}
|
| 2516 |
```
|
|
|
|
| 2535 |
using char_type = charT;
|
| 2536 |
using string_type = basic_string<charT>;
|
| 2537 |
|
| 2538 |
explicit messages(size_t refs = 0);
|
| 2539 |
|
| 2540 |
+
catalog open(const string& fn, const locale&) const;
|
| 2541 |
string_type get(catalog c, int set, int msgid,
|
| 2542 |
const string_type& dfault) const;
|
| 2543 |
void close(catalog c) const;
|
| 2544 |
|
| 2545 |
static locale::id id;
|
| 2546 |
|
| 2547 |
protected:
|
| 2548 |
~messages();
|
| 2549 |
+
virtual catalog do_open(const string&, const locale&) const;
|
| 2550 |
virtual string_type do_get(catalog, int set, int msgid,
|
| 2551 |
const string_type& dfault) const;
|
| 2552 |
virtual void do_close(catalog) const;
|
| 2553 |
};
|
| 2554 |
}
|
| 2555 |
```
|
| 2556 |
|
| 2557 |
Values of type `messages_base::catalog` usable as arguments to members
|
| 2558 |
`get` and `close` can be obtained only by calling member `open`.
|
| 2559 |
|
| 2560 |
+
##### Members <a id="locale.messages.members">[[locale.messages.members]]</a>
|
| 2561 |
|
| 2562 |
``` cpp
|
| 2563 |
+
catalog open(const string& name, const locale& loc) const;
|
| 2564 |
```
|
| 2565 |
|
| 2566 |
*Returns:* `do_open(name, loc)`.
|
| 2567 |
|
| 2568 |
``` cpp
|
|
|
|
| 2575 |
void close(catalog cat) const;
|
| 2576 |
```
|
| 2577 |
|
| 2578 |
*Effects:* Calls `do_close(cat)`.
|
| 2579 |
|
| 2580 |
+
##### Virtual functions <a id="locale.messages.virtuals">[[locale.messages.virtuals]]</a>
|
| 2581 |
|
| 2582 |
``` cpp
|
| 2583 |
+
catalog do_open(const string& name, const locale& loc) const;
|
| 2584 |
```
|
| 2585 |
|
| 2586 |
*Returns:* A value that may be passed to `get()` to retrieve a message
|
| 2587 |
from the message catalog identified by the string `name` according to an
|
| 2588 |
*implementation-defined* mapping. The result can be used until it is
|
|
|
|
| 2595 |
|
| 2596 |
``` cpp
|
| 2597 |
string_type do_get(catalog cat, int set, int msgid, const string_type& dfault) const;
|
| 2598 |
```
|
| 2599 |
|
| 2600 |
+
*Preconditions:* `cat` is a catalog obtained from `open()` and not yet
|
| 2601 |
closed.
|
| 2602 |
|
| 2603 |
*Returns:* A message identified by arguments `set`, `msgid`, and
|
| 2604 |
`dfault`, according to an *implementation-defined* mapping. If no such
|
| 2605 |
message can be found, returns `dfault`.
|
| 2606 |
|
| 2607 |
``` cpp
|
| 2608 |
void do_close(catalog cat) const;
|
| 2609 |
```
|
| 2610 |
|
| 2611 |
+
*Preconditions:* `cat` is a catalog obtained from `open()` and not yet
|
| 2612 |
closed.
|
| 2613 |
|
| 2614 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 2615 |
|
| 2616 |
*Remarks:* The limit on such resources, if any, is
|
|
|
|
| 2626 |
using catalog = messages_base::catalog;
|
| 2627 |
using string_type = basic_string<charT>;
|
| 2628 |
|
| 2629 |
explicit messages_byname(const char*, size_t refs = 0);
|
| 2630 |
explicit messages_byname(const string&, size_t refs = 0);
|
| 2631 |
+
|
| 2632 |
protected:
|
| 2633 |
~messages_byname();
|
| 2634 |
};
|
| 2635 |
}
|
| 2636 |
```
|
| 2637 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|