- tmp/tmp0qang188/{from.md → to.md} +362 -346
tmp/tmp0qang188/{from.md → to.md}
RENAMED
|
@@ -23,11 +23,11 @@ another virtual function.
|
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
namespace std {
|
| 26 |
class ctype_base {
|
| 27 |
public:
|
| 28 |
-
|
| 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;
|
|
@@ -51,49 +51,42 @@ The type `mask` is a bitmask type ([[bitmask.types]]).
|
|
| 51 |
``` cpp
|
| 52 |
namespace std {
|
| 53 |
template <class charT>
|
| 54 |
class ctype : public locale::facet, public ctype_base {
|
| 55 |
public:
|
| 56 |
-
|
| 57 |
|
| 58 |
explicit ctype(size_t refs = 0);
|
| 59 |
|
| 60 |
bool is(mask m, charT c) const;
|
| 61 |
const charT* is(const charT* low, const charT* high, mask* vec) const;
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
const charT* scan_not(mask m,
|
| 65 |
-
const charT* low, const charT* high) const;
|
| 66 |
charT toupper(charT c) const;
|
| 67 |
const charT* toupper(charT* low, const charT* high) const;
|
| 68 |
charT tolower(charT c) const;
|
| 69 |
const charT* tolower(charT* low, const charT* high) const;
|
| 70 |
|
| 71 |
charT widen(char c) const;
|
| 72 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 73 |
char narrow(charT c, char dfault) const;
|
| 74 |
-
|
| 75 |
-
char* to) const;
|
| 76 |
|
| 77 |
static locale::id id;
|
| 78 |
|
| 79 |
protected:
|
| 80 |
~ctype();
|
| 81 |
virtual bool do_is(mask m, charT c) const;
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
const charT* low, const charT* high) const;
|
| 86 |
-
virtual const charT* do_scan_not(mask m,
|
| 87 |
-
const charT* low, const charT* high) const;
|
| 88 |
virtual charT do_toupper(charT) const;
|
| 89 |
virtual const charT* do_toupper(charT* low, const charT* high) const;
|
| 90 |
virtual charT do_tolower(charT) const;
|
| 91 |
virtual const charT* do_tolower(charT* low, const charT* high) const;
|
| 92 |
virtual charT do_widen(char) const;
|
| 93 |
-
|
| 94 |
-
charT* dest) const;
|
| 95 |
virtual char do_narrow(charT, char dfault) const;
|
| 96 |
virtual const charT* do_narrow(const charT* low, const charT* high,
|
| 97 |
char dfault, char* dest) const;
|
| 98 |
};
|
| 99 |
}
|
|
@@ -114,54 +107,54 @@ appropriate to the implementation’s native character set.
|
|
| 114 |
bool is(mask m, charT c) const;
|
| 115 |
const charT* is(const charT* low, const charT* high,
|
| 116 |
mask* vec) const;
|
| 117 |
```
|
| 118 |
|
| 119 |
-
*Returns:* `do_is(m,c)` or `do_is(low,high,vec)`
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
const charT* scan_is(mask m,
|
| 123 |
const charT* low, const charT* high) const;
|
| 124 |
```
|
| 125 |
|
| 126 |
-
*Returns:* `do_scan_is(m,low,high)`
|
| 127 |
|
| 128 |
``` cpp
|
| 129 |
const charT* scan_not(mask m,
|
| 130 |
const charT* low, const charT* high) const;
|
| 131 |
```
|
| 132 |
|
| 133 |
-
*Returns:* `do_scan_not(m,low,high)`
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
charT toupper(charT) const;
|
| 137 |
const charT* toupper(charT* low, const charT* high) const;
|
| 138 |
```
|
| 139 |
|
| 140 |
-
*Returns:* `do_toupper(c)` or `do_toupper(low,high)`
|
| 141 |
|
| 142 |
``` cpp
|
| 143 |
charT tolower(charT c) const;
|
| 144 |
const charT* tolower(charT* low, const charT* high) const;
|
| 145 |
```
|
| 146 |
|
| 147 |
-
*Returns:* `do_tolower(c)` or `do_tolower(low,high)`
|
| 148 |
|
| 149 |
``` cpp
|
| 150 |
charT widen(char c) const;
|
| 151 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 152 |
```
|
| 153 |
|
| 154 |
-
*Returns:* `do_widen(c)` or `do_widen(low,high,to)`
|
| 155 |
|
| 156 |
``` cpp
|
| 157 |
char narrow(charT c, char dfault) const;
|
| 158 |
-
const charT* narrow(const charT* low, const charT*, char dfault,
|
| 159 |
char* to) const;
|
| 160 |
```
|
| 161 |
|
| 162 |
-
*Returns:* `do_narrow(c,dfault)` or `do_narrow(low,high,dfault,to)`
|
| 163 |
|
| 164 |
##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
|
| 165 |
|
| 166 |
``` cpp
|
| 167 |
bool do_is(mask m, charT c) const;
|
|
@@ -170,30 +163,29 @@ const charT* do_is(const charT* low, const charT* high,
|
|
| 170 |
```
|
| 171 |
|
| 172 |
*Effects:* Classifies a character or sequence of characters. For each
|
| 173 |
argument character, identifies a value `M` of type `ctype_base::mask`.
|
| 174 |
The second form identifies a value `M` of type `ctype_base::mask` for
|
| 175 |
-
each `*p` where `(low<=p && p<high)`, and places it into
|
|
|
|
| 176 |
|
| 177 |
*Returns:* The first form returns the result of the expression
|
| 178 |
`(M & m) != 0`; i.e., `true` if the character has the characteristics
|
| 179 |
specified. The second form returns `high`.
|
| 180 |
|
| 181 |
``` cpp
|
| 182 |
-
const charT* do_scan_is(mask m,
|
| 183 |
-
const charT* low, const charT* high) const;
|
| 184 |
```
|
| 185 |
|
| 186 |
*Effects:* Locates a character in a buffer that conforms to a
|
| 187 |
classification `m`.
|
| 188 |
|
| 189 |
-
*Returns:* The smallest pointer `p` in the range
|
| 190 |
-
`is(m,*p)` would return `true`; otherwise, returns `high`.
|
| 191 |
|
| 192 |
``` cpp
|
| 193 |
-
const charT* do_scan_not(mask m,
|
| 194 |
-
const charT* low, const charT* high) const;
|
| 195 |
```
|
| 196 |
|
| 197 |
*Effects:* Locates a character in a buffer that fails to conform to a
|
| 198 |
classification `m`.
|
| 199 |
|
|
@@ -233,16 +225,16 @@ const char* do_widen(const char* low, const char* high,
|
|
| 233 |
charT* dest) const;
|
| 234 |
```
|
| 235 |
|
| 236 |
*Effects:* Applies the simplest reasonable transformation from a `char`
|
| 237 |
value or sequence of `char` values to the corresponding `charT` value or
|
| 238 |
-
values.[^
|
| 239 |
required are those in the basic source character set ([[lex.charset]]).
|
| 240 |
|
| 241 |
For any named `ctype` category with a `ctype <charT>` facet `ctc` and
|
| 242 |
valid `ctype_base::mask` value `M`,
|
| 243 |
-
`(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^
|
| 244 |
|
| 245 |
The second form transforms each character `*p` in the range \[`low`,
|
| 246 |
`high`), placing the result in `dest[p - low]`.
|
| 247 |
|
| 248 |
*Returns:* The first form returns the transformed value. The second form
|
|
@@ -287,11 +279,11 @@ no mapping is readily available. The second form returns `high`.
|
|
| 287 |
``` cpp
|
| 288 |
namespace std {
|
| 289 |
template <class charT>
|
| 290 |
class ctype_byname : public ctype<charT> {
|
| 291 |
public:
|
| 292 |
-
|
| 293 |
explicit ctype_byname(const char*, size_t refs = 0);
|
| 294 |
explicit ctype_byname(const string&, size_t refs = 0);
|
| 295 |
protected:
|
| 296 |
~ctype_byname();
|
| 297 |
};
|
|
@@ -300,14 +292,14 @@ namespace std {
|
|
| 300 |
|
| 301 |
#### `ctype` specializations <a id="facet.ctype.special">[[facet.ctype.special]]</a>
|
| 302 |
|
| 303 |
``` cpp
|
| 304 |
namespace std {
|
| 305 |
-
template <>
|
| 306 |
-
: public locale::facet, public ctype_base {
|
| 307 |
public:
|
| 308 |
-
|
| 309 |
|
| 310 |
explicit ctype(const mask* tab = 0, bool del = false,
|
| 311 |
size_t refs = 0);
|
| 312 |
|
| 313 |
bool is(mask m, char c) const;
|
|
@@ -352,21 +344,21 @@ namespace std {
|
|
| 352 |
};
|
| 353 |
}
|
| 354 |
```
|
| 355 |
|
| 356 |
A specialization `ctype<char>` is provided so that the member functions
|
| 357 |
-
on type `char` can be implemented `inline`.[^
|
| 358 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 359 |
|
| 360 |
##### `ctype<char>` destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
|
| 361 |
|
| 362 |
``` cpp
|
| 363 |
~ctype();
|
| 364 |
```
|
| 365 |
|
| 366 |
*Effects:* If the constructor’s first argument was nonzero, and its
|
| 367 |
-
second argument was true, does `delete [] table()`.
|
| 368 |
|
| 369 |
##### `ctype<char>` members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
|
| 370 |
|
| 371 |
In the following member descriptions, for `unsigned char` values `v`
|
| 372 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
|
@@ -376,22 +368,23 @@ implementation-specific value (possibly different for each such value
|
|
| 376 |
``` cpp
|
| 377 |
explicit ctype(const mask* tbl = 0, bool del = false,
|
| 378 |
size_t refs = 0);
|
| 379 |
```
|
| 380 |
|
| 381 |
-
`tbl` either 0 or an array of at least `table_size`
|
|
|
|
| 382 |
|
| 383 |
*Effects:* Passes its `refs` argument to its base class constructor.
|
| 384 |
|
| 385 |
``` cpp
|
| 386 |
bool is(mask m, char c) const;
|
| 387 |
const char* is(const char* low, const char* high,
|
| 388 |
mask* vec) const;
|
| 389 |
```
|
| 390 |
|
| 391 |
*Effects:* The second form, for all `*p` in the range \[`low`, `high`),
|
| 392 |
-
assigns into `vec[p-low]` the value `table()[
|
| 393 |
|
| 394 |
*Returns:* The first form returns `table()[(unsigned char)c] & m`; the
|
| 395 |
second form returns `high`.
|
| 396 |
|
| 397 |
``` cpp
|
|
@@ -453,22 +446,22 @@ respectively.
|
|
| 453 |
|
| 454 |
``` cpp
|
| 455 |
const mask* table() const noexcept;
|
| 456 |
```
|
| 457 |
|
| 458 |
-
*Returns:* The first constructor argument, if it was
|
| 459 |
`classic_table()`.
|
| 460 |
|
| 461 |
##### `ctype<char>` static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
|
| 462 |
|
| 463 |
``` cpp
|
| 464 |
static const mask* classic_table() noexcept;
|
| 465 |
```
|
| 466 |
|
| 467 |
*Returns:* A pointer to the initial element of an array of size
|
| 468 |
`table_size` which represents the classifications of characters in the
|
| 469 |
-
"C" locale.
|
| 470 |
|
| 471 |
##### `ctype<char>` virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
|
| 472 |
|
| 473 |
``` cpp
|
| 474 |
char do_toupper(char) const;
|
|
@@ -499,46 +492,54 @@ namespace std {
|
|
| 499 |
};
|
| 500 |
|
| 501 |
template <class internT, class externT, class stateT>
|
| 502 |
class codecvt : public locale::facet, public codecvt_base {
|
| 503 |
public:
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
|
| 508 |
explicit codecvt(size_t refs = 0);
|
| 509 |
|
| 510 |
-
|
|
|
|
| 511 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 512 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 513 |
-
|
|
|
|
|
|
|
| 514 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 515 |
-
|
|
|
|
|
|
|
| 516 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 517 |
internT* to, internT* to_end, internT*& to_next) const;
|
|
|
|
| 518 |
int encoding() const noexcept;
|
| 519 |
bool always_noconv() const noexcept;
|
| 520 |
-
|
| 521 |
-
size_t max) const;
|
| 522 |
int max_length() const noexcept;
|
| 523 |
|
| 524 |
static locale::id id;
|
| 525 |
|
| 526 |
protected:
|
| 527 |
~codecvt();
|
| 528 |
-
|
|
|
|
| 529 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 530 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 531 |
-
|
|
|
|
| 532 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 533 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 534 |
-
|
|
|
|
| 535 |
externT* to, externT* to_end, externT*& to_next) const;
|
|
|
|
| 536 |
virtual int do_encoding() const noexcept;
|
| 537 |
virtual bool do_always_noconv() const noexcept;
|
| 538 |
-
|
| 539 |
-
const externT* end, size_t max) const;
|
| 540 |
virtual int do_max_length() const noexcept;
|
| 541 |
};
|
| 542 |
}
|
| 543 |
```
|
| 544 |
|
|
@@ -552,103 +553,105 @@ mapped between.
|
|
| 552 |
|
| 553 |
The specializations required in Table
|
| 554 |
[[tab:localization.category.facets]] ([[locale.category]]) convert the
|
| 555 |
implementation-defined native character set.
|
| 556 |
`codecvt<char, char, mbstate_t>` implements a degenerate conversion; it
|
| 557 |
-
does not convert at all. The specialization
|
| 558 |
-
`char, mbstate_t>` converts between the UTF-16 and
|
| 559 |
-
and the specialization `codecvt`
|
| 560 |
-
between the UTF-32 and UTF-8
|
| 561 |
-
`codecvt<wchar_t,char,mbstate_t>` converts between the
|
| 562 |
-
sets for narrow and wide characters. Specializations on
|
| 563 |
-
perform conversion between encodings known to the library
|
| 564 |
-
Other encodings can be converted by specializing on a
|
| 565 |
-
`stateT` type. Objects of type `stateT` can contain any
|
| 566 |
-
useful to communicate to or from the specialized `do_in`
|
| 567 |
-
members.
|
| 568 |
|
| 569 |
##### `codecvt` members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
|
| 570 |
|
| 571 |
``` cpp
|
| 572 |
-
result out(
|
|
|
|
| 573 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 574 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 575 |
```
|
| 576 |
|
| 577 |
*Returns:*
|
| 578 |
-
`do_out(state, from, from_end, from_next, to, to_end, to_next)`
|
| 579 |
|
| 580 |
``` cpp
|
| 581 |
-
result unshift(stateT& state,
|
| 582 |
-
externT* to, externT* to_end, externT*& to_next) const;
|
| 583 |
```
|
| 584 |
|
| 585 |
-
*Returns:* `do_unshift(state, to, to_end, to_next)`
|
| 586 |
|
| 587 |
``` cpp
|
| 588 |
-
result in(
|
|
|
|
| 589 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 590 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 591 |
```
|
| 592 |
|
| 593 |
*Returns:*
|
| 594 |
-
`do_in(state, from, from_end, from_next, to, to_end, to_next)`
|
| 595 |
|
| 596 |
``` cpp
|
| 597 |
int encoding() const noexcept;
|
| 598 |
```
|
| 599 |
|
| 600 |
-
*Returns:* `do_encoding()`
|
| 601 |
|
| 602 |
``` cpp
|
| 603 |
bool always_noconv() const noexcept;
|
| 604 |
```
|
| 605 |
|
| 606 |
-
*Returns:* `do_always_noconv()`
|
| 607 |
|
| 608 |
``` cpp
|
| 609 |
-
int length(stateT& state, const externT* from, const externT* from_end,
|
| 610 |
-
size_t max) const;
|
| 611 |
```
|
| 612 |
|
| 613 |
-
*Returns:* `do_length(state, from,from_end,max)`
|
| 614 |
|
| 615 |
``` cpp
|
| 616 |
int max_length() const noexcept;
|
| 617 |
```
|
| 618 |
|
| 619 |
-
*Returns:* `do_max_length()`
|
| 620 |
|
| 621 |
##### `codecvt` virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
|
| 622 |
|
| 623 |
``` cpp
|
| 624 |
-
result do_out(
|
|
|
|
| 625 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 626 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 627 |
|
| 628 |
-
result do_in(
|
|
|
|
| 629 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 630 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 631 |
```
|
| 632 |
|
| 633 |
-
*
|
| 634 |
`true`; `state` initialized, if at the beginning of a sequence, or else
|
| 635 |
equal to the result of converting the preceding characters in the
|
| 636 |
sequence.
|
| 637 |
|
| 638 |
-
*Effects:* Translates characters in the source range
|
| 639 |
-
placing the results in sequential positions starting at
|
| 640 |
-
`to`. Converts no more than `(from_end-from)` source
|
| 641 |
-
stores no more than `(to_end-to)` destination elements.
|
| 642 |
|
| 643 |
Stops if it encounters a character it cannot convert. It always leaves
|
| 644 |
the `from_next` and `to_next` pointers pointing one beyond the last
|
| 645 |
element successfully converted. If returns `noconv`, `internT` and
|
| 646 |
`externT` are the same type and the converted sequence is identical to
|
| 647 |
-
the input sequence
|
| 648 |
-
the value of `state` is unchanged, and there are no changes to the
|
| 649 |
-
values in
|
| 650 |
|
| 651 |
A `codecvt` facet that is used by `basic_filebuf` ([[file.streams]])
|
| 652 |
shall have the property that if
|
| 653 |
|
| 654 |
``` cpp
|
|
@@ -671,105 +674,107 @@ would return `ok`, where `to != to_end`, then
|
|
| 671 |
|
| 672 |
``` cpp
|
| 673 |
do_in(state, from, from_end, from_next, to, to + 1, to_next)
|
| 674 |
```
|
| 675 |
|
| 676 |
-
shall also return `ok`.[^
|
| 677 |
-
return `ok` or `partial` and set `from_next == from` and
|
| 678 |
-
`to_next != to`.
|
| 679 |
|
| 680 |
-
*
|
| 681 |
-
|
| 682 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 683 |
|
| 684 |
*Returns:* An enumeration value, as summarized in
|
| 685 |
Table [[tab:localization.convert.result.values.out.in]].
|
| 686 |
|
| 687 |
**Table: `do_in/do_out` result values** <a id="tab:localization.convert.result.values.out.in">[tab:localization.convert.result.values.out.in]</a>
|
| 688 |
|
| 689 |
| Value | Meaning |
|
| 690 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 691 |
| `ok` | completed the conversion |
|
| 692 |
| `partial` | not all source characters converted |
|
| 693 |
-
| `error` | encountered a character in
|
| 694 |
| `noconv` | `internT` and `externT` are the same type, and input sequence is identical to converted sequence |
|
| 695 |
|
| 696 |
|
| 697 |
-
A return value of `partial`, if `(from_next==from_end)`, indicates
|
| 698 |
-
either the destination sequence has not absorbed all the available
|
| 699 |
destination elements, or that additional source elements are needed
|
| 700 |
before another destination element can be produced.
|
| 701 |
|
| 702 |
``` cpp
|
| 703 |
-
result do_unshift(stateT& state,
|
| 704 |
-
externT* to, externT* to_end, externT*& to_next) const;
|
| 705 |
```
|
| 706 |
|
| 707 |
-
*Requires:* `(to <= to_end)` well defined and true; state initialized,
|
| 708 |
if at the beginning of a sequence, or else equal to the result of
|
| 709 |
converting the preceding characters in the sequence.
|
| 710 |
|
| 711 |
*Effects:* Places characters starting at `to` that should be appended to
|
| 712 |
-
terminate a sequence when the current `stateT` is given by `state`.[^
|
| 713 |
Stores no more than `(to_end - to)` destination elements, and leaves the
|
| 714 |
`to_next` pointer pointing one beyond the last element successfully
|
| 715 |
stored.
|
| 716 |
|
| 717 |
*Returns:* An enumeration value, as summarized in
|
| 718 |
Table [[tab:localization.convert.result.values.unshift]].
|
| 719 |
|
| 720 |
**Table: `do_unshift` result values** <a id="tab:localization.convert.result.values.unshift">[tab:localization.convert.result.values.unshift]</a>
|
| 721 |
|
| 722 |
| Value | Meaning |
|
| 723 |
-
| --------- | ------------------------------------------------------------------------------------------------------------------ |
|
| 724 |
| `ok` | completed the sequence |
|
| 725 |
| `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
|
| 726 |
| `error` | an unspecified error has occurred |
|
| 727 |
| `noconv` | no termination is needed for this `state_type` |
|
| 728 |
|
| 729 |
``` cpp
|
| 730 |
int do_encoding() const noexcept;
|
| 731 |
```
|
| 732 |
|
| 733 |
-
*Returns:* -1 if the encoding of the `externT` sequence is
|
| 734 |
state-dependent; else the constant number of `externT` characters needed
|
| 735 |
-
to produce an internal character; or 0 if this number is not a
|
| 736 |
-
constant.[^
|
| 737 |
|
| 738 |
``` cpp
|
| 739 |
bool do_always_noconv() const noexcept;
|
| 740 |
```
|
| 741 |
|
| 742 |
*Returns:* `true` if `do_in()` and `do_out()` return `noconv` for all
|
| 743 |
valid argument values. `codecvt<char, char, mbstate_t>` returns `true`.
|
| 744 |
|
| 745 |
``` cpp
|
| 746 |
-
int do_length(stateT& state, const externT* from, const externT* from_end,
|
| 747 |
-
size_t max) const;
|
| 748 |
```
|
| 749 |
|
| 750 |
-
*
|
| 751 |
initialized, if at the beginning of a sequence, or else equal to the
|
| 752 |
result of converting the preceding characters in the sequence.
|
| 753 |
|
| 754 |
*Effects:* The effect on the `state` argument is “as if” it called
|
| 755 |
`do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
|
| 756 |
to a buffer of at least `max` elements.
|
| 757 |
|
| 758 |
*Returns:* `(from_next-from)` where `from_next` is the largest value in
|
| 759 |
-
the range
|
| 760 |
range \[`from`, `from_next`) represents `max` or fewer valid complete
|
| 761 |
characters of type `internT`. The specialization
|
| 762 |
`codecvt<char, char, mbstate_t>`, returns the lesser of `max` and
|
| 763 |
`(from_end-from)`.
|
| 764 |
|
| 765 |
``` cpp
|
| 766 |
int do_max_length() const noexcept;
|
| 767 |
```
|
| 768 |
|
| 769 |
*Returns:* The maximum value that `do_length(state, from, from_end, 1)`
|
| 770 |
-
can return for any valid range
|
| 771 |
`state`. The specialization
|
| 772 |
`codecvt<char, char, mbstate_t>::do_max_length()` returns 1.
|
| 773 |
|
| 774 |
#### Class template `codecvt_byname` <a id="locale.codecvt.byname">[[locale.codecvt.byname]]</a>
|
| 775 |
|
|
@@ -789,11 +794,11 @@ namespace std {
|
|
| 789 |
### The numeric category <a id="category.numeric">[[category.numeric]]</a>
|
| 790 |
|
| 791 |
The classes `num_get<>` and `num_put<>` handle numeric formatting and
|
| 792 |
parsing. Virtual functions are provided for several numeric types.
|
| 793 |
Implementations may (but are not required to) delegate extraction of
|
| 794 |
-
smaller types to extractors for larger types.[^
|
| 795 |
|
| 796 |
All specifications of member functions for `num_put` and `num_get` in
|
| 797 |
the subclauses of [[category.numeric]] only apply to the
|
| 798 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 799 |
and [[tab:localization.required.specializations]] (
|
|
@@ -814,12 +819,12 @@ values ([[istream.formatted.reqmts]], [[ostream.formatted.reqmts]]).
|
|
| 814 |
``` cpp
|
| 815 |
namespace std {
|
| 816 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 817 |
class num_get : public locale::facet {
|
| 818 |
public:
|
| 819 |
-
|
| 820 |
-
|
| 821 |
|
| 822 |
explicit num_get(size_t refs = 0);
|
| 823 |
|
| 824 |
iter_type get(iter_type in, iter_type end, ios_base&,
|
| 825 |
ios_base::iostate& err, bool& v) const;
|
|
@@ -991,12 +996,12 @@ as indicated in Table [[tab:localization.length.modifier.in]].
|
|
| 991 |
| `double` | `l` |
|
| 992 |
| `long double` | `L` |
|
| 993 |
|
| 994 |
- **Stage 2:**
|
| 995 |
|
| 996 |
-
If `in==end` then stage 2 terminates. Otherwise a `charT` is taken
|
| 997 |
-
`in` and local variables are initialized as if by
|
| 998 |
|
| 999 |
``` cpp
|
| 1000 |
char_type ct = *in;
|
| 1001 |
char c = src[find(atoms, atoms + sizeof(src) - 1, ct) - atoms];
|
| 1002 |
if (ct == use_facet<numpunct<charT>>(loc).decimal_point())
|
|
@@ -1014,11 +1019,11 @@ char_type atoms[sizeof(src)];
|
|
| 1014 |
use_facet<ctype<charT>>(loc).widen(src, src + sizeof(src), atoms);
|
| 1015 |
```
|
| 1016 |
|
| 1017 |
for this value of `loc`.
|
| 1018 |
|
| 1019 |
-
If `discard` is true, then if `’.’` has not yet been accumulated, then
|
| 1020 |
the position of the character is remembered, but the character is
|
| 1021 |
otherwise ignored. Otherwise, if `’.’` has already been accumulated, the
|
| 1022 |
character is discarded and Stage 2 terminates. If it is not discarded,
|
| 1023 |
then a check is made to determine if `c` is allowed as the next
|
| 1024 |
character of an input field of the conversion specifier returned by
|
|
@@ -1035,54 +1040,60 @@ header `<cstdlib>`:
|
|
| 1035 |
|
| 1036 |
- For a signed integer value, the function `strtoll`.
|
| 1037 |
|
| 1038 |
- For an unsigned integer value, the function `strtoull`.
|
| 1039 |
|
| 1040 |
-
- For a
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1041 |
|
| 1042 |
The numeric value to be stored can be one of:
|
| 1043 |
|
| 1044 |
-
- zero, if the conversion function
|
| 1045 |
-
`ios_base::failbit` is assigned to `err`.
|
| 1046 |
|
| 1047 |
-
- the most positive representable value, if the field
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
|
| 1051 |
-
- the most
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
|
| 1055 |
- the converted value, otherwise.
|
| 1056 |
|
| 1057 |
-
The resultant numeric value is stored in `val`.
|
|
|
|
|
|
|
|
|
|
| 1058 |
|
| 1059 |
Digit grouping is checked. That is, the positions of discarded
|
| 1060 |
separators is examined for consistency with
|
| 1061 |
-
`use_facet<numpunct<charT>
|
| 1062 |
-
|
| 1063 |
|
| 1064 |
In any case, if stage 2 processing was terminated by the test for
|
| 1065 |
`in == end` then `err |= ios_base::eofbit` is performed.
|
| 1066 |
|
| 1067 |
``` cpp
|
| 1068 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 1069 |
ios_base::iostate& err, bool& val) const;
|
| 1070 |
```
|
| 1071 |
|
| 1072 |
-
*Effects:* If `(str
|
| 1073 |
proceeds as it would for a `long` except that if a value is being stored
|
| 1074 |
into `val`, the value is determined according to the following: If the
|
| 1075 |
-
value to be stored is 0 then `false` is stored. If the value is 1 then
|
| 1076 |
`true` is stored. Otherwise `true` is stored and `ios_base::failbit` is
|
| 1077 |
assigned to `err`.
|
| 1078 |
|
| 1079 |
Otherwise target sequences are determined “as if” by calling the members
|
| 1080 |
`falsename()` and `truename()` of the facet obtained by
|
| 1081 |
-
`use_facet<numpunct<charT>
|
| 1082 |
-
|
| 1083 |
-
|
| 1084 |
necessary to identify a unique match. The input iterator `in` is
|
| 1085 |
compared to `end` only when necessary to obtain a character. If a target
|
| 1086 |
sequence is uniquely matched, `val` is set to the corresponding value.
|
| 1087 |
Otherwise `false` is stored and `ios_base::failbit` is assigned to
|
| 1088 |
`err`.
|
|
@@ -1090,127 +1101,102 @@ Otherwise `false` is stored and `ios_base::failbit` is assigned to
|
|
| 1090 |
The `in` iterator is always left pointing one position beyond the last
|
| 1091 |
character successfully matched. If `val` is set, then `err` is set to
|
| 1092 |
`str.goodbit`; or to `str.eofbit` if, when seeking another character to
|
| 1093 |
match, it is found that `(in == end)`. If `val` is not set, then `err`
|
| 1094 |
is set to `str.failbit`; or to `(str.failbit|str.eofbit)` if the reason
|
| 1095 |
-
for the failure was that `(in == end)`.
|
| 1096 |
-
|
| 1097 |
-
|
| 1098 |
-
`
|
| 1099 |
-
|
| 1100 |
-
`
|
| 1101 |
-
|
|
|
|
|
|
|
| 1102 |
|
| 1103 |
*Returns:* `in`.
|
| 1104 |
|
| 1105 |
#### Class template `num_put` <a id="locale.nm.put">[[locale.nm.put]]</a>
|
| 1106 |
|
| 1107 |
``` cpp
|
| 1108 |
namespace std {
|
| 1109 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 1110 |
class num_put : public locale::facet {
|
| 1111 |
public:
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
|
| 1115 |
explicit num_put(size_t refs = 0);
|
| 1116 |
|
| 1117 |
iter_type put(iter_type s, ios_base& f, char_type fill, bool v) const;
|
| 1118 |
iter_type put(iter_type s, ios_base& f, char_type fill, long v) const;
|
| 1119 |
iter_type put(iter_type s, ios_base& f, char_type fill, long long v) const;
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
double v) const;
|
| 1126 |
-
iter_type put(iter_type s, ios_base& f, char_type fill,
|
| 1127 |
-
long double v) const;
|
| 1128 |
-
iter_type put(iter_type s, ios_base& f, char_type fill,
|
| 1129 |
-
const void* v) const;
|
| 1130 |
|
| 1131 |
static locale::id id;
|
| 1132 |
|
| 1133 |
protected:
|
| 1134 |
~num_put();
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 1144 |
-
unsigned long long) const;
|
| 1145 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 1146 |
-
double v) const;
|
| 1147 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 1148 |
-
long double v) const;
|
| 1149 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 1150 |
-
const void* v) const;
|
| 1151 |
};
|
| 1152 |
}
|
| 1153 |
```
|
| 1154 |
|
| 1155 |
The facet `num_put` is used to format numeric values to a character
|
| 1156 |
sequence such as an ostream.
|
| 1157 |
|
| 1158 |
##### `num_put` members <a id="facet.num.put.members">[[facet.num.put.members]]</a>
|
| 1159 |
|
| 1160 |
``` cpp
|
| 1161 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1162 |
-
|
| 1163 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1164 |
-
|
| 1165 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1166 |
-
|
| 1167 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1168 |
-
|
| 1169 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1170 |
-
unsigned long long val) const;
|
| 1171 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1172 |
-
double val) const;
|
| 1173 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1174 |
-
long double val) const;
|
| 1175 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 1176 |
-
const void* val) const;
|
| 1177 |
```
|
| 1178 |
|
| 1179 |
*Returns:* `do_put(out, str, fill, val)`.
|
| 1180 |
|
| 1181 |
##### `num_put` virtual functions <a id="facet.num.put.virtuals">[[facet.num.put.virtuals]]</a>
|
| 1182 |
|
| 1183 |
``` cpp
|
| 1184 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1185 |
-
|
| 1186 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1187 |
-
|
| 1188 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1189 |
-
|
| 1190 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1191 |
-
unsigned long long val) const;
|
| 1192 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1193 |
-
double val) const;
|
| 1194 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1195 |
-
long double val) const;
|
| 1196 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1197 |
-
const void* val) const;
|
| 1198 |
```
|
| 1199 |
|
| 1200 |
*Effects:* Writes characters to the sequence `out`, formatting `val` as
|
| 1201 |
-
desired. In the following description, a local variable initialized
|
|
|
|
| 1202 |
|
| 1203 |
``` cpp
|
| 1204 |
locale loc = str.getloc();
|
| 1205 |
```
|
| 1206 |
|
| 1207 |
The details of this operation occur in several stages:
|
| 1208 |
|
| 1209 |
-
- Stage 1: Determine a printf conversion specifier `spec` and
|
| 1210 |
-
|
| 1211 |
-
|
| 1212 |
``` cpp
|
| 1213 |
printf(spec, val)
|
| 1214 |
```
|
| 1215 |
|
| 1216 |
assuming that the current locale is the `"C"` locale.
|
|
@@ -1235,10 +1221,11 @@ fmtflags flags = str.flags() ;
|
|
| 1235 |
fmtflags basefield = (flags & (ios_base::basefield));
|
| 1236 |
fmtflags uppercase = (flags & (ios_base::uppercase));
|
| 1237 |
fmtflags floatfield = (flags & (ios_base::floatfield));
|
| 1238 |
fmtflags showpos = (flags & (ios_base::showpos));
|
| 1239 |
fmtflags showbase = (flags & (ios_base::showbase));
|
|
|
|
| 1240 |
```
|
| 1241 |
|
| 1242 |
All tables used in describing stage 1 are ordered. That is, the first
|
| 1243 |
line whose condition is true applies. A line without a condition is the
|
| 1244 |
default behavior when none of the earlier lines apply.
|
|
@@ -1296,15 +1283,15 @@ qualifiers prepended as indicated in
|
|
| 1296 |
Table [[tab:localization.numeric.conversions]].
|
| 1297 |
|
| 1298 |
**Table: Numeric conversions** <a id="tab:localization.numeric.conversions">[tab:localization.numeric.conversions]</a>
|
| 1299 |
|
| 1300 |
| Type(s) | State | `stdio` equivalent |
|
| 1301 |
-
| --------------------- | -----------
|
| 1302 |
-
| an integral type | `
|
| 1303 |
-
| | `
|
| 1304 |
-
| a floating-point type | `
|
| 1305 |
-
| | `
|
| 1306 |
|
| 1307 |
|
| 1308 |
For conversion from a floating-point type, if
|
| 1309 |
`floatfield != (ios_base::fixed | ios_base::scientific)`,
|
| 1310 |
`str.precision()` is specified as precision in the conversion
|
|
@@ -1340,11 +1327,11 @@ A local variable is initialized as
|
|
| 1340 |
|
| 1341 |
``` cpp
|
| 1342 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 1343 |
```
|
| 1344 |
|
| 1345 |
-
The location of any padding[^
|
| 1346 |
Table [[tab:localization.fill.padding]].
|
| 1347 |
|
| 1348 |
**Table: Fill padding** <a id="tab:localization.fill.padding">[tab:localization.fill.padding]</a>
|
| 1349 |
|
| 1350 |
| State | Location |
|
|
@@ -1370,12 +1357,11 @@ The sequence of `charT`’s at the end of stage 3 are output via
|
|
| 1370 |
``` cpp
|
| 1371 |
*out++ = c
|
| 1372 |
```
|
| 1373 |
|
| 1374 |
``` cpp
|
| 1375 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 1376 |
-
bool val) const;
|
| 1377 |
```
|
| 1378 |
|
| 1379 |
*Returns:* If `(str.flags() & ios_base::boolalpha) == 0` returns
|
| 1380 |
`do_put(out, str, fill,`
|
| 1381 |
`(int)val)`, otherwise obtains a string `s` as if by
|
|
@@ -1396,12 +1382,12 @@ and returns `out`.
|
|
| 1396 |
``` cpp
|
| 1397 |
namespace std {
|
| 1398 |
template <class charT>
|
| 1399 |
class numpunct : public locale::facet {
|
| 1400 |
public:
|
| 1401 |
-
|
| 1402 |
-
|
| 1403 |
|
| 1404 |
explicit numpunct(size_t refs = 0);
|
| 1405 |
|
| 1406 |
char_type decimal_point() const;
|
| 1407 |
char_type thousands_sep() const;
|
|
@@ -1460,23 +1446,23 @@ thousands-separators, no grouping constraint is applied.
|
|
| 1460 |
|
| 1461 |
``` cpp
|
| 1462 |
char_type decimal_point() const;
|
| 1463 |
```
|
| 1464 |
|
| 1465 |
-
*Returns:* `do_decimal_point()`
|
| 1466 |
|
| 1467 |
``` cpp
|
| 1468 |
char_type thousands_sep() const;
|
| 1469 |
```
|
| 1470 |
|
| 1471 |
-
*Returns:* `do_thousands_sep()`
|
| 1472 |
|
| 1473 |
``` cpp
|
| 1474 |
string grouping() const;
|
| 1475 |
```
|
| 1476 |
|
| 1477 |
-
*Returns:* `do_grouping()`
|
| 1478 |
|
| 1479 |
``` cpp
|
| 1480 |
string_type truename() const;
|
| 1481 |
string_type falsename() const;
|
| 1482 |
```
|
|
@@ -1503,14 +1489,14 @@ required specializations return `’,’` or `L’,’`.
|
|
| 1503 |
string do_grouping() const;
|
| 1504 |
```
|
| 1505 |
|
| 1506 |
*Returns:* A basic_string\<char\> `vec` used as a vector of integer
|
| 1507 |
values, in which each element `vec[i]` represents the number of
|
| 1508 |
-
digits[^
|
| 1509 |
the rightmost group. If `vec.size() <= i`, the number is the same as
|
| 1510 |
-
group `(i-1)`; if `(i<0 || vec[i]<=0 || vec[i]==CHAR_MAX)`, the
|
| 1511 |
-
the digit group is unlimited.
|
| 1512 |
|
| 1513 |
The required specializations return the empty string, indicating no
|
| 1514 |
grouping.
|
| 1515 |
|
| 1516 |
``` cpp
|
|
@@ -1530,12 +1516,13 @@ or `L"true"` and `L"false"`.
|
|
| 1530 |
namespace std {
|
| 1531 |
template <class charT>
|
| 1532 |
class numpunct_byname : public numpunct<charT> {
|
| 1533 |
// this class is specialized for char and wchar_t.
|
| 1534 |
public:
|
| 1535 |
-
|
| 1536 |
-
|
|
|
|
| 1537 |
explicit numpunct_byname(const char*, size_t refs = 0);
|
| 1538 |
explicit numpunct_byname(const string&, size_t refs = 0);
|
| 1539 |
protected:
|
| 1540 |
~numpunct_byname();
|
| 1541 |
};
|
|
@@ -1549,12 +1536,12 @@ namespace std {
|
|
| 1549 |
``` cpp
|
| 1550 |
namespace std {
|
| 1551 |
template <class charT>
|
| 1552 |
class collate : public locale::facet {
|
| 1553 |
public:
|
| 1554 |
-
|
| 1555 |
-
|
| 1556 |
|
| 1557 |
explicit collate(size_t refs = 0);
|
| 1558 |
|
| 1559 |
int compare(const charT* low1, const charT* high1,
|
| 1560 |
const charT* low2, const charT* high2) const;
|
|
@@ -1590,23 +1577,23 @@ Each function compares a string of characters `*p` in the range \[`low`,
|
|
| 1590 |
``` cpp
|
| 1591 |
int compare(const charT* low1, const charT* high1,
|
| 1592 |
const charT* low2, const charT* high2) const;
|
| 1593 |
```
|
| 1594 |
|
| 1595 |
-
*Returns:* `do_compare(low1, high1, low2, high2)`
|
| 1596 |
|
| 1597 |
``` cpp
|
| 1598 |
string_type transform(const charT* low, const charT* high) const;
|
| 1599 |
```
|
| 1600 |
|
| 1601 |
-
*Returns:* `do_transform(low, high)`
|
| 1602 |
|
| 1603 |
``` cpp
|
| 1604 |
long hash(const charT* low, const charT* high) const;
|
| 1605 |
```
|
| 1606 |
|
| 1607 |
-
*Returns:* `do_hash(low, high)`
|
| 1608 |
|
| 1609 |
##### `collate` virtual functions <a id="locale.collate.virtuals">[[locale.collate.virtuals]]</a>
|
| 1610 |
|
| 1611 |
``` cpp
|
| 1612 |
int do_compare(const charT* low1, const charT* high1,
|
|
@@ -1624,30 +1611,33 @@ string_type do_transform(const charT* low, const charT* high) const;
|
|
| 1624 |
```
|
| 1625 |
|
| 1626 |
*Returns:* A `basic_string<charT>` value that, compared
|
| 1627 |
lexicographically with the result of calling `transform()` on another
|
| 1628 |
string, yields the same result as calling `do_compare()` on the same two
|
| 1629 |
-
strings.[^
|
| 1630 |
|
| 1631 |
``` cpp
|
| 1632 |
long do_hash(const charT* low, const charT* high) const;
|
| 1633 |
```
|
| 1634 |
|
| 1635 |
*Returns:* An integer value equal to the result of calling `hash()` on
|
| 1636 |
any other string for which `do_compare()` returns 0 (equal) when passed
|
| 1637 |
-
the two strings.
|
|
|
|
|
|
|
| 1638 |
string which does not compare equal should be very small, approaching
|
| 1639 |
-
`(1.0/numeric_limits<unsigned long>::max())`.
|
| 1640 |
|
| 1641 |
#### Class template `collate_byname` <a id="locale.collate.byname">[[locale.collate.byname]]</a>
|
| 1642 |
|
| 1643 |
``` cpp
|
| 1644 |
namespace std {
|
| 1645 |
template <class charT>
|
| 1646 |
class collate_byname : public collate<charT> {
|
| 1647 |
public:
|
| 1648 |
-
|
|
|
|
| 1649 |
explicit collate_byname(const char*, size_t refs = 0);
|
| 1650 |
explicit collate_byname(const string&, size_t refs = 0);
|
| 1651 |
protected:
|
| 1652 |
~collate_byname();
|
| 1653 |
};
|
|
@@ -1661,12 +1651,12 @@ Templates `time_get<charT,InputIterator>` and
|
|
| 1661 |
parsing. All specifications of member functions for `time_put` and
|
| 1662 |
`time_get` in the subclauses of [[category.time]] only apply to the
|
| 1663 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 1664 |
and [[tab:localization.required.specializations]] (
|
| 1665 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 1666 |
-
`ios_base::iostate&`, and `fill` arguments as described in
|
| 1667 |
-
[[locale.categories]]
|
| 1668 |
details.
|
| 1669 |
|
| 1670 |
#### Class template `time_get` <a id="locale.time.get">[[locale.time.get]]</a>
|
| 1671 |
|
| 1672 |
``` cpp
|
|
@@ -1677,12 +1667,12 @@ namespace std {
|
|
| 1677 |
};
|
| 1678 |
|
| 1679 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 1680 |
class time_get : public locale::facet, public time_base {
|
| 1681 |
public:
|
| 1682 |
-
|
| 1683 |
-
|
| 1684 |
|
| 1685 |
explicit time_get(size_t refs = 0);
|
| 1686 |
|
| 1687 |
dateorder date_order() const { return do_date_order(); }
|
| 1688 |
iter_type get_time(iter_type s, iter_type end, ios_base& f,
|
|
@@ -1723,81 +1713,81 @@ namespace std {
|
|
| 1723 |
```
|
| 1724 |
|
| 1725 |
`time_get`
|
| 1726 |
|
| 1727 |
is used to parse a character sequence, extracting components of a time
|
| 1728 |
-
or date into a `struct tm`
|
| 1729 |
produced by a corresponding format specifier to `time_put<>::put`. If
|
| 1730 |
the sequence being parsed matches the correct format, the corresponding
|
| 1731 |
members of the `struct tm` argument are set to the values used to
|
| 1732 |
produce the sequence; otherwise either an error is reported or
|
| 1733 |
-
unspecified values are assigned.[^
|
| 1734 |
|
| 1735 |
If the end iterator is reached during parsing by any of the `get()`
|
| 1736 |
member functions, the member sets `ios_base::eofbit` in `err`.
|
| 1737 |
|
| 1738 |
##### `time_get` members <a id="locale.time.get.members">[[locale.time.get.members]]</a>
|
| 1739 |
|
| 1740 |
``` cpp
|
| 1741 |
dateorder date_order() const;
|
| 1742 |
```
|
| 1743 |
|
| 1744 |
-
*Returns:* `do_date_order()`
|
| 1745 |
|
| 1746 |
``` cpp
|
| 1747 |
iter_type get_time(iter_type s, iter_type end, ios_base& str,
|
| 1748 |
ios_base::iostate& err, tm* t) const;
|
| 1749 |
```
|
| 1750 |
|
| 1751 |
-
*Returns:* `do_get_time(s, end, str, err, t)`
|
| 1752 |
|
| 1753 |
``` cpp
|
| 1754 |
iter_type get_date(iter_type s, iter_type end, ios_base& str,
|
| 1755 |
ios_base::iostate& err, tm* t) const;
|
| 1756 |
```
|
| 1757 |
|
| 1758 |
-
*Returns:* `do_get_date(s, end, str, err, t)`
|
| 1759 |
|
| 1760 |
``` cpp
|
| 1761 |
iter_type get_weekday(iter_type s, iter_type end, ios_base& str,
|
| 1762 |
ios_base::iostate& err, tm* t) const;
|
| 1763 |
iter_type get_monthname(iter_type s, iter_type end, ios_base& str,
|
| 1764 |
ios_base::iostate& err, tm* t) const;
|
| 1765 |
```
|
| 1766 |
|
| 1767 |
*Returns:* `do_get_weekday(s, end, str, err, t)` or
|
| 1768 |
-
`do_get_monthname(s, end, str, err, t)`
|
| 1769 |
|
| 1770 |
``` cpp
|
| 1771 |
iter_type get_year(iter_type s, iter_type end, ios_base& str,
|
| 1772 |
ios_base::iostate& err, tm* t) const;
|
| 1773 |
```
|
| 1774 |
|
| 1775 |
-
*Returns:* `do_get_year(s, end, str, err, t)`
|
| 1776 |
|
| 1777 |
``` cpp
|
| 1778 |
-
iter_type get(iter_type s, iter_type end, ios_base& f,
|
| 1779 |
-
|
| 1780 |
```
|
| 1781 |
|
| 1782 |
-
*Returns:* `do_get(s, end, f, err, t, format, modifier)`
|
| 1783 |
|
| 1784 |
``` cpp
|
| 1785 |
-
iter_type get(iter_type s, iter_type end, ios_base& f,
|
| 1786 |
-
|
| 1787 |
```
|
| 1788 |
|
| 1789 |
*Requires:* \[`fmt`, `fmtend`) shall be a valid range.
|
| 1790 |
|
| 1791 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 1792 |
It then enters a loop, reading zero or more characters from `s` at each
|
| 1793 |
iteration. Unless otherwise specified below, the loop terminates when
|
| 1794 |
the first of the following conditions holds:
|
| 1795 |
|
| 1796 |
-
- The expression `fmt == fmtend` evaluates to true.
|
| 1797 |
-
- The expression `err == ios_base::goodbit` evaluates to false.
|
| 1798 |
-
- The expression `s == end` evaluates to true, in which case the
|
| 1799 |
function evaluates `err = ios_base::eofbit | ios_base::failbit`.
|
| 1800 |
- The next element of `fmt` is equal to `’%’`, optionally followed by a
|
| 1801 |
modifier character, followed by a conversion specifier character,
|
| 1802 |
`format`, together forming a conversion specification valid for the
|
| 1803 |
ISO/IEC 9945 function `strptime`. If the number of elements in the
|
|
@@ -1808,36 +1798,37 @@ the first of the following conditions holds:
|
|
| 1808 |
value of `modifier` is `’\0’` when the optional modifier is absent
|
| 1809 |
from the conversion specification. If `err == ios_base::goodbit` holds
|
| 1810 |
after the evaluation of the expression, the function increments `fmt`
|
| 1811 |
to point just past the end of the conversion specification and
|
| 1812 |
continues looping.
|
| 1813 |
-
- The expression `isspace(*fmt, f.getloc())` evaluates to true, in
|
| 1814 |
-
case the function first increments `fmt` until
|
| 1815 |
-
`fmt == fmtend || !isspace(*fmt, f.getloc())` evaluates to true,
|
| 1816 |
-
advances `s` until `s == end || !isspace(*s, f.getloc())` is
|
| 1817 |
-
finally resumes looping.
|
| 1818 |
- The next character read from `s` matches the element pointed to by
|
| 1819 |
`fmt` in a case-insensitive comparison, in which case the function
|
| 1820 |
evaluates `++fmt, ++s` and continues looping. Otherwise, the function
|
| 1821 |
evaluates `err = ios_base::failbit`.
|
| 1822 |
|
| 1823 |
-
The function uses the `ctype<charT>` facet installed in
|
| 1824 |
-
determine valid whitespace characters. It is unspecified
|
| 1825 |
-
the function performs case-insensitive comparison or
|
| 1826 |
-
multi-character sequences are considered while doing
|
|
|
|
| 1827 |
|
| 1828 |
-
*Returns:* `s`
|
| 1829 |
|
| 1830 |
##### `time_get` virtual functions <a id="locale.time.get.virtuals">[[locale.time.get.virtuals]]</a>
|
| 1831 |
|
| 1832 |
``` cpp
|
| 1833 |
dateorder do_date_order() const;
|
| 1834 |
```
|
| 1835 |
|
| 1836 |
*Returns:* An enumeration value indicating the preferred order of
|
| 1837 |
components for those date formats that are composed of day, month, and
|
| 1838 |
-
year.[^
|
| 1839 |
contains other variable components (e.g., Julian day, week number, week
|
| 1840 |
day).
|
| 1841 |
|
| 1842 |
``` cpp
|
| 1843 |
iter_type do_get_time(iter_type s, iter_type end, ios_base& str,
|
|
@@ -1924,24 +1915,24 @@ any remaining format characters, corresponding to a conversion directive
|
|
| 1924 |
appropriate for the ISO/IEC 9945 function `strptime`, formed by
|
| 1925 |
concatenating `’%’`, the `modifier` character, when non-NUL, and the
|
| 1926 |
`format` character. When the concatenation fails to yield a complete
|
| 1927 |
valid directive the function leaves the object pointed to by `t`
|
| 1928 |
unchanged and evaluates `err |= ios_base::failbit`. When `s == end`
|
| 1929 |
-
evaluates to true after reading a character the function evaluates
|
| 1930 |
`err |= ios_base::eofbit`.
|
| 1931 |
|
| 1932 |
For complex conversion directives such as `%c`, `%x`, or `%X`, or
|
| 1933 |
directives that involve the optional modifiers `E` or `O`, when the
|
| 1934 |
function is unable to unambiguously determine some or all `struct tm`
|
| 1935 |
members from the input sequence \[`s`, `end`), it evaluates
|
| 1936 |
`err |= ios_base::eofbit`. In such cases the values of those `struct tm`
|
| 1937 |
members are unspecified and may be outside their valid range.
|
| 1938 |
|
| 1939 |
-
It is unspecified whether multiple calls to `do_get()` with
|
| 1940 |
-
of the same `struct tm` object will update the current
|
| 1941 |
-
object or simply overwrite its members. Portable
|
| 1942 |
-
the object before invoking the function.
|
| 1943 |
|
| 1944 |
*Returns:* An iterator pointing immediately beyond the last character
|
| 1945 |
recognized as possibly part of a valid input sequence for the given
|
| 1946 |
`format` and `modifier`.
|
| 1947 |
|
|
@@ -1950,12 +1941,12 @@ recognized as possibly part of a valid input sequence for the given
|
|
| 1950 |
``` cpp
|
| 1951 |
namespace std {
|
| 1952 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 1953 |
class time_get_byname : public time_get<charT, InputIterator> {
|
| 1954 |
public:
|
| 1955 |
-
|
| 1956 |
-
|
| 1957 |
|
| 1958 |
explicit time_get_byname(const char*, size_t refs = 0);
|
| 1959 |
explicit time_get_byname(const string&, size_t refs = 0);
|
| 1960 |
protected:
|
| 1961 |
~time_get_byname();
|
|
@@ -1968,12 +1959,12 @@ namespace std {
|
|
| 1968 |
``` cpp
|
| 1969 |
namespace std {
|
| 1970 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 1971 |
class time_put : public locale::facet {
|
| 1972 |
public:
|
| 1973 |
-
|
| 1974 |
-
|
| 1975 |
|
| 1976 |
explicit time_put(size_t refs = 0);
|
| 1977 |
|
| 1978 |
// the following is implemented in terms of other member functions.
|
| 1979 |
iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb,
|
|
@@ -2008,20 +1999,20 @@ call to `do_put`; thus, format elements and other characters are
|
|
| 2008 |
interleaved in the output in the order in which they appear in the
|
| 2009 |
pattern. Format sequences are identified by converting each character
|
| 2010 |
`c` to a `char` value as if by `ct.narrow(c, 0)`, where `ct` is a
|
| 2011 |
reference to `ctype<charT>` obtained from `str.getloc()`. The first
|
| 2012 |
character of each sequence is equal to `’%’`, followed by an optional
|
| 2013 |
-
modifier character `mod`[^
|
| 2014 |
defined for the function `strftime`. If no modifier character is
|
| 2015 |
present, `mod` is zero. For each valid format sequence identified, calls
|
| 2016 |
`do_put(s, str, fill, t, spec, mod)`.
|
| 2017 |
|
| 2018 |
The second form calls `do_put(s, str, fill, t, format, modifier)`.
|
| 2019 |
|
| 2020 |
-
The `fill` argument may be used in the
|
| 2021 |
-
by derivations. A space character is a
|
| 2022 |
-
argument.
|
| 2023 |
|
| 2024 |
*Returns:* An iterator pointing immediately after the last character
|
| 2025 |
produced.
|
| 2026 |
|
| 2027 |
##### `time_put` virtual functions <a id="locale.time.put.virtuals">[[locale.time.put.virtuals]]</a>
|
|
@@ -2033,29 +2024,31 @@ iter_type do_put(iter_type s, ios_base&, char_type fill, const tm* t,
|
|
| 2033 |
|
| 2034 |
*Effects:* Formats the contents of the parameter `t` into characters
|
| 2035 |
placed on the output sequence `s`. Formatting is controlled by the
|
| 2036 |
parameters `format` and `modifier`, interpreted identically as the
|
| 2037 |
format specifiers in the string argument to the standard library
|
| 2038 |
-
function `strftime()`[^
|
| 2039 |
produced for those specifiers that are described as depending on the C
|
| 2040 |
-
locale are instead *implementation-defined*.[^
|
| 2041 |
|
| 2042 |
*Returns:* An iterator pointing immediately after the last character
|
| 2043 |
-
produced.
|
| 2044 |
-
|
| 2045 |
-
|
|
|
|
|
|
|
| 2046 |
|
| 2047 |
#### Class template `time_put_byname` <a id="locale.time.put.byname">[[locale.time.put.byname]]</a>
|
| 2048 |
|
| 2049 |
``` cpp
|
| 2050 |
namespace std {
|
| 2051 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2052 |
class time_put_byname : public time_put<charT, OutputIterator>
|
| 2053 |
{
|
| 2054 |
public:
|
| 2055 |
-
|
| 2056 |
-
|
| 2057 |
|
| 2058 |
explicit time_put_byname(const char*, size_t refs = 0);
|
| 2059 |
explicit time_put_byname(const string&, size_t refs = 0);
|
| 2060 |
protected:
|
| 2061 |
~time_put_byname();
|
|
@@ -2071,25 +2064,24 @@ whether local or international monetary formats are to be used.
|
|
| 2071 |
All specifications of member functions for `money_put` and `money_get`
|
| 2072 |
in the subclauses of [[category.monetary]] only apply to the
|
| 2073 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 2074 |
and [[tab:localization.required.specializations]] (
|
| 2075 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 2076 |
-
`ios_base
|
| 2077 |
-
[[locale.categories]]
|
| 2078 |
determine formatting details.
|
| 2079 |
|
| 2080 |
#### Class template `money_get` <a id="locale.money.get">[[locale.money.get]]</a>
|
| 2081 |
|
| 2082 |
``` cpp
|
| 2083 |
namespace std {
|
| 2084 |
-
template <class charT,
|
| 2085 |
-
class InputIterator = istreambuf_iterator<charT> >
|
| 2086 |
class money_get : public locale::facet {
|
| 2087 |
public:
|
| 2088 |
-
|
| 2089 |
-
|
| 2090 |
-
|
| 2091 |
|
| 2092 |
explicit money_get(size_t refs = 0);
|
| 2093 |
|
| 2094 |
iter_type get(iter_type s, iter_type end, bool intl,
|
| 2095 |
ios_base& f, ios_base::iostate& err,
|
|
@@ -2118,11 +2110,11 @@ iter_type get(iter_type s, iter_type end, bool intl,
|
|
| 2118 |
long double& quant) const;
|
| 2119 |
iter_type get(s, iter_type end, bool intl, ios_base&f,
|
| 2120 |
ios_base::iostate& err, string_type& quant) const;
|
| 2121 |
```
|
| 2122 |
|
| 2123 |
-
*Returns:* `do_get(s, end, intl, f, err, quant)`
|
| 2124 |
|
| 2125 |
##### `money_get` virtual functions <a id="locale.money.get.virtuals">[[locale.money.get.virtuals]]</a>
|
| 2126 |
|
| 2127 |
``` cpp
|
| 2128 |
iter_type do_get(iter_type s, iter_type end, bool intl,
|
|
@@ -2143,13 +2135,17 @@ does not change `err`; otherwise, sets `err` to `(err|str.failbit)`, or
|
|
| 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 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2151 |
any such characters are not read, and parsing is terminated at the point
|
| 2152 |
where they first appear. Otherwise, thousands separators are optional;
|
| 2153 |
if present, they are checked for correct placement only after all format
|
| 2154 |
components have been read.
|
| 2155 |
|
|
@@ -2165,27 +2161,30 @@ format; otherwise, the currency symbol is required.
|
|
| 2165 |
|
| 2166 |
If the first character (if any) in the string `pos` returned by
|
| 2167 |
`mp.positive_sign()` or the string `neg` returned by
|
| 2168 |
`mp.negative_sign()` is recognized in the position indicated by `sign`
|
| 2169 |
in the format pattern, it is consumed and any remaining characters in
|
| 2170 |
-
the string are required after all the other format components.
|
| 2171 |
-
|
| 2172 |
-
|
| 2173 |
-
|
| 2174 |
-
|
| 2175 |
-
|
| 2176 |
-
|
| 2177 |
-
|
| 2178 |
-
|
| 2179 |
-
|
| 2180 |
-
|
|
|
|
|
|
|
|
|
|
| 2181 |
|
| 2182 |
Digits in the numeric monetary component are extracted and placed in
|
| 2183 |
`digits`, or into a character buffer `buf1` for conversion to produce a
|
| 2184 |
value for `units`, in the order in which they appear, preceded by a
|
| 2185 |
minus sign if and only if the result is negative. The value `units` is
|
| 2186 |
-
produced as if by[^
|
| 2187 |
|
| 2188 |
``` cpp
|
| 2189 |
for (int i = 0; i < n; ++i)
|
| 2190 |
buf2[i] = src[find(atoms, atoms+sizeof(src), buf1[i]) - atoms];
|
| 2191 |
buf2[n] = 0;
|
|
@@ -2206,17 +2205,16 @@ recognized as part of a valid monetary quantity.
|
|
| 2206 |
|
| 2207 |
#### Class template `money_put` <a id="locale.money.put">[[locale.money.put]]</a>
|
| 2208 |
|
| 2209 |
``` cpp
|
| 2210 |
namespace std {
|
| 2211 |
-
template <class charT,
|
| 2212 |
-
class OutputIterator = ostreambuf_iterator<charT> >
|
| 2213 |
class money_put : public locale::facet {
|
| 2214 |
public:
|
| 2215 |
-
|
| 2216 |
-
|
| 2217 |
-
|
| 2218 |
|
| 2219 |
explicit money_put(size_t refs = 0);
|
| 2220 |
|
| 2221 |
iter_type put(iter_type s, bool intl, ios_base& f,
|
| 2222 |
char_type fill, long double units) const;
|
|
@@ -2242,11 +2240,11 @@ iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
|
| 2242 |
long double quant) const;
|
| 2243 |
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
| 2244 |
const string_type& quant) const;
|
| 2245 |
```
|
| 2246 |
|
| 2247 |
-
*Returns:* `do_put(s, intl, f, loc, quant)`
|
| 2248 |
|
| 2249 |
##### `money_put` virtual functions <a id="locale.money.put.virtuals">[[locale.money.put.virtuals]]</a>
|
| 2250 |
|
| 2251 |
``` cpp
|
| 2252 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
@@ -2281,16 +2279,18 @@ Calls `str.width(0)`.
|
|
| 2281 |
`(str.flags() & str.showbase)` is nonzero. If the number of characters
|
| 2282 |
generated for the specified format is less than the value returned by
|
| 2283 |
`str.width()` on entry to the function, then copies of `fill` are
|
| 2284 |
inserted as necessary to pad to the specified width. For the value `af`
|
| 2285 |
equal to `(str.flags() & str.adjustfield)`, if `(af == str.internal)` is
|
| 2286 |
-
true, the fill characters are placed where `none` or `space` appears
|
| 2287 |
-
the formatting pattern; otherwise if `(af == str.left)` is true,
|
| 2288 |
-
are placed after the other characters; otherwise, they are placed
|
| 2289 |
-
the other characters.
|
| 2290 |
-
|
| 2291 |
-
|
|
|
|
|
|
|
| 2292 |
|
| 2293 |
*Returns:* An iterator pointing immediately after the last character
|
| 2294 |
produced.
|
| 2295 |
|
| 2296 |
#### Class template `moneypunct` <a id="locale.moneypunct">[[locale.moneypunct]]</a>
|
|
@@ -2304,12 +2304,12 @@ namespace std {
|
|
| 2304 |
};
|
| 2305 |
|
| 2306 |
template <class charT, bool International = false>
|
| 2307 |
class moneypunct : public locale::facet, public money_base {
|
| 2308 |
public:
|
| 2309 |
-
|
| 2310 |
-
|
| 2311 |
|
| 2312 |
explicit moneypunct(size_t refs = 0);
|
| 2313 |
|
| 2314 |
charT decimal_point() const;
|
| 2315 |
charT thousands_sep() const;
|
|
@@ -2341,11 +2341,11 @@ namespace std {
|
|
| 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`th component of
|
| 2346 |
-
the format[^
|
| 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 |
|
| 2351 |
Where `none` or `space` appears, white space is permitted in the format,
|
|
@@ -2408,56 +2408,56 @@ int frac_digits() const;
|
|
| 2408 |
pattern pos_format() const;
|
| 2409 |
pattern neg_format() const;
|
| 2410 |
```
|
| 2411 |
|
| 2412 |
Each of these functions `F` returns the result of calling the
|
| 2413 |
-
corresponding virtual member function `
|
| 2414 |
|
| 2415 |
##### `moneypunct` virtual functions <a id="locale.moneypunct.virtuals">[[locale.moneypunct.virtuals]]</a>
|
| 2416 |
|
| 2417 |
``` cpp
|
| 2418 |
charT do_decimal_point() const;
|
| 2419 |
```
|
| 2420 |
|
| 2421 |
*Returns:* The radix separator to use in case `do_frac_digits()` is
|
| 2422 |
-
greater than zero.[^
|
| 2423 |
|
| 2424 |
``` cpp
|
| 2425 |
charT do_thousands_sep() const;
|
| 2426 |
```
|
| 2427 |
|
| 2428 |
*Returns:* The digit group separator to use in case `do_grouping()`
|
| 2429 |
-
specifies a digit grouping pattern.[^
|
| 2430 |
|
| 2431 |
``` cpp
|
| 2432 |
string do_grouping() const;
|
| 2433 |
```
|
| 2434 |
|
| 2435 |
*Returns:* A pattern defined identically as, but not necessarily equal
|
| 2436 |
-
to, the result of `numpunct<charT>::do_grouping()`.[^
|
| 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 |
```
|
|
@@ -2465,21 +2465,21 @@ pattern do_neg_format() const;
|
|
| 2465 |
*Returns:* The specializations required in
|
| 2466 |
Table [[tab:localization.required.specializations]] ([[locale.category]]),
|
| 2467 |
namely `moneypunct<char>`, `moneypunct<wchar_t>`,
|
| 2468 |
`moneypunct<char, true>`, and `moneypunct<wchar_t, true>`, return an
|
| 2469 |
object of type `pattern` initialized to
|
| 2470 |
-
`{ symbol, sign, none, value }`.[^
|
| 2471 |
|
| 2472 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 2473 |
|
| 2474 |
``` cpp
|
| 2475 |
namespace std {
|
| 2476 |
template <class charT, bool Intl = false>
|
| 2477 |
class moneypunct_byname : public moneypunct<charT, Intl> {
|
| 2478 |
public:
|
| 2479 |
-
|
| 2480 |
-
|
| 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();
|
|
@@ -2496,18 +2496,18 @@ catalogs.
|
|
| 2496 |
|
| 2497 |
``` cpp
|
| 2498 |
namespace std {
|
| 2499 |
class messages_base {
|
| 2500 |
public:
|
| 2501 |
-
|
| 2502 |
};
|
| 2503 |
|
| 2504 |
template <class charT>
|
| 2505 |
class messages : public locale::facet, public messages_base {
|
| 2506 |
public:
|
| 2507 |
-
|
| 2508 |
-
|
| 2509 |
|
| 2510 |
explicit messages(size_t refs = 0);
|
| 2511 |
|
| 2512 |
catalog open(const basic_string<char>& fn, const locale&) const;
|
| 2513 |
string_type get(catalog c, int set, int msgid,
|
|
@@ -2536,12 +2536,11 @@ catalog open(const basic_string<char>& name, const locale& loc) const;
|
|
| 2536 |
```
|
| 2537 |
|
| 2538 |
*Returns:* `do_open(name, loc)`.
|
| 2539 |
|
| 2540 |
``` cpp
|
| 2541 |
-
string_type get(catalog cat, int set, int msgid,
|
| 2542 |
-
const string_type& dfault) const;
|
| 2543 |
```
|
| 2544 |
|
| 2545 |
*Returns:* `do_get(cat, set, msgid, dfault)`.
|
| 2546 |
|
| 2547 |
``` cpp
|
|
@@ -2551,12 +2550,11 @@ void close(catalog cat) const;
|
|
| 2551 |
*Effects:* Calls `do_close(cat)`.
|
| 2552 |
|
| 2553 |
##### `messages` virtual functions <a id="locale.messages.virtuals">[[locale.messages.virtuals]]</a>
|
| 2554 |
|
| 2555 |
``` cpp
|
| 2556 |
-
catalog do_open(const basic_string<char>& name,
|
| 2557 |
-
const locale& loc) const;
|
| 2558 |
```
|
| 2559 |
|
| 2560 |
*Returns:* A value that may be passed to `get()` to retrieve a message
|
| 2561 |
from the message catalog identified by the string `name` according to an
|
| 2562 |
*implementation-defined* mapping. The result can be used until it is
|
|
@@ -2566,12 +2564,11 @@ Returns a value less than 0 if no such catalog can be opened.
|
|
| 2566 |
|
| 2567 |
*Remarks:* The locale argument `loc` is used for character set code
|
| 2568 |
conversion when retrieving messages, if needed.
|
| 2569 |
|
| 2570 |
``` cpp
|
| 2571 |
-
string_type do_get(catalog cat, int set, int msgid,
|
| 2572 |
-
const string_type& dfault) const;
|
| 2573 |
```
|
| 2574 |
|
| 2575 |
*Requires:* `cat` shall be a catalog obtained from `open()` and not yet
|
| 2576 |
closed.
|
| 2577 |
|
|
@@ -2587,21 +2584,21 @@ void do_close(catalog cat) const;
|
|
| 2587 |
closed.
|
| 2588 |
|
| 2589 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 2590 |
|
| 2591 |
*Remarks:* The limit on such resources, if any, is
|
| 2592 |
-
implementation-defined.
|
| 2593 |
|
| 2594 |
#### Class template `messages_byname` <a id="locale.messages.byname">[[locale.messages.byname]]</a>
|
| 2595 |
|
| 2596 |
``` cpp
|
| 2597 |
namespace std {
|
| 2598 |
template <class charT>
|
| 2599 |
class messages_byname : public messages<charT> {
|
| 2600 |
public:
|
| 2601 |
-
|
| 2602 |
-
|
| 2603 |
|
| 2604 |
explicit messages_byname(const char*, size_t refs = 0);
|
| 2605 |
explicit messages_byname(const string&, size_t refs = 0);
|
| 2606 |
protected:
|
| 2607 |
~messages_byname();
|
|
@@ -2614,11 +2611,14 @@ namespace std {
|
|
| 2614 |
A C++program may define facets to be added to a locale and used
|
| 2615 |
identically as the built-in facets. To create a new facet interface,
|
| 2616 |
C++programs simply derive from `locale::facet` a class containing a
|
| 2617 |
static member: `static locale::id id`.
|
| 2618 |
|
| 2619 |
-
The locale member function templates verify its type and
|
|
|
|
|
|
|
|
|
|
| 2620 |
|
| 2621 |
Traditional global localization is still easy:
|
| 2622 |
|
| 2623 |
``` cpp
|
| 2624 |
#include <iostream>
|
|
@@ -2636,10 +2636,14 @@ int main(int argc, char** argv) {
|
|
| 2636 |
|
| 2637 |
return MyObject(argc, argv).doit();
|
| 2638 |
}
|
| 2639 |
```
|
| 2640 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2641 |
Greater flexibility is possible:
|
| 2642 |
|
| 2643 |
``` cpp
|
| 2644 |
#include <iostream>
|
| 2645 |
#include <locale>
|
|
@@ -2653,13 +2657,17 @@ int main() {
|
|
| 2653 |
}
|
| 2654 |
```
|
| 2655 |
|
| 2656 |
In a European locale, with input `3.456,78`, output is `3456.78`.
|
| 2657 |
|
|
|
|
|
|
|
| 2658 |
This can be important even for simple programs, which may need to write
|
| 2659 |
a data file in a fixed format, regardless of a user’s preference.
|
| 2660 |
|
|
|
|
|
|
|
| 2661 |
Here is an example of the use of locales in a library interface.
|
| 2662 |
|
| 2663 |
``` cpp
|
| 2664 |
// file: Date.h
|
| 2665 |
#include <iosfwd>
|
|
@@ -2707,15 +2715,19 @@ std::istream& operator>>(std::istream& s, Date& d) {
|
|
| 2707 |
}
|
| 2708 |
return s;
|
| 2709 |
}
|
| 2710 |
```
|
| 2711 |
|
|
|
|
|
|
|
| 2712 |
A locale object may be extended with a new facet simply by constructing
|
| 2713 |
it with an instance of a class derived from `locale::facet`. The only
|
| 2714 |
member a C++program must define is the static member `id`, which
|
| 2715 |
identifies your class interface as a new facet.
|
| 2716 |
|
|
|
|
|
|
|
| 2717 |
Classifying Japanese characters:
|
| 2718 |
|
| 2719 |
``` cpp
|
| 2720 |
// file: <jctype>
|
| 2721 |
#include <locale>
|
|
@@ -2737,33 +2749,36 @@ namespace My {
|
|
| 2737 |
#include "jctype" // above
|
| 2738 |
std::locale::id My::JCtype::id; // the static JCtype member declared above.
|
| 2739 |
|
| 2740 |
int main() {
|
| 2741 |
using namespace std;
|
| 2742 |
-
|
| 2743 |
locale loc(locale(""), // the user's preferred locale ...
|
| 2744 |
new My::JCtype); // and a new feature ...
|
| 2745 |
wchar_t c = use_facet<wctype>(loc).widen('!');
|
| 2746 |
if (!use_facet<My::JCtype>(loc).is_kanji(c))
|
| 2747 |
cout << "no it isn't!" << endl;
|
| 2748 |
-
return 0;
|
| 2749 |
}
|
| 2750 |
```
|
| 2751 |
|
| 2752 |
The new facet is used exactly like the built-in facets.
|
| 2753 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2754 |
Replacing an existing facet is even easier. The code does not define a
|
| 2755 |
member `id` because it is reusing the `numpunct<charT>` facet interface:
|
| 2756 |
|
| 2757 |
``` cpp
|
| 2758 |
// file: my_bool.C
|
| 2759 |
#include <iostream>
|
| 2760 |
#include <locale>
|
| 2761 |
#include <string>
|
| 2762 |
namespace My {
|
| 2763 |
using namespace std;
|
| 2764 |
-
|
| 2765 |
class BoolNames : public cnumpunct {
|
| 2766 |
protected:
|
| 2767 |
string do_truename() const { return "Oui Oui!"; }
|
| 2768 |
string do_falsename() const { return "Mais Non!"; }
|
| 2769 |
~BoolNames() { }
|
|
@@ -2776,9 +2791,10 @@ int main(int argc, char** argv) {
|
|
| 2776 |
using namespace std;
|
| 2777 |
// make the user's preferred locale, except for...
|
| 2778 |
locale loc(locale(""), new My::BoolNames(""));
|
| 2779 |
cout.imbue(loc);
|
| 2780 |
cout << boolalpha << "Any arguments today? " << (argc > 1) << endl;
|
| 2781 |
-
return 0;
|
| 2782 |
}
|
| 2783 |
```
|
| 2784 |
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
namespace std {
|
| 26 |
class ctype_base {
|
| 27 |
public:
|
| 28 |
+
using mask = T;
|
| 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;
|
|
|
|
| 51 |
``` cpp
|
| 52 |
namespace std {
|
| 53 |
template <class charT>
|
| 54 |
class ctype : public locale::facet, public ctype_base {
|
| 55 |
public:
|
| 56 |
+
using char_type = charT;
|
| 57 |
|
| 58 |
explicit ctype(size_t refs = 0);
|
| 59 |
|
| 60 |
bool is(mask m, charT c) const;
|
| 61 |
const charT* is(const charT* low, const charT* high, mask* vec) const;
|
| 62 |
+
const charT* scan_is(mask m, const charT* low, const charT* high) const;
|
| 63 |
+
const charT* scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
|
|
|
| 64 |
charT toupper(charT c) const;
|
| 65 |
const charT* toupper(charT* low, const charT* high) const;
|
| 66 |
charT tolower(charT c) const;
|
| 67 |
const charT* tolower(charT* low, const charT* high) const;
|
| 68 |
|
| 69 |
charT widen(char c) const;
|
| 70 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 71 |
char narrow(charT c, char dfault) const;
|
| 72 |
+
const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
|
|
|
|
| 73 |
|
| 74 |
static locale::id id;
|
| 75 |
|
| 76 |
protected:
|
| 77 |
~ctype();
|
| 78 |
virtual bool do_is(mask m, charT c) const;
|
| 79 |
+
virtual const charT* do_is(const charT* low, const charT* high, mask* vec) const;
|
| 80 |
+
virtual const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
|
| 81 |
+
virtual const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
|
|
|
|
|
|
| 82 |
virtual charT do_toupper(charT) const;
|
| 83 |
virtual const charT* do_toupper(charT* low, const charT* high) const;
|
| 84 |
virtual charT do_tolower(charT) const;
|
| 85 |
virtual const charT* do_tolower(charT* low, const charT* high) const;
|
| 86 |
virtual charT do_widen(char) const;
|
| 87 |
+
virtual const char* do_widen(const char* low, const char* high, charT* dest) const;
|
|
|
|
| 88 |
virtual char do_narrow(charT, char dfault) const;
|
| 89 |
virtual const charT* do_narrow(const charT* low, const charT* high,
|
| 90 |
char dfault, char* dest) const;
|
| 91 |
};
|
| 92 |
}
|
|
|
|
| 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
|
| 129 |
charT toupper(charT) const;
|
| 130 |
const charT* toupper(charT* low, const charT* high) const;
|
| 131 |
```
|
| 132 |
|
| 133 |
+
*Returns:* `do_toupper(c)` or `do_toupper(low, high)`.
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
charT tolower(charT c) const;
|
| 137 |
const charT* tolower(charT* low, const charT* high) const;
|
| 138 |
```
|
| 139 |
|
| 140 |
+
*Returns:* `do_tolower(c)` or `do_tolower(low, high)`.
|
| 141 |
|
| 142 |
``` cpp
|
| 143 |
charT widen(char c) const;
|
| 144 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 145 |
```
|
| 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;
|
|
|
|
| 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
|
| 168 |
+
each `*p` where `(low <= p && p < high)`, and places it into
|
| 169 |
+
`vec[p - low]`.
|
| 170 |
|
| 171 |
*Returns:* The first form returns the result of the expression
|
| 172 |
`(M & m) != 0`; i.e., `true` if the character has the characteristics
|
| 173 |
specified. The second form returns `high`.
|
| 174 |
|
| 175 |
``` cpp
|
| 176 |
+
const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 177 |
```
|
| 178 |
|
| 179 |
*Effects:* Locates a character in a buffer that conforms to a
|
| 180 |
classification `m`.
|
| 181 |
|
| 182 |
+
*Returns:* The smallest pointer `p` in the range \[`low`, `high`) such
|
| 183 |
+
that `is(m, *p)` would return `true`; otherwise, returns `high`.
|
| 184 |
|
| 185 |
``` cpp
|
| 186 |
+
const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 187 |
```
|
| 188 |
|
| 189 |
*Effects:* Locates a character in a buffer that fails to conform to a
|
| 190 |
classification `m`.
|
| 191 |
|
|
|
|
| 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 ([[lex.charset]]).
|
| 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 |
|
| 237 |
The second form transforms each character `*p` in the range \[`low`,
|
| 238 |
`high`), placing the result in `dest[p - low]`.
|
| 239 |
|
| 240 |
*Returns:* The first form returns the transformed value. The second form
|
|
|
|
| 279 |
``` cpp
|
| 280 |
namespace std {
|
| 281 |
template <class charT>
|
| 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 |
};
|
|
|
|
| 292 |
|
| 293 |
#### `ctype` specializations <a id="facet.ctype.special">[[facet.ctype.special]]</a>
|
| 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 = 0, bool del = false,
|
| 303 |
size_t refs = 0);
|
| 304 |
|
| 305 |
bool is(mask m, char c) const;
|
|
|
|
| 344 |
};
|
| 345 |
}
|
| 346 |
```
|
| 347 |
|
| 348 |
A specialization `ctype<char>` is provided so that the member functions
|
| 349 |
+
on type `char` can be implemented `inline`.[^7] The
|
| 350 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 351 |
|
| 352 |
##### `ctype<char>` destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
|
| 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 |
##### `ctype<char>` members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
|
| 362 |
|
| 363 |
In the following member descriptions, for `unsigned char` values `v`
|
| 364 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
|
|
|
| 368 |
``` cpp
|
| 369 |
explicit ctype(const mask* tbl = 0, bool del = false,
|
| 370 |
size_t refs = 0);
|
| 371 |
```
|
| 372 |
|
| 373 |
+
*Requires:* `tbl` either 0 or an array of at least `table_size`
|
| 374 |
+
elements.
|
| 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
|
|
|
|
| 446 |
|
| 447 |
``` cpp
|
| 448 |
const mask* table() const noexcept;
|
| 449 |
```
|
| 450 |
|
| 451 |
+
*Returns:* The first constructor argument, if it was nonzero, otherwise
|
| 452 |
`classic_table()`.
|
| 453 |
|
| 454 |
##### `ctype<char>` static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
|
| 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 |
##### `ctype<char>` virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
|
| 465 |
|
| 466 |
``` cpp
|
| 467 |
char do_toupper(char) const;
|
|
|
|
| 492 |
};
|
| 493 |
|
| 494 |
template <class internT, class externT, class stateT>
|
| 495 |
class codecvt : public locale::facet, public codecvt_base {
|
| 496 |
public:
|
| 497 |
+
using intern_type = internT;
|
| 498 |
+
using extern_type = externT;
|
| 499 |
+
using state_type = stateT;
|
| 500 |
|
| 501 |
explicit codecvt(size_t refs = 0);
|
| 502 |
|
| 503 |
+
result out(
|
| 504 |
+
stateT& state,
|
| 505 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 506 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 507 |
+
|
| 508 |
+
result unshift(
|
| 509 |
+
stateT& state,
|
| 510 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 511 |
+
|
| 512 |
+
result in(
|
| 513 |
+
stateT& state,
|
| 514 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 515 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 516 |
+
|
| 517 |
int encoding() const noexcept;
|
| 518 |
bool always_noconv() const noexcept;
|
| 519 |
+
int length(stateT&, const externT* from, const externT* end, size_t max) const;
|
|
|
|
| 520 |
int max_length() const noexcept;
|
| 521 |
|
| 522 |
static locale::id id;
|
| 523 |
|
| 524 |
protected:
|
| 525 |
~codecvt();
|
| 526 |
+
virtual result do_out(
|
| 527 |
+
stateT& state,
|
| 528 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 529 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 530 |
+
virtual result do_in(
|
| 531 |
+
stateT& state,
|
| 532 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 533 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 534 |
+
virtual result do_unshift(
|
| 535 |
+
stateT& state,
|
| 536 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 537 |
+
|
| 538 |
virtual int do_encoding() const noexcept;
|
| 539 |
virtual bool do_always_noconv() const noexcept;
|
| 540 |
+
virtual int do_length(stateT&, const externT* from, const externT* end, size_t max) const;
|
|
|
|
| 541 |
virtual int do_max_length() const noexcept;
|
| 542 |
};
|
| 543 |
}
|
| 544 |
```
|
| 545 |
|
|
|
|
| 553 |
|
| 554 |
The specializations required in Table
|
| 555 |
[[tab:localization.category.facets]] ([[locale.category]]) convert the
|
| 556 |
implementation-defined native character set.
|
| 557 |
`codecvt<char, char, mbstate_t>` implements a degenerate conversion; it
|
| 558 |
+
does not convert at all. The specialization
|
| 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, char, mbstate_t>` converts between the UTF-32 and UTF-8
|
| 562 |
+
encoding forms. `codecvt<wchar_t, char, mbstate_t>` converts between the
|
| 563 |
+
native character sets for narrow and wide characters. Specializations on
|
| 564 |
+
`mbstate_t` perform conversion between encodings known to the library
|
| 565 |
+
implementer. Other encodings can be converted by specializing on a
|
| 566 |
+
user-defined `stateT` type. Objects of type `stateT` can contain any
|
| 567 |
+
state that is useful to communicate to or from the specialized `do_in`
|
| 568 |
+
or `do_out` members.
|
| 569 |
|
| 570 |
##### `codecvt` members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
|
| 571 |
|
| 572 |
``` cpp
|
| 573 |
+
result out(
|
| 574 |
+
stateT& state,
|
| 575 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 576 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 577 |
```
|
| 578 |
|
| 579 |
*Returns:*
|
| 580 |
+
`do_out(state, from, from_end, from_next, to, to_end, to_next)`.
|
| 581 |
|
| 582 |
``` cpp
|
| 583 |
+
result unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
|
|
|
|
| 584 |
```
|
| 585 |
|
| 586 |
+
*Returns:* `do_unshift(state, to, to_end, to_next)`.
|
| 587 |
|
| 588 |
``` cpp
|
| 589 |
+
result in(
|
| 590 |
+
stateT& state,
|
| 591 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 592 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 593 |
```
|
| 594 |
|
| 595 |
*Returns:*
|
| 596 |
+
`do_in(state, from, from_end, from_next, to, to_end, to_next)`.
|
| 597 |
|
| 598 |
``` cpp
|
| 599 |
int encoding() const noexcept;
|
| 600 |
```
|
| 601 |
|
| 602 |
+
*Returns:* `do_encoding()`.
|
| 603 |
|
| 604 |
``` cpp
|
| 605 |
bool always_noconv() const noexcept;
|
| 606 |
```
|
| 607 |
|
| 608 |
+
*Returns:* `do_always_noconv()`.
|
| 609 |
|
| 610 |
``` cpp
|
| 611 |
+
int length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
|
|
|
|
| 612 |
```
|
| 613 |
|
| 614 |
+
*Returns:* `do_length(state, from, from_end, max)`.
|
| 615 |
|
| 616 |
``` cpp
|
| 617 |
int max_length() const noexcept;
|
| 618 |
```
|
| 619 |
|
| 620 |
+
*Returns:* `do_max_length()`.
|
| 621 |
|
| 622 |
##### `codecvt` virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
|
| 623 |
|
| 624 |
``` cpp
|
| 625 |
+
result do_out(
|
| 626 |
+
stateT& state,
|
| 627 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 628 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 629 |
|
| 630 |
+
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 |
+
*Requires:* `(from <= from_end && to <= to_end)` well-defined and
|
| 637 |
`true`; `state` initialized, if at the beginning of a sequence, or else
|
| 638 |
equal to the result of converting the preceding characters in the
|
| 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.
|
| 645 |
|
| 646 |
Stops if it encounters a character it cannot convert. It always leaves
|
| 647 |
the `from_next` and `to_next` pointers pointing one beyond the last
|
| 648 |
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` ([[file.streams]])
|
| 655 |
shall have the property that if
|
| 656 |
|
| 657 |
``` cpp
|
|
|
|
| 674 |
|
| 675 |
``` cpp
|
| 676 |
do_in(state, from, from_end, from_next, to, to + 1, to_next)
|
| 677 |
```
|
| 678 |
|
| 679 |
+
shall also return `ok`.[^8]
|
|
|
|
|
|
|
| 680 |
|
| 681 |
+
[*Note 1*: As a result of operations on `state`, it can return `ok` or
|
| 682 |
+
`partial` and set `from_next == from` and
|
| 683 |
+
`to_next != to`. — *end note*]
|
| 684 |
+
|
| 685 |
+
*Remarks:* Its operations on `state` are unspecified.
|
| 686 |
+
|
| 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 |
Table [[tab:localization.convert.result.values.out.in]].
|
| 693 |
|
| 694 |
**Table: `do_in/do_out` result values** <a id="tab:localization.convert.result.values.out.in">[tab:localization.convert.result.values.out.in]</a>
|
| 695 |
|
| 696 |
| Value | Meaning |
|
| 697 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 698 |
| `ok` | completed the conversion |
|
| 699 |
| `partial` | not all source characters converted |
|
| 700 |
+
| `error` | encountered a character in {[}`from`, `from_end`{)} that it could not convert |
|
| 701 |
| `noconv` | `internT` and `externT` are the same type, and input sequence is identical to converted sequence |
|
| 702 |
|
| 703 |
|
| 704 |
+
A return value of `partial`, if `(from_next == from_end)`, indicates
|
| 705 |
+
that either the destination sequence has not absorbed all the available
|
| 706 |
destination elements, or that additional source elements are needed
|
| 707 |
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 |
+
*Requires:* `(to <= to_end)` well defined and `true`; state initialized,
|
| 714 |
if at the beginning of a sequence, or else equal to the result of
|
| 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 |
Table [[tab:localization.convert.result.values.unshift]].
|
| 725 |
|
| 726 |
**Table: `do_unshift` result values** <a id="tab:localization.convert.result.values.unshift">[tab:localization.convert.result.values.unshift]</a>
|
| 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` |
|
| 732 |
| `error` | an unspecified error has occurred |
|
| 733 |
| `noconv` | no termination is needed for this `state_type` |
|
| 734 |
|
| 735 |
``` cpp
|
| 736 |
int do_encoding() const noexcept;
|
| 737 |
```
|
| 738 |
|
| 739 |
+
*Returns:* `-1` if the encoding of the `externT` sequence is
|
| 740 |
state-dependent; else the constant number of `externT` characters needed
|
| 741 |
+
to produce an internal character; or `0` if this number is not a
|
| 742 |
+
constant.[^10]
|
| 743 |
|
| 744 |
``` cpp
|
| 745 |
bool do_always_noconv() const noexcept;
|
| 746 |
```
|
| 747 |
|
| 748 |
*Returns:* `true` if `do_in()` and `do_out()` return `noconv` for all
|
| 749 |
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 |
+
*Requires:* `(from <= from_end)` well-defined and `true`; `state`
|
| 756 |
initialized, if at the beginning of a sequence, or else equal to the
|
| 757 |
result of converting the preceding characters in the sequence.
|
| 758 |
|
| 759 |
*Effects:* The effect on the `state` argument is “as if” it called
|
| 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
|
| 765 |
range \[`from`, `from_next`) represents `max` or fewer valid complete
|
| 766 |
characters of type `internT`. The specialization
|
| 767 |
`codecvt<char, char, mbstate_t>`, returns the lesser of `max` and
|
| 768 |
`(from_end-from)`.
|
| 769 |
|
| 770 |
``` cpp
|
| 771 |
int do_max_length() const noexcept;
|
| 772 |
```
|
| 773 |
|
| 774 |
*Returns:* The maximum value that `do_length(state, from, from_end, 1)`
|
| 775 |
+
can return for any valid range \[`from`, `from_end`) and `stateT` value
|
| 776 |
`state`. The specialization
|
| 777 |
`codecvt<char, char, mbstate_t>::do_max_length()` returns 1.
|
| 778 |
|
| 779 |
#### Class template `codecvt_byname` <a id="locale.codecvt.byname">[[locale.codecvt.byname]]</a>
|
| 780 |
|
|
|
|
| 794 |
### The numeric category <a id="category.numeric">[[category.numeric]]</a>
|
| 795 |
|
| 796 |
The classes `num_get<>` and `num_put<>` handle numeric formatting and
|
| 797 |
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:localization.category.facets]]
|
| 804 |
and [[tab:localization.required.specializations]] (
|
|
|
|
| 819 |
``` cpp
|
| 820 |
namespace std {
|
| 821 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 822 |
class num_get : public locale::facet {
|
| 823 |
public:
|
| 824 |
+
using char_type = charT;
|
| 825 |
+
using iter_type = InputIterator;
|
| 826 |
|
| 827 |
explicit num_get(size_t refs = 0);
|
| 828 |
|
| 829 |
iter_type get(iter_type in, iter_type end, ios_base&,
|
| 830 |
ios_base::iostate& err, bool& v) const;
|
|
|
|
| 996 |
| `double` | `l` |
|
| 997 |
| `long double` | `L` |
|
| 998 |
|
| 999 |
- **Stage 2:**
|
| 1000 |
|
| 1001 |
+
If `in == end` then stage 2 terminates. Otherwise a `charT` is taken
|
| 1002 |
+
from `in` and local variables are initialized as if by
|
| 1003 |
|
| 1004 |
``` cpp
|
| 1005 |
char_type ct = *in;
|
| 1006 |
char c = src[find(atoms, atoms + sizeof(src) - 1, ct) - atoms];
|
| 1007 |
if (ct == use_facet<numpunct<charT>>(loc).decimal_point())
|
|
|
|
| 1019 |
use_facet<ctype<charT>>(loc).widen(src, src + sizeof(src), atoms);
|
| 1020 |
```
|
| 1021 |
|
| 1022 |
for this value of `loc`.
|
| 1023 |
|
| 1024 |
+
If `discard` is `true`, then if `’.’` has not yet been accumulated, then
|
| 1025 |
the position of the character is remembered, but the character is
|
| 1026 |
otherwise ignored. Otherwise, if `’.’` has already been accumulated, the
|
| 1027 |
character is discarded and Stage 2 terminates. If it is not discarded,
|
| 1028 |
then a check is made to determine if `c` is allowed as the next
|
| 1029 |
character of an input field of the conversion specifier returned by
|
|
|
|
| 1040 |
|
| 1041 |
- For a signed integer value, the function `strtoll`.
|
| 1042 |
|
| 1043 |
- For an unsigned integer value, the function `strtoull`.
|
| 1044 |
|
| 1045 |
+
- For a `float` value, the function `strtof`.
|
| 1046 |
+
|
| 1047 |
+
- For a `double` value, the function `strtod`.
|
| 1048 |
+
|
| 1049 |
+
- For a `long double` value, the function `strtold`.
|
| 1050 |
|
| 1051 |
The numeric value to be stored can be one of:
|
| 1052 |
|
| 1053 |
+
- zero, if the conversion function does not convert the entire field.
|
|
|
|
| 1054 |
|
| 1055 |
+
- the most positive (or negative) representable value, if the field to
|
| 1056 |
+
be converted to a signed integer type represents a value too large
|
| 1057 |
+
positive (or negative) to be represented in `val`.
|
| 1058 |
|
| 1059 |
+
- the most positive representable value, if the field to be converted to
|
| 1060 |
+
an unsigned integer type represents a value that cannot be represented
|
| 1061 |
+
in `val`.
|
| 1062 |
|
| 1063 |
- the converted value, otherwise.
|
| 1064 |
|
| 1065 |
+
The resultant numeric value is stored in `val`. If the conversion
|
| 1066 |
+
function does not convert the entire field, or if the field represents a
|
| 1067 |
+
value outside the range of representable values, `ios_base::failbit` is
|
| 1068 |
+
assigned to `err`.
|
| 1069 |
|
| 1070 |
Digit grouping is checked. That is, the positions of discarded
|
| 1071 |
separators is examined for consistency with
|
| 1072 |
+
`use_facet<numpunct<charT>>(loc).grouping()`. If they are not consistent
|
| 1073 |
+
then `ios_base::failbit` is assigned to `err`.
|
| 1074 |
|
| 1075 |
In any case, if stage 2 processing was terminated by the test for
|
| 1076 |
`in == end` then `err |= ios_base::eofbit` is performed.
|
| 1077 |
|
| 1078 |
``` cpp
|
| 1079 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 1080 |
ios_base::iostate& err, bool& val) const;
|
| 1081 |
```
|
| 1082 |
|
| 1083 |
+
*Effects:* If `(str.flags()&ios_base::boolalpha) == 0` then input
|
| 1084 |
proceeds as it would for a `long` except that if a value is being stored
|
| 1085 |
into `val`, the value is determined according to the following: If the
|
| 1086 |
+
value to be stored is 0 then `false` is stored. If the value is `1` then
|
| 1087 |
`true` is stored. Otherwise `true` is stored and `ios_base::failbit` is
|
| 1088 |
assigned to `err`.
|
| 1089 |
|
| 1090 |
Otherwise target sequences are determined “as if” by calling the members
|
| 1091 |
`falsename()` and `truename()` of the facet obtained by
|
| 1092 |
+
`use_facet<numpunct<charT>>(str.getloc())`. Successive characters in the
|
| 1093 |
+
range \[`in`, `end`) (see [[sequence.reqmts]]) are obtained and matched
|
| 1094 |
+
against corresponding positions in the target sequences only as
|
| 1095 |
necessary to identify a unique match. The input iterator `in` is
|
| 1096 |
compared to `end` only when necessary to obtain a character. If a target
|
| 1097 |
sequence is uniquely matched, `val` is set to the corresponding value.
|
| 1098 |
Otherwise `false` is stored and `ios_base::failbit` is assigned to
|
| 1099 |
`err`.
|
|
|
|
| 1101 |
The `in` iterator is always left pointing one position beyond the last
|
| 1102 |
character successfully matched. If `val` is set, then `err` is set to
|
| 1103 |
`str.goodbit`; or to `str.eofbit` if, when seeking another character to
|
| 1104 |
match, it is found that `(in == end)`. If `val` is not set, then `err`
|
| 1105 |
is set to `str.failbit`; or to `(str.failbit|str.eofbit)` if the reason
|
| 1106 |
+
for the failure was that `(in == end)`.
|
| 1107 |
+
|
| 1108 |
+
[*Example 1*: For targets `true`: `"a"` and `false`: `"abb"`, the input
|
| 1109 |
+
sequence `"a"` yields `val == true` and `err == str.eofbit`; the input
|
| 1110 |
+
sequence `"abc"` yields `err = str.failbit`, with `in` ending at the
|
| 1111 |
+
`’c’` element. For targets `true`: `"1"` and `false`: `"0"`, the input
|
| 1112 |
+
sequence `"1"` yields `val == true` and `err == str.goodbit`. For empty
|
| 1113 |
+
targets `("")`, any input sequence yields
|
| 1114 |
+
`err == str.failbit`. — *end example*]
|
| 1115 |
|
| 1116 |
*Returns:* `in`.
|
| 1117 |
|
| 1118 |
#### Class template `num_put` <a id="locale.nm.put">[[locale.nm.put]]</a>
|
| 1119 |
|
| 1120 |
``` cpp
|
| 1121 |
namespace std {
|
| 1122 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 1123 |
class num_put : public locale::facet {
|
| 1124 |
public:
|
| 1125 |
+
using char_type = charT;
|
| 1126 |
+
using iter_type = OutputIterator;
|
| 1127 |
|
| 1128 |
explicit num_put(size_t refs = 0);
|
| 1129 |
|
| 1130 |
iter_type put(iter_type s, ios_base& f, char_type fill, bool v) const;
|
| 1131 |
iter_type put(iter_type s, ios_base& f, char_type fill, long v) const;
|
| 1132 |
iter_type put(iter_type s, ios_base& f, char_type fill, long long v) const;
|
| 1133 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long v) const;
|
| 1134 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long long v) const;
|
| 1135 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, double v) const;
|
| 1136 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, long double v) const;
|
| 1137 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, const void* v) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1138 |
|
| 1139 |
static locale::id id;
|
| 1140 |
|
| 1141 |
protected:
|
| 1142 |
~num_put();
|
| 1143 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, bool v) const;
|
| 1144 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, long v) const;
|
| 1145 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, long long v) const;
|
| 1146 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long) const;
|
| 1147 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long long) const;
|
| 1148 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, double v) const;
|
| 1149 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, long double v) const;
|
| 1150 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, const void* v) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1151 |
};
|
| 1152 |
}
|
| 1153 |
```
|
| 1154 |
|
| 1155 |
The facet `num_put` is used to format numeric values to a character
|
| 1156 |
sequence such as an ostream.
|
| 1157 |
|
| 1158 |
##### `num_put` members <a id="facet.num.put.members">[[facet.num.put.members]]</a>
|
| 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;
|
| 1164 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
|
| 1165 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
|
| 1166 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, double val) const;
|
| 1167 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, long double val) const;
|
| 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 |
##### `num_put` virtual functions <a id="facet.num.put.virtuals">[[facet.num.put.virtuals]]</a>
|
| 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;
|
| 1179 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
|
| 1180 |
+
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 initialized
|
| 1187 |
+
with:
|
| 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` ([[c.files]]) given
|
| 1197 |
+
this conversion specifier for
|
| 1198 |
``` cpp
|
| 1199 |
printf(spec, val)
|
| 1200 |
```
|
| 1201 |
|
| 1202 |
assuming that the current locale is the `"C"` locale.
|
|
|
|
| 1221 |
fmtflags basefield = (flags & (ios_base::basefield));
|
| 1222 |
fmtflags uppercase = (flags & (ios_base::uppercase));
|
| 1223 |
fmtflags floatfield = (flags & (ios_base::floatfield));
|
| 1224 |
fmtflags showpos = (flags & (ios_base::showpos));
|
| 1225 |
fmtflags showbase = (flags & (ios_base::showbase));
|
| 1226 |
+
fmtflags showpoint = (flags & (ios_base::showpoint));
|
| 1227 |
```
|
| 1228 |
|
| 1229 |
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.
|
|
|
|
| 1283 |
Table [[tab:localization.numeric.conversions]].
|
| 1284 |
|
| 1285 |
**Table: Numeric conversions** <a id="tab:localization.numeric.conversions">[tab:localization.numeric.conversions]</a>
|
| 1286 |
|
| 1287 |
| Type(s) | State | `stdio` equivalent |
|
| 1288 |
+
| --------------------- | ----------- | ------------------ |
|
| 1289 |
+
| an integral type | `showpos` | `+` |
|
| 1290 |
+
| | `showbase` | `#` |
|
| 1291 |
+
| a floating-point type | `showpos` | `+` |
|
| 1292 |
+
| | `showpoint` | `#` |
|
| 1293 |
|
| 1294 |
|
| 1295 |
For conversion from a floating-point type, if
|
| 1296 |
`floatfield != (ios_base::fixed | ios_base::scientific)`,
|
| 1297 |
`str.precision()` is specified as precision in the conversion
|
|
|
|
| 1327 |
|
| 1328 |
``` cpp
|
| 1329 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 1330 |
```
|
| 1331 |
|
| 1332 |
+
The location of any padding[^12] is determined according to
|
| 1333 |
Table [[tab:localization.fill.padding]].
|
| 1334 |
|
| 1335 |
**Table: Fill padding** <a id="tab:localization.fill.padding">[tab:localization.fill.padding]</a>
|
| 1336 |
|
| 1337 |
| State | Location |
|
|
|
|
| 1357 |
``` cpp
|
| 1358 |
*out++ = c
|
| 1359 |
```
|
| 1360 |
|
| 1361 |
``` cpp
|
| 1362 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, bool val) const;
|
|
|
|
| 1363 |
```
|
| 1364 |
|
| 1365 |
*Returns:* If `(str.flags() & ios_base::boolalpha) == 0` returns
|
| 1366 |
`do_put(out, str, fill,`
|
| 1367 |
`(int)val)`, otherwise obtains a string `s` as if by
|
|
|
|
| 1382 |
``` cpp
|
| 1383 |
namespace std {
|
| 1384 |
template <class charT>
|
| 1385 |
class numpunct : public locale::facet {
|
| 1386 |
public:
|
| 1387 |
+
using char_type = charT;
|
| 1388 |
+
using string_type = basic_string<charT>;
|
| 1389 |
|
| 1390 |
explicit numpunct(size_t refs = 0);
|
| 1391 |
|
| 1392 |
char_type decimal_point() const;
|
| 1393 |
char_type thousands_sep() const;
|
|
|
|
| 1446 |
|
| 1447 |
``` cpp
|
| 1448 |
char_type decimal_point() const;
|
| 1449 |
```
|
| 1450 |
|
| 1451 |
+
*Returns:* `do_decimal_point()`.
|
| 1452 |
|
| 1453 |
``` cpp
|
| 1454 |
char_type thousands_sep() const;
|
| 1455 |
```
|
| 1456 |
|
| 1457 |
+
*Returns:* `do_thousands_sep()`.
|
| 1458 |
|
| 1459 |
``` cpp
|
| 1460 |
string grouping() const;
|
| 1461 |
```
|
| 1462 |
|
| 1463 |
+
*Returns:* `do_grouping()`.
|
| 1464 |
|
| 1465 |
``` cpp
|
| 1466 |
string_type truename() const;
|
| 1467 |
string_type falsename() const;
|
| 1468 |
```
|
|
|
|
| 1489 |
string do_grouping() const;
|
| 1490 |
```
|
| 1491 |
|
| 1492 |
*Returns:* A basic_string\<char\> `vec` used as a vector of integer
|
| 1493 |
values, in which each element `vec[i]` represents the number of
|
| 1494 |
+
digits[^13] in the group at position `i`, starting with position 0 as
|
| 1495 |
the rightmost group. If `vec.size() <= i`, the number is the same as
|
| 1496 |
+
group `(i - 1)`; if `(i < 0 || vec[i] <= 0 || vec[i] == CHAR_MAX)`, the
|
| 1497 |
+
size of the digit group is unlimited.
|
| 1498 |
|
| 1499 |
The required specializations return the empty string, indicating no
|
| 1500 |
grouping.
|
| 1501 |
|
| 1502 |
``` cpp
|
|
|
|
| 1516 |
namespace std {
|
| 1517 |
template <class charT>
|
| 1518 |
class numpunct_byname : public numpunct<charT> {
|
| 1519 |
// this class is specialized for char and wchar_t.
|
| 1520 |
public:
|
| 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 |
};
|
|
|
|
| 1536 |
``` cpp
|
| 1537 |
namespace std {
|
| 1538 |
template <class charT>
|
| 1539 |
class collate : public locale::facet {
|
| 1540 |
public:
|
| 1541 |
+
using char_type = charT;
|
| 1542 |
+
using string_type = basic_string<charT>;
|
| 1543 |
|
| 1544 |
explicit collate(size_t refs = 0);
|
| 1545 |
|
| 1546 |
int compare(const charT* low1, const charT* high1,
|
| 1547 |
const charT* low2, const charT* high2) const;
|
|
|
|
| 1577 |
``` cpp
|
| 1578 |
int compare(const charT* low1, const charT* high1,
|
| 1579 |
const charT* low2, const charT* high2) const;
|
| 1580 |
```
|
| 1581 |
|
| 1582 |
+
*Returns:* `do_compare(low1, high1, low2, high2)`.
|
| 1583 |
|
| 1584 |
``` cpp
|
| 1585 |
string_type transform(const charT* low, const charT* high) const;
|
| 1586 |
```
|
| 1587 |
|
| 1588 |
+
*Returns:* `do_transform(low, high)`.
|
| 1589 |
|
| 1590 |
``` cpp
|
| 1591 |
long hash(const charT* low, const charT* high) const;
|
| 1592 |
```
|
| 1593 |
|
| 1594 |
+
*Returns:* `do_hash(low, high)`.
|
| 1595 |
|
| 1596 |
##### `collate` virtual functions <a id="locale.collate.virtuals">[[locale.collate.virtuals]]</a>
|
| 1597 |
|
| 1598 |
``` cpp
|
| 1599 |
int do_compare(const charT* low1, const charT* high1,
|
|
|
|
| 1611 |
```
|
| 1612 |
|
| 1613 |
*Returns:* A `basic_string<charT>` value that, compared
|
| 1614 |
lexicographically with the result of calling `transform()` on another
|
| 1615 |
string, yields the same result as calling `do_compare()` on the same two
|
| 1616 |
+
strings.[^14]
|
| 1617 |
|
| 1618 |
``` cpp
|
| 1619 |
long do_hash(const charT* low, const charT* high) const;
|
| 1620 |
```
|
| 1621 |
|
| 1622 |
*Returns:* An integer value equal to the result of calling `hash()` on
|
| 1623 |
any other string for which `do_compare()` returns 0 (equal) when passed
|
| 1624 |
+
the two strings.
|
| 1625 |
+
|
| 1626 |
+
[*Note 1*: The probability that the result equals that for another
|
| 1627 |
string which does not compare equal should be very small, approaching
|
| 1628 |
+
`(1.0/numeric_limits<unsigned long>::max())`. — *end note*]
|
| 1629 |
|
| 1630 |
#### Class template `collate_byname` <a id="locale.collate.byname">[[locale.collate.byname]]</a>
|
| 1631 |
|
| 1632 |
``` cpp
|
| 1633 |
namespace std {
|
| 1634 |
template <class charT>
|
| 1635 |
class collate_byname : public collate<charT> {
|
| 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 |
};
|
|
|
|
| 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:localization.category.facets]]
|
| 1654 |
and [[tab:localization.required.specializations]] (
|
| 1655 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 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 |
|
| 1662 |
``` cpp
|
|
|
|
| 1667 |
};
|
| 1668 |
|
| 1669 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 1670 |
class time_get : public locale::facet, public time_base {
|
| 1671 |
public:
|
| 1672 |
+
using char_type = charT;
|
| 1673 |
+
using iter_type = InputIterator;
|
| 1674 |
|
| 1675 |
explicit time_get(size_t refs = 0);
|
| 1676 |
|
| 1677 |
dateorder date_order() const { return do_date_order(); }
|
| 1678 |
iter_type get_time(iter_type s, iter_type end, ios_base& f,
|
|
|
|
| 1713 |
```
|
| 1714 |
|
| 1715 |
`time_get`
|
| 1716 |
|
| 1717 |
is used to parse a character sequence, extracting components of a time
|
| 1718 |
+
or date into a `struct tm` object. Each `get` member parses a format as
|
| 1719 |
produced by a corresponding format specifier to `time_put<>::put`. If
|
| 1720 |
the sequence being parsed matches the correct format, the corresponding
|
| 1721 |
members of the `struct tm` argument are set to the values used to
|
| 1722 |
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 |
##### `time_get` members <a id="locale.time.get.members">[[locale.time.get.members]]</a>
|
| 1729 |
|
| 1730 |
``` cpp
|
| 1731 |
dateorder date_order() const;
|
| 1732 |
```
|
| 1733 |
|
| 1734 |
+
*Returns:* `do_date_order()`.
|
| 1735 |
|
| 1736 |
``` cpp
|
| 1737 |
iter_type get_time(iter_type s, iter_type end, ios_base& str,
|
| 1738 |
ios_base::iostate& err, tm* t) const;
|
| 1739 |
```
|
| 1740 |
|
| 1741 |
+
*Returns:* `do_get_time(s, end, str, err, t)`.
|
| 1742 |
|
| 1743 |
``` cpp
|
| 1744 |
iter_type get_date(iter_type s, iter_type end, ios_base& str,
|
| 1745 |
ios_base::iostate& err, tm* t) const;
|
| 1746 |
```
|
| 1747 |
|
| 1748 |
+
*Returns:* `do_get_date(s, end, str, err, t)`.
|
| 1749 |
|
| 1750 |
``` cpp
|
| 1751 |
iter_type get_weekday(iter_type s, iter_type end, ios_base& str,
|
| 1752 |
ios_base::iostate& err, tm* t) const;
|
| 1753 |
iter_type get_monthname(iter_type s, iter_type end, ios_base& str,
|
| 1754 |
ios_base::iostate& err, tm* t) const;
|
| 1755 |
```
|
| 1756 |
|
| 1757 |
*Returns:* `do_get_weekday(s, end, str, err, t)` or
|
| 1758 |
+
`do_get_monthname(s, end, str, err, t)`.
|
| 1759 |
|
| 1760 |
``` cpp
|
| 1761 |
iter_type get_year(iter_type s, iter_type end, ios_base& str,
|
| 1762 |
ios_base::iostate& err, tm* t) const;
|
| 1763 |
```
|
| 1764 |
|
| 1765 |
+
*Returns:* `do_get_year(s, end, str, err, t)`.
|
| 1766 |
|
| 1767 |
``` cpp
|
| 1768 |
+
iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
| 1769 |
+
tm* t, char format, char modifier = 0) const;
|
| 1770 |
```
|
| 1771 |
|
| 1772 |
+
*Returns:* `do_get(s, end, f, err, t, format, modifier)`.
|
| 1773 |
|
| 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 |
*Requires:* \[`fmt`, `fmtend`) shall be a valid range.
|
| 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:
|
| 1785 |
|
| 1786 |
+
- The expression `fmt == fmtend` evaluates to `true`.
|
| 1787 |
+
- The expression `err == ios_base::goodbit` evaluates to `false`.
|
| 1788 |
+
- The expression `s == end` evaluates to `true`, in which case the
|
| 1789 |
function evaluates `err = ios_base::eofbit | ios_base::failbit`.
|
| 1790 |
- The next element of `fmt` is equal to `’%’`, optionally followed by a
|
| 1791 |
modifier character, followed by a conversion specifier character,
|
| 1792 |
`format`, together forming a conversion specification valid for the
|
| 1793 |
ISO/IEC 9945 function `strptime`. If the number of elements in the
|
|
|
|
| 1798 |
value of `modifier` is `’\0’` when the optional modifier is absent
|
| 1799 |
from the conversion specification. If `err == ios_base::goodbit` holds
|
| 1800 |
after the evaluation of the expression, the function increments `fmt`
|
| 1801 |
to point just past the end of the conversion specification and
|
| 1802 |
continues looping.
|
| 1803 |
+
- The expression `isspace(*fmt, f.getloc())` evaluates to `true`, in
|
| 1804 |
+
which case the function first increments `fmt` until
|
| 1805 |
+
`fmt == fmtend || !isspace(*fmt, f.getloc())` evaluates to `true`,
|
| 1806 |
+
then advances `s` until `s == end || !isspace(*s, f.getloc())` is
|
| 1807 |
+
`true`, and finally resumes looping.
|
| 1808 |
- The next character read from `s` matches the element pointed to by
|
| 1809 |
`fmt` in a case-insensitive comparison, in which case the function
|
| 1810 |
evaluates `++fmt, ++s` and continues looping. Otherwise, the function
|
| 1811 |
evaluates `err = ios_base::failbit`.
|
| 1812 |
|
| 1813 |
+
[*Note 1*: The function uses the `ctype<charT>` facet installed in
|
| 1814 |
+
`f`’s locale to determine valid whitespace characters. It is unspecified
|
| 1815 |
+
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 |
##### `time_get` virtual functions <a id="locale.time.get.virtuals">[[locale.time.get.virtuals]]</a>
|
| 1822 |
|
| 1823 |
``` cpp
|
| 1824 |
dateorder do_date_order() const;
|
| 1825 |
```
|
| 1826 |
|
| 1827 |
*Returns:* An enumeration value indicating the preferred order of
|
| 1828 |
components for those date formats that are composed of day, month, and
|
| 1829 |
+
year.[^16] Returns `no_order` if the date format specified by `’x’`
|
| 1830 |
contains other variable components (e.g., Julian day, week number, week
|
| 1831 |
day).
|
| 1832 |
|
| 1833 |
``` cpp
|
| 1834 |
iter_type do_get_time(iter_type s, iter_type end, ios_base& str,
|
|
|
|
| 1915 |
appropriate for the ISO/IEC 9945 function `strptime`, formed by
|
| 1916 |
concatenating `’%’`, the `modifier` character, when non-NUL, and the
|
| 1917 |
`format` character. When the concatenation fails to yield a complete
|
| 1918 |
valid directive the function leaves the object pointed to by `t`
|
| 1919 |
unchanged and evaluates `err |= ios_base::failbit`. When `s == end`
|
| 1920 |
+
evaluates to `true` after reading a character the function evaluates
|
| 1921 |
`err |= ios_base::eofbit`.
|
| 1922 |
|
| 1923 |
For complex conversion directives such as `%c`, `%x`, or `%X`, or
|
| 1924 |
directives that involve the optional modifiers `E` or `O`, when the
|
| 1925 |
function is unable to unambiguously determine some or all `struct tm`
|
| 1926 |
members from the input sequence \[`s`, `end`), it evaluates
|
| 1927 |
`err |= ios_base::eofbit`. In such cases the values of those `struct tm`
|
| 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 must zero out the object before invoking the function.
|
| 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 |
|
|
|
|
| 1941 |
``` cpp
|
| 1942 |
namespace std {
|
| 1943 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 1944 |
class time_get_byname : public time_get<charT, InputIterator> {
|
| 1945 |
public:
|
| 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();
|
|
|
|
| 1959 |
``` cpp
|
| 1960 |
namespace std {
|
| 1961 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 1962 |
class time_put : public locale::facet {
|
| 1963 |
public:
|
| 1964 |
+
using char_type = charT;
|
| 1965 |
+
using iter_type = OutputIterator;
|
| 1966 |
|
| 1967 |
explicit time_put(size_t refs = 0);
|
| 1968 |
|
| 1969 |
// the following is implemented in terms of other member functions.
|
| 1970 |
iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb,
|
|
|
|
| 1999 |
interleaved in the output in the order in which they appear in the
|
| 2000 |
pattern. Format sequences are identified by converting each character
|
| 2001 |
`c` to a `char` value as if by `ct.narrow(c, 0)`, where `ct` is a
|
| 2002 |
reference to `ctype<charT>` obtained from `str.getloc()`. The first
|
| 2003 |
character of each sequence is equal to `’%’`, followed by an optional
|
| 2004 |
+
modifier character `mod`[^17] and a format specifier character `spec` as
|
| 2005 |
defined for the function `strftime`. If no modifier character is
|
| 2006 |
present, `mod` is zero. For each valid format sequence identified, calls
|
| 2007 |
`do_put(s, str, fill, t, spec, mod)`.
|
| 2008 |
|
| 2009 |
The second form calls `do_put(s, str, fill, t, format, modifier)`.
|
| 2010 |
|
| 2011 |
+
[*Note 1*: The `fill` argument may be used in the
|
| 2012 |
+
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 |
##### `time_put` virtual functions <a id="locale.time.put.virtuals">[[locale.time.put.virtuals]]</a>
|
|
|
|
| 2024 |
|
| 2025 |
*Effects:* Formats the contents of the parameter `t` into characters
|
| 2026 |
placed on the output sequence `s`. Formatting is controlled by the
|
| 2027 |
parameters `format` and `modifier`, interpreted identically as the
|
| 2028 |
format specifiers in the string argument to the standard library
|
| 2029 |
+
function `strftime()`[^18], except that the sequence of characters
|
| 2030 |
produced for those specifiers that are described as depending on the C
|
| 2031 |
+
locale are instead *implementation-defined*.[^19]
|
| 2032 |
|
| 2033 |
*Returns:* An iterator pointing immediately after the last character
|
| 2034 |
+
produced.
|
| 2035 |
+
|
| 2036 |
+
[*Note 2*: The `fill` argument may be used in the
|
| 2037 |
+
implementation-defined formats or by derivations. A space character is a
|
| 2038 |
+
reasonable default for this argument. — *end note*]
|
| 2039 |
|
| 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 |
class time_put_byname : public time_put<charT, OutputIterator>
|
| 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();
|
|
|
|
| 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:localization.category.facets]]
|
| 2067 |
and [[tab:localization.required.specializations]] (
|
| 2068 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 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 |
|
| 2075 |
``` cpp
|
| 2076 |
namespace std {
|
| 2077 |
+
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
|
|
|
| 2078 |
class money_get : public locale::facet {
|
| 2079 |
public:
|
| 2080 |
+
using char_type = charT;
|
| 2081 |
+
using iter_type = InputIterator;
|
| 2082 |
+
using string_type = basic_string<charT>;
|
| 2083 |
|
| 2084 |
explicit money_get(size_t refs = 0);
|
| 2085 |
|
| 2086 |
iter_type get(iter_type s, iter_type end, bool intl,
|
| 2087 |
ios_base& f, ios_base::iostate& err,
|
|
|
|
| 2110 |
long double& quant) const;
|
| 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 |
##### `money_get` virtual functions <a id="locale.money.get.virtuals">[[locale.money.get.virtuals]]</a>
|
| 2118 |
|
| 2119 |
``` cpp
|
| 2120 |
iter_type do_get(iter_type s, iter_type end, bool intl,
|
|
|
|
| 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’`, inclusive) stored in
|
| 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*]
|
| 2145 |
+
|
| 2146 |
+
If `mp.grouping()` indicates that no thousands separators are permitted,
|
| 2147 |
any such characters are not read, and parsing is terminated at the point
|
| 2148 |
where they first appear. Otherwise, thousands separators are optional;
|
| 2149 |
if present, they are checked for correct placement only after all format
|
| 2150 |
components have been read.
|
| 2151 |
|
|
|
|
| 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
|
| 2166 |
+
the string are required after all the other format components.
|
| 2167 |
+
|
| 2168 |
+
[*Example 2*: If `showbase` is off, then for a `neg` value of `"()"`
|
| 2169 |
+
and a currency symbol of `"L"`, in `"(100 L)"` the `"L"` is consumed;
|
| 2170 |
+
but if `neg` is `"-"`, the `"L"` in `"-100 L"` is not
|
| 2171 |
+
consumed. — *end example*]
|
| 2172 |
+
|
| 2173 |
+
If `pos` or `neg` is empty, the sign component is optional, and if no
|
| 2174 |
+
sign is detected, the result is given the sign that corresponds to the
|
| 2175 |
+
source of the empty string. Otherwise, the character in the indicated
|
| 2176 |
+
position must match the first character of `pos` or `neg`, and the
|
| 2177 |
+
result is given the corresponding sign. If the first character of `pos`
|
| 2178 |
+
is equal to the first character of `neg`, or if both strings are empty,
|
| 2179 |
+
the result is given a positive sign.
|
| 2180 |
|
| 2181 |
Digits in the numeric monetary component are extracted and placed in
|
| 2182 |
`digits`, or into a character buffer `buf1` for conversion to produce a
|
| 2183 |
value for `units`, in the order in which they appear, preceded by a
|
| 2184 |
minus sign if and only if the result is negative. The value `units` is
|
| 2185 |
+
produced as if by[^20]
|
| 2186 |
|
| 2187 |
``` cpp
|
| 2188 |
for (int i = 0; i < n; ++i)
|
| 2189 |
buf2[i] = src[find(atoms, atoms+sizeof(src), buf1[i]) - atoms];
|
| 2190 |
buf2[n] = 0;
|
|
|
|
| 2205 |
|
| 2206 |
#### Class template `money_put` <a id="locale.money.put">[[locale.money.put]]</a>
|
| 2207 |
|
| 2208 |
``` cpp
|
| 2209 |
namespace std {
|
| 2210 |
+
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
|
|
|
| 2211 |
class money_put : public locale::facet {
|
| 2212 |
public:
|
| 2213 |
+
using char_type = charT;
|
| 2214 |
+
using iter_type = OutputIterator;
|
| 2215 |
+
using string_type = basic_string<charT>;
|
| 2216 |
|
| 2217 |
explicit money_put(size_t refs = 0);
|
| 2218 |
|
| 2219 |
iter_type put(iter_type s, bool intl, ios_base& f,
|
| 2220 |
char_type fill, long double units) const;
|
|
|
|
| 2240 |
long double quant) const;
|
| 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 |
##### `money_put` virtual functions <a id="locale.money.put.virtuals">[[locale.money.put.virtuals]]</a>
|
| 2248 |
|
| 2249 |
``` cpp
|
| 2250 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
|
|
| 2279 |
`(str.flags() & str.showbase)` is nonzero. If the number of characters
|
| 2280 |
generated for the specified format is less than the value returned by
|
| 2281 |
`str.width()` on entry to the function, then copies of `fill` are
|
| 2282 |
inserted as necessary to pad to the specified width. For the value `af`
|
| 2283 |
equal to `(str.flags() & str.adjustfield)`, if `(af == str.internal)` is
|
| 2284 |
+
`true`, the fill characters are placed where `none` or `space` appears
|
| 2285 |
+
in the formatting pattern; otherwise if `(af == str.left)` is `true`,
|
| 2286 |
+
they are placed after the other characters; otherwise, they are placed
|
| 2287 |
+
before the other characters.
|
| 2288 |
+
|
| 2289 |
+
[*Note 1*: It is possible, with some combinations of format patterns
|
| 2290 |
+
and flag values, to produce output that cannot be parsed using
|
| 2291 |
+
`num_get<>::get`. — *end note*]
|
| 2292 |
|
| 2293 |
*Returns:* An iterator pointing immediately after the last character
|
| 2294 |
produced.
|
| 2295 |
|
| 2296 |
#### Class template `moneypunct` <a id="locale.moneypunct">[[locale.moneypunct]]</a>
|
|
|
|
| 2304 |
};
|
| 2305 |
|
| 2306 |
template <class charT, bool International = false>
|
| 2307 |
class moneypunct : public locale::facet, public money_base {
|
| 2308 |
public:
|
| 2309 |
+
using char_type = charT;
|
| 2310 |
+
using string_type = basic_string<charT>;
|
| 2311 |
|
| 2312 |
explicit moneypunct(size_t refs = 0);
|
| 2313 |
|
| 2314 |
charT decimal_point() const;
|
| 2315 |
charT thousands_sep() const;
|
|
|
|
| 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`th component of
|
| 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 |
|
| 2351 |
Where `none` or `space` appears, white space is permitted in the format,
|
|
|
|
| 2408 |
pattern pos_format() const;
|
| 2409 |
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 |
##### `moneypunct` virtual functions <a id="locale.moneypunct.virtuals">[[locale.moneypunct.virtuals]]</a>
|
| 2416 |
|
| 2417 |
``` cpp
|
| 2418 |
charT do_decimal_point() const;
|
| 2419 |
```
|
| 2420 |
|
| 2421 |
*Returns:* The radix separator to use in case `do_frac_digits()` is
|
| 2422 |
+
greater than zero.[^22]
|
| 2423 |
|
| 2424 |
``` cpp
|
| 2425 |
charT do_thousands_sep() const;
|
| 2426 |
```
|
| 2427 |
|
| 2428 |
*Returns:* The digit group separator to use in case `do_grouping()`
|
| 2429 |
+
specifies a digit grouping pattern.[^23]
|
| 2430 |
|
| 2431 |
``` cpp
|
| 2432 |
string do_grouping() const;
|
| 2433 |
```
|
| 2434 |
|
| 2435 |
*Returns:* A pattern defined identically as, but not necessarily equal
|
| 2436 |
+
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.[^25]
|
| 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;[^26] `do_negative_sign()` returns the string to
|
| 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.[^27]
|
| 2459 |
|
| 2460 |
``` cpp
|
| 2461 |
pattern do_pos_format() const;
|
| 2462 |
pattern do_neg_format() const;
|
| 2463 |
```
|
|
|
|
| 2465 |
*Returns:* The specializations required in
|
| 2466 |
Table [[tab:localization.required.specializations]] ([[locale.category]]),
|
| 2467 |
namely `moneypunct<char>`, `moneypunct<wchar_t>`,
|
| 2468 |
`moneypunct<char, true>`, and `moneypunct<wchar_t, true>`, return an
|
| 2469 |
object of type `pattern` initialized to
|
| 2470 |
+
`{ symbol, sign, none, value }`.[^28]
|
| 2471 |
|
| 2472 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 2473 |
|
| 2474 |
``` cpp
|
| 2475 |
namespace std {
|
| 2476 |
template <class charT, bool Intl = false>
|
| 2477 |
class moneypunct_byname : public moneypunct<charT, Intl> {
|
| 2478 |
public:
|
| 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();
|
|
|
|
| 2496 |
|
| 2497 |
``` cpp
|
| 2498 |
namespace std {
|
| 2499 |
class messages_base {
|
| 2500 |
public:
|
| 2501 |
+
using catalog = unspecified signed integer type;
|
| 2502 |
};
|
| 2503 |
|
| 2504 |
template <class charT>
|
| 2505 |
class messages : public locale::facet, public messages_base {
|
| 2506 |
public:
|
| 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 basic_string<char>& fn, const locale&) const;
|
| 2513 |
string_type get(catalog c, int set, int msgid,
|
|
|
|
| 2536 |
```
|
| 2537 |
|
| 2538 |
*Returns:* `do_open(name, loc)`.
|
| 2539 |
|
| 2540 |
``` cpp
|
| 2541 |
+
string_type get(catalog cat, int set, int msgid, const string_type& dfault) const;
|
|
|
|
| 2542 |
```
|
| 2543 |
|
| 2544 |
*Returns:* `do_get(cat, set, msgid, dfault)`.
|
| 2545 |
|
| 2546 |
``` cpp
|
|
|
|
| 2550 |
*Effects:* Calls `do_close(cat)`.
|
| 2551 |
|
| 2552 |
##### `messages` virtual functions <a id="locale.messages.virtuals">[[locale.messages.virtuals]]</a>
|
| 2553 |
|
| 2554 |
``` cpp
|
| 2555 |
+
catalog do_open(const basic_string<char>& name, const locale& loc) 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
|
|
|
|
| 2564 |
|
| 2565 |
*Remarks:* The locale argument `loc` is used for character set code
|
| 2566 |
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 |
*Requires:* `cat` shall be a catalog obtained from `open()` and not yet
|
| 2573 |
closed.
|
| 2574 |
|
|
|
|
| 2584 |
closed.
|
| 2585 |
|
| 2586 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 2587 |
|
| 2588 |
*Remarks:* The limit on such resources, if any, is
|
| 2589 |
+
*implementation-defined*.
|
| 2590 |
|
| 2591 |
#### Class template `messages_byname` <a id="locale.messages.byname">[[locale.messages.byname]]</a>
|
| 2592 |
|
| 2593 |
``` cpp
|
| 2594 |
namespace std {
|
| 2595 |
template <class charT>
|
| 2596 |
class messages_byname : public messages<charT> {
|
| 2597 |
public:
|
| 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();
|
|
|
|
| 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>
|
|
|
|
| 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>
|
|
|
|
| 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>
|
|
|
|
| 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>
|
|
|
|
| 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() { }
|
|
|
|
| 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 |
+
|