- tmp/tmplpwcgig3/{from.md → to.md} +499 -825
tmp/tmplpwcgig3/{from.md → to.md}
RENAMED
|
@@ -13,27 +13,26 @@ standard facets, and facilities from the ISO C library, as summarized in
|
|
| 13 |
Table [[tab:localization.lib.summary]].
|
| 14 |
|
| 15 |
**Table: Localization library summary** <a id="tab:localization.lib.summary">[tab:localization.lib.summary]</a>
|
| 16 |
|
| 17 |
| Subclause | | Header |
|
| 18 |
-
| --------------------- | ----------------------------
|
| 19 |
| [[locales]] | Locales | `<locale>` |
|
| 20 |
| [[locale.categories]] | Standard `locale` Categories | |
|
| 21 |
-
| [[locale.stdcvt]] | Standard code conversion facets | `<codecvt>` |
|
| 22 |
| [[c.locales]] | C library locales | `<clocale>` |
|
| 23 |
|
| 24 |
|
| 25 |
## Header `<locale>` synopsis <a id="locale.syn">[[locale.syn]]</a>
|
| 26 |
|
| 27 |
``` cpp
|
| 28 |
namespace std {
|
| 29 |
-
// [locale], locale
|
| 30 |
class locale;
|
| 31 |
template <class Facet> const Facet& use_facet(const locale&);
|
| 32 |
template <class Facet> bool has_facet(const locale&) noexcept;
|
| 33 |
|
| 34 |
-
// [locale.convenience], convenience interfaces
|
| 35 |
template <class charT> bool isspace (charT c, const locale& loc);
|
| 36 |
template <class charT> bool isprint (charT c, const locale& loc);
|
| 37 |
template <class charT> bool iscntrl (charT c, const locale& loc);
|
| 38 |
template <class charT> bool isupper (charT c, const locale& loc);
|
| 39 |
template <class charT> bool islower (charT c, const locale& loc);
|
|
@@ -44,54 +43,57 @@ namespace std {
|
|
| 44 |
template <class charT> bool isalnum (charT c, const locale& loc);
|
| 45 |
template <class charT> bool isgraph (charT c, const locale& loc);
|
| 46 |
template <class charT> bool isblank (charT c, const locale& loc);
|
| 47 |
template <class charT> charT toupper(charT c, const locale& loc);
|
| 48 |
template <class charT> charT tolower(charT c, const locale& loc);
|
| 49 |
-
template <class Codecvt, class Elem = wchar_t,
|
| 50 |
-
class Wide_alloc = std::allocator<Elem>,
|
| 51 |
-
class Byte_alloc = std::allocator<char> > class wstring_convert;
|
| 52 |
-
template <class Codecvt, class Elem = wchar_t,
|
| 53 |
-
class Tr = char_traits<Elem>>{} class wbuffer_convert;
|
| 54 |
|
| 55 |
-
// [category.ctype], ctype
|
| 56 |
class ctype_base;
|
| 57 |
template <class charT> class ctype;
|
| 58 |
template <> class ctype<char>; // specialization
|
| 59 |
template <class charT> class ctype_byname;
|
| 60 |
class codecvt_base;
|
| 61 |
template <class internT, class externT, class stateT> class codecvt;
|
| 62 |
template <class internT, class externT, class stateT> class codecvt_byname;
|
| 63 |
|
| 64 |
-
// [category.numeric], numeric
|
| 65 |
-
template <class charT, class InputIterator = istreambuf_iterator<charT>
|
| 66 |
-
|
| 67 |
-
template <class charT
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
// [category.collate], collation
|
| 71 |
template <class charT> class collate;
|
| 72 |
template <class charT> class collate_byname;
|
| 73 |
|
| 74 |
-
// [category.time], date and time
|
| 75 |
class time_base;
|
| 76 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 77 |
class time_get;
|
| 78 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 79 |
class time_get_byname;
|
| 80 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 81 |
class time_put;
|
| 82 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 83 |
class time_put_byname;
|
| 84 |
|
| 85 |
-
// [category.monetary], money
|
| 86 |
class money_base;
|
| 87 |
-
template <class charT, class InputIterator = istreambuf_iterator<charT>
|
| 88 |
-
|
| 89 |
-
template <class charT,
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
// [category.messages], message retrieval
|
| 93 |
class messages_base;
|
| 94 |
template <class charT> class messages;
|
| 95 |
template <class charT> class messages_byname;
|
| 96 |
}
|
| 97 |
```
|
|
@@ -108,11 +110,11 @@ namespace std {
|
|
| 108 |
class locale {
|
| 109 |
public:
|
| 110 |
// types:
|
| 111 |
class facet;
|
| 112 |
class id;
|
| 113 |
-
|
| 114 |
static const category // values assigned here are for exposition only
|
| 115 |
none = 0,
|
| 116 |
collate = 0x010, ctype = 0x020,
|
| 117 |
monetary = 0x040, numeric = 0x080,
|
| 118 |
time = 0x100, messages = 0x200,
|
|
@@ -154,10 +156,12 @@ it’s just a class interface; at the same time, it’s an index into a
|
|
| 154 |
locale’s set of facets.
|
| 155 |
|
| 156 |
Access to the facets of a `locale` is via two function templates,
|
| 157 |
`use_facet<>` and `has_facet<>`.
|
| 158 |
|
|
|
|
|
|
|
| 159 |
An iostream `operator<<` might be implemented as:[^2]
|
| 160 |
|
| 161 |
``` cpp
|
| 162 |
template <class charT, class traits>
|
| 163 |
basic_ostream<charT, traits>&
|
|
@@ -172,18 +176,22 @@ operator<< (basic_ostream<charT,traits>& s, Date d) {
|
|
| 172 |
}
|
| 173 |
return s;
|
| 174 |
}
|
| 175 |
```
|
| 176 |
|
|
|
|
|
|
|
| 177 |
In the call to `use_facet<Facet>(loc)`, the type argument chooses a
|
| 178 |
facet, making available all members of the named type. If `Facet` is not
|
| 179 |
present in a locale, it throws the standard exception `bad_cast`. A
|
| 180 |
C++program can check if a locale implements a particular facet with the
|
| 181 |
function template `has_facet<Facet>()`. User-defined facets may be
|
| 182 |
installed in a locale, and used identically as may standard facets (
|
| 183 |
[[facets.examples]]).
|
| 184 |
|
|
|
|
|
|
|
| 185 |
All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
|
| 186 |
except that:
|
| 187 |
|
| 188 |
- A member operator template
|
| 189 |
`operator()(const basic_string<C, T, A>&, const basic_string<{}C, T, A>&)`
|
|
@@ -192,10 +200,12 @@ except that:
|
|
| 192 |
- Convenient global interfaces are provided for traditional `ctype`
|
| 193 |
functions such as `isdigit()` and `isspace()`, so that given a locale
|
| 194 |
object `loc` a C++program can call `isspace(c, loc)`. (This eases
|
| 195 |
upgrading existing extractors ([[istream.formatted]]).)
|
| 196 |
|
|
|
|
|
|
|
| 197 |
Once a facet reference is obtained from a locale object by calling
|
| 198 |
`use_facet<>`, that reference remains usable, and the results from
|
| 199 |
member functions of it may be cached and re-used, as long as some locale
|
| 200 |
object refers to that facet.
|
| 201 |
|
|
@@ -218,11 +228,11 @@ implementations are not required to avoid data races on it (
|
|
| 218 |
#### `locale` types <a id="locale.types">[[locale.types]]</a>
|
| 219 |
|
| 220 |
##### Type `locale::category` <a id="locale.category">[[locale.category]]</a>
|
| 221 |
|
| 222 |
``` cpp
|
| 223 |
-
|
| 224 |
```
|
| 225 |
|
| 226 |
*Valid* `category` values include the `locale` member bitmask elements
|
| 227 |
`collate`, `ctype`, `monetary`, `numeric`, `time`, and `messages`, each
|
| 228 |
of which represents a single locale category. In addition, `locale`
|
|
@@ -248,11 +258,11 @@ including at least those shown in Table
|
|
| 248 |
[[tab:localization.category.facets]].
|
| 249 |
|
| 250 |
**Table: Locale category facets** <a id="tab:localization.category.facets">[tab:localization.category.facets]</a>
|
| 251 |
|
| 252 |
| Category | Includes facets |
|
| 253 |
-
| -------- | --------------------------------------------------- |
|
| 254 |
| collate | `collate<char>`, `collate<wchar_t>` |
|
| 255 |
| ctype | `ctype<char>`, `ctype<wchar_t>` |
|
| 256 |
| | `codecvt<char, char, mbstate_t>` |
|
| 257 |
| | `codecvt<char16_t, char, mbstate_t>` |
|
| 258 |
| | `codecvt<char32_t, char, mbstate_t>` |
|
|
@@ -269,22 +279,22 @@ including at least those shown in Table
|
|
| 269 |
| messages | `messages<char>`, `messages<wchar_t>` |
|
| 270 |
|
| 271 |
|
| 272 |
For any locale `loc` either constructed, or returned by
|
| 273 |
`locale::classic()`, and any facet `Facet` shown in Table
|
| 274 |
-
[[tab:localization.category.facets]], `has_facet<Facet>(loc)` is true.
|
| 275 |
Each `locale` member function which takes a `locale::category` argument
|
| 276 |
operates on the corresponding set of facets.
|
| 277 |
|
| 278 |
An implementation is required to provide those specializations for facet
|
| 279 |
templates identified as members of a category, and for those shown in
|
| 280 |
Table [[tab:localization.required.specializations]].
|
| 281 |
|
| 282 |
**Table: Required specializations** <a id="tab:localization.required.specializations">[tab:localization.required.specializations]</a>
|
| 283 |
|
| 284 |
| Category | Includes facets |
|
| 285 |
-
| -------- | ------------------------------------------------------- |
|
| 286 |
| collate | `collate_byname<char>`, `collate_byname<wchar_t>` |
|
| 287 |
| ctype | `ctype_byname<char>`, `ctype_byname<wchar_t>` |
|
| 288 |
| | `codecvt_byname<char, char, mbstate_t>` |
|
| 289 |
| | `codecvt_byname<char16_t, char, mbstate_t>` |
|
| 290 |
| | `codecvt_byname<char32_t, char, mbstate_t>` |
|
|
@@ -316,14 +326,14 @@ In declarations of facets, a template parameter with name
|
|
| 316 |
`InputIterator` or `OutputIterator` indicates the set of all possible
|
| 317 |
specializations on parameters that satisfy the requirements of an Input
|
| 318 |
Iterator or an Output Iterator, respectively (
|
| 319 |
[[iterator.requirements]]). A template parameter with name `C`
|
| 320 |
represents the set of types containing `char`, `wchar_t`, and any other
|
| 321 |
-
implementation-defined character types that satisfy the requirements
|
| 322 |
-
a character on which any of the iostream components can be
|
| 323 |
-
A template parameter with name `International` represents
|
| 324 |
-
possible specializations on a bool parameter.
|
| 325 |
|
| 326 |
##### Class `locale::facet` <a id="locale.facet">[[locale.facet]]</a>
|
| 327 |
|
| 328 |
``` cpp
|
| 329 |
namespace std {
|
|
@@ -335,25 +345,32 @@ namespace std {
|
|
| 335 |
void operator=(const facet&) = delete;
|
| 336 |
};
|
| 337 |
}
|
| 338 |
```
|
| 339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
Template parameters in this Clause which are required to be facets are
|
| 341 |
those named `Facet` in declarations. A program that passes a type that
|
| 342 |
is *not* a facet, or a type that refers to a volatile-qualified facet,
|
| 343 |
as an (explicit or deduced) template parameter to a locale function
|
| 344 |
expecting a facet, is ill-formed. A const-qualified facet is a valid
|
| 345 |
template argument to any locale function that expects a Facet template
|
| 346 |
parameter.
|
| 347 |
|
| 348 |
The `refs` argument to the constructor is used for lifetime management.
|
| 349 |
-
|
| 350 |
-
- For `refs == 0`, the implementation performs
|
| 351 |
`delete static_cast<locale::facet*>(f)` (where `f` is a pointer to the
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
facet.
|
| 355 |
|
| 356 |
Constructors of all facets defined in this Clause take such an argument
|
| 357 |
and pass it along to their `facet` base class constructor. All
|
| 358 |
one-argument constructors defined in this Clause are *explicit*,
|
| 359 |
preventing their participation in automatic conversions.
|
|
@@ -381,21 +398,21 @@ namespace std {
|
|
| 381 |
id(const id&) = delete;
|
| 382 |
};
|
| 383 |
}
|
| 384 |
```
|
| 385 |
|
| 386 |
-
The class locale::id provides identification of a locale facet
|
| 387 |
interface, used as an index for lookup and to encapsulate
|
| 388 |
initialization.
|
| 389 |
|
| 390 |
-
Because facets are used by iostreams, potentially while
|
| 391 |
-
constructors are running, their initialization cannot depend on
|
| 392 |
programmed static initialization. One initialization strategy is for
|
| 393 |
`locale` to initialize each facet’s `id` member the first time an
|
| 394 |
instance of the facet is installed into a locale. This depends only on
|
| 395 |
static storage being zero before constructors run (
|
| 396 |
-
[[basic.start.
|
| 397 |
|
| 398 |
#### `locale` constructors and destructor <a id="locale.cons">[[locale.cons]]</a>
|
| 399 |
|
| 400 |
``` cpp
|
| 401 |
locale() noexcept;
|
|
@@ -404,12 +421,15 @@ locale() noexcept;
|
|
| 404 |
Default constructor: a snapshot of the current global locale.
|
| 405 |
|
| 406 |
*Effects:* Constructs a copy of the argument last passed to
|
| 407 |
`locale::global(locale&)`, if it has been called; else, the resulting
|
| 408 |
facets have virtual function semantics identical to those of
|
| 409 |
-
`locale::classic()`.
|
| 410 |
-
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
``` cpp
|
| 413 |
locale(const locale& other) noexcept;
|
| 414 |
```
|
| 415 |
|
|
@@ -478,11 +498,11 @@ arguments have names.
|
|
| 478 |
const locale& operator=(const locale& other) noexcept;
|
| 479 |
```
|
| 480 |
|
| 481 |
*Effects:* Creates a copy of `other`, replacing the current value.
|
| 482 |
|
| 483 |
-
*Returns:* `*this`
|
| 484 |
|
| 485 |
``` cpp
|
| 486 |
~locale();
|
| 487 |
```
|
| 488 |
|
|
@@ -497,23 +517,20 @@ template <class Facet> locale combine(const locale& other) const;
|
|
| 497 |
*Effects:* Constructs a locale incorporating all facets from `*this`
|
| 498 |
except for that one facet of `other` that is identified by `Facet`.
|
| 499 |
|
| 500 |
*Returns:* The newly created locale.
|
| 501 |
|
| 502 |
-
*Throws:* `runtime_error` if `has_facet<Facet>(other)` is false.
|
| 503 |
|
| 504 |
*Remarks:* The resulting locale has no name.
|
| 505 |
|
| 506 |
``` cpp
|
| 507 |
basic_string<char> name() const;
|
| 508 |
```
|
| 509 |
|
| 510 |
*Returns:* The name of `*this`, if it has one; otherwise, the string
|
| 511 |
-
`"*"`.
|
| 512 |
-
`locale(name().c`\textunderscore`str())` is equivalent to `*this`.
|
| 513 |
-
Details of the contents of the resulting string are otherwise
|
| 514 |
-
implementation-defined.
|
| 515 |
|
| 516 |
#### `locale` operators <a id="locale.operators">[[locale.operators]]</a>
|
| 517 |
|
| 518 |
``` cpp
|
| 519 |
bool operator==(const locale& other) const;
|
|
@@ -525,11 +542,11 @@ copy of the other, or each has a name and the names are identical;
|
|
| 525 |
|
| 526 |
``` cpp
|
| 527 |
bool operator!=(const locale& other) const;
|
| 528 |
```
|
| 529 |
|
| 530 |
-
*Returns:*
|
| 531 |
|
| 532 |
``` cpp
|
| 533 |
template <class charT, class traits, class Allocator>
|
| 534 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 535 |
const basic_string<charT, traits, Allocator>& s2) const;
|
|
@@ -539,24 +556,28 @@ template <class charT, class traits, class Allocator>
|
|
| 539 |
|
| 540 |
*Remarks:* This member operator template (and therefore `locale` itself)
|
| 541 |
satisfies requirements for a comparator predicate template argument
|
| 542 |
(Clause [[algorithms]]) applied to strings.
|
| 543 |
|
| 544 |
-
*Returns:*
|
| 545 |
|
| 546 |
``` cpp
|
| 547 |
-
use_facet<
|
| 548 |
-
|
| 549 |
```
|
| 550 |
|
|
|
|
|
|
|
| 551 |
A vector of strings `v` can be collated according to collation rules in
|
| 552 |
locale `loc` simply by ([[alg.sort]], [[vector]]):
|
| 553 |
|
| 554 |
``` cpp
|
| 555 |
std::sort(v.begin(), v.end(), loc);
|
| 556 |
```
|
| 557 |
|
|
|
|
|
|
|
| 558 |
#### `locale` static members <a id="locale.statics">[[locale.statics]]</a>
|
| 559 |
|
| 560 |
``` cpp
|
| 561 |
static locale global(const locale& loc);
|
| 562 |
```
|
|
@@ -565,18 +586,19 @@ Sets the global locale to its argument.
|
|
| 565 |
|
| 566 |
*Effects:* Causes future calls to the constructor `locale()` to return a
|
| 567 |
copy of the argument. If the argument has a name, does
|
| 568 |
|
| 569 |
``` cpp
|
| 570 |
-
|
| 571 |
```
|
| 572 |
|
| 573 |
otherwise, the effect on the C locale, if any, is
|
| 574 |
*implementation-defined*. No library function other than
|
| 575 |
`locale::global()` shall affect the value returned by `locale()`.
|
| 576 |
-
|
| 577 |
-
|
|
|
|
| 578 |
|
| 579 |
*Returns:* The previous value of `locale()`.
|
| 580 |
|
| 581 |
``` cpp
|
| 582 |
static const locale& classic();
|
|
@@ -608,12 +630,12 @@ copy of `loc` exists.
|
|
| 608 |
|
| 609 |
``` cpp
|
| 610 |
template <class Facet> bool has_facet(const locale& loc) noexcept;
|
| 611 |
```
|
| 612 |
|
| 613 |
-
*Returns:*
|
| 614 |
-
false.
|
| 615 |
|
| 616 |
### Convenience interfaces <a id="locale.convenience">[[locale.convenience]]</a>
|
| 617 |
|
| 618 |
#### Character classification <a id="classification">[[classification]]</a>
|
| 619 |
|
|
@@ -630,19 +652,18 @@ template <class charT> bool isxdigit(charT c, const locale& loc);
|
|
| 630 |
template <class charT> bool isalnum (charT c, const locale& loc);
|
| 631 |
template <class charT> bool isgraph (charT c, const locale& loc);
|
| 632 |
template <class charT> bool isblank (charT c, const locale& loc);
|
| 633 |
```
|
| 634 |
|
| 635 |
-
Each of these functions `
|
| 636 |
-
expression:
|
| 637 |
|
| 638 |
``` cpp
|
| 639 |
use_facet<ctype<charT>>(loc).is(ctype_base::F, c)
|
| 640 |
```
|
| 641 |
|
| 642 |
-
where
|
| 643 |
-
function ([[category.ctype]]).[^
|
| 644 |
|
| 645 |
#### Conversions <a id="conversions">[[conversions]]</a>
|
| 646 |
|
| 647 |
##### Character conversions <a id="conversions.character">[[conversions.character]]</a>
|
| 648 |
|
|
@@ -656,304 +677,10 @@ template <class charT> charT toupper(charT c, const locale& loc);
|
|
| 656 |
template <class charT> charT tolower(charT c, const locale& loc);
|
| 657 |
```
|
| 658 |
|
| 659 |
*Returns:* `use_facet<ctype<charT>>(loc).tolower(c)`.
|
| 660 |
|
| 661 |
-
##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
|
| 662 |
-
|
| 663 |
-
Class template `wstring_convert` performs conversions between a wide
|
| 664 |
-
string and a byte string. It lets you specify a code conversion facet
|
| 665 |
-
(like class template `codecvt`) to perform the conversions, without
|
| 666 |
-
affecting any streams or locales. If you want to use the code conversion
|
| 667 |
-
facet `codecvt_utf8` to output to `cout` a UTF-8 multibyte sequence
|
| 668 |
-
corresponding to a wide string, but you don’t want to alter the locale
|
| 669 |
-
for `cout`, you can write something like:
|
| 670 |
-
|
| 671 |
-
``` cpp
|
| 672 |
-
wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
|
| 673 |
-
std::string mbstring = myconv.to_bytes(L"Hello\n");
|
| 674 |
-
std::cout << mbstring;
|
| 675 |
-
```
|
| 676 |
-
|
| 677 |
-
``` cpp
|
| 678 |
-
namespace std {
|
| 679 |
-
template<class Codecvt, class Elem = wchar_t,
|
| 680 |
-
class Wide_alloc = std::allocator<Elem>,
|
| 681 |
-
class Byte_alloc = std::allocator<char> > class wstring_convert {
|
| 682 |
-
public:
|
| 683 |
-
typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
|
| 684 |
-
typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
|
| 685 |
-
typedef typename Codecvt::state_type state_type;
|
| 686 |
-
typedef typename wide_string::traits_type::int_type int_type;
|
| 687 |
-
|
| 688 |
-
explicit wstring_convert(Codecvt* pcvt = new Codecvt);
|
| 689 |
-
wstring_convert(Codecvt* pcvt, state_type state);
|
| 690 |
-
explicit wstring_convert(const byte_string& byte_err,
|
| 691 |
-
const wide_string& wide_err = wide_string());
|
| 692 |
-
~wstring_convert();
|
| 693 |
-
|
| 694 |
-
wstring_convert(const wstring_convert&) = delete;
|
| 695 |
-
wstring_convert& operator=(const wstring_convert&) = delete;
|
| 696 |
-
|
| 697 |
-
wide_string from_bytes(char byte);
|
| 698 |
-
wide_string from_bytes(const char* ptr);
|
| 699 |
-
wide_string from_bytes(const byte_string& str);
|
| 700 |
-
wide_string from_bytes(const char* first, const char* last);
|
| 701 |
-
|
| 702 |
-
byte_string to_bytes(Elem wchar);
|
| 703 |
-
byte_string to_bytes(const Elem* wptr);
|
| 704 |
-
byte_string to_bytes(const wide_string& wstr);
|
| 705 |
-
byte_string to_bytes(const Elem* first, const Elem* last);
|
| 706 |
-
|
| 707 |
-
size_t converted() const noexcept;
|
| 708 |
-
state_type state() const;
|
| 709 |
-
private:
|
| 710 |
-
byte_string byte_err_string; // exposition only
|
| 711 |
-
wide_string wide_err_string; // exposition only
|
| 712 |
-
Codecvt* cvtptr; // exposition only
|
| 713 |
-
state_type cvtstate; // exposition only
|
| 714 |
-
size_t cvtcount; // exposition only
|
| 715 |
-
};
|
| 716 |
-
}
|
| 717 |
-
```
|
| 718 |
-
|
| 719 |
-
The class template describes an object that controls conversions between
|
| 720 |
-
wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
|
| 721 |
-
Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
|
| 722 |
-
char_traits<char>, Byte_alloc>`. The class template defines the types
|
| 723 |
-
`wide_string` and `byte_string` as synonyms for these two types.
|
| 724 |
-
Conversion between a sequence of `Elem` values (stored in a
|
| 725 |
-
`wide_string` object) and multibyte sequences (stored in a `byte_string`
|
| 726 |
-
object) is performed by an object of class `Codecvt`, which meets the
|
| 727 |
-
requirements of the standard code-conversion facet `std::codecvt<Elem,
|
| 728 |
-
char, std::mbstate_t>`.
|
| 729 |
-
|
| 730 |
-
An object of this class template stores:
|
| 731 |
-
|
| 732 |
-
- `byte_err_string` — a byte string to display on errors
|
| 733 |
-
- `wide_err_string` — a wide string to display on errors
|
| 734 |
-
- `cvtptr` — a pointer to the allocated conversion object (which is
|
| 735 |
-
freed when the `wstring_convert` object is destroyed)
|
| 736 |
-
- `cvtstate` — a conversion state object
|
| 737 |
-
- `cvtcount` — a conversion count
|
| 738 |
-
|
| 739 |
-
``` cpp
|
| 740 |
-
typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
|
| 741 |
-
```
|
| 742 |
-
|
| 743 |
-
The type shall be a synonym for
|
| 744 |
-
`std::basic_string<char, char_traits<char>, Byte_alloc>`
|
| 745 |
-
|
| 746 |
-
``` cpp
|
| 747 |
-
size_t converted() const noexcept;
|
| 748 |
-
```
|
| 749 |
-
|
| 750 |
-
*Returns:* `cvtcount`.
|
| 751 |
-
|
| 752 |
-
``` cpp
|
| 753 |
-
wide_string from_bytes(char byte);
|
| 754 |
-
wide_string from_bytes(const char* ptr);
|
| 755 |
-
wide_string from_bytes(const byte_string& str);
|
| 756 |
-
wide_string from_bytes(const char* first, const char* last);
|
| 757 |
-
```
|
| 758 |
-
|
| 759 |
-
*Effects:* The first member function shall convert the single-element
|
| 760 |
-
sequence `byte` to a wide string. The second member function shall
|
| 761 |
-
convert the null-terminated sequence beginning at `ptr` to a wide
|
| 762 |
-
string. The third member function shall convert the sequence stored in
|
| 763 |
-
`str` to a wide string. The fourth member function shall convert the
|
| 764 |
-
sequence defined by the range \[`first`, `last`) to a wide string.
|
| 765 |
-
|
| 766 |
-
In all cases:
|
| 767 |
-
|
| 768 |
-
- If the `cvtstate` object was not constructed with an explicit value,
|
| 769 |
-
it shall be set to its default value (the initial conversion state)
|
| 770 |
-
before the conversion begins. Otherwise it shall be left unchanged.
|
| 771 |
-
- The number of input elements successfully converted shall be stored in
|
| 772 |
-
`cvtcount`.
|
| 773 |
-
|
| 774 |
-
*Returns:* If no conversion error occurs, the member function shall
|
| 775 |
-
return the converted wide string. Otherwise, if the object was
|
| 776 |
-
constructed with a wide-error string, the member function shall return
|
| 777 |
-
the wide-error string. Otherwise, the member function throws an object
|
| 778 |
-
of class `std::range_error`.
|
| 779 |
-
|
| 780 |
-
``` cpp
|
| 781 |
-
typedef typename wide_string::traits_type::int_type int_type;
|
| 782 |
-
```
|
| 783 |
-
|
| 784 |
-
The type shall be a synonym for `wide_string::traits_type::int_type`.
|
| 785 |
-
|
| 786 |
-
``` cpp
|
| 787 |
-
state_type state() const;
|
| 788 |
-
```
|
| 789 |
-
|
| 790 |
-
returns `cvtstate`.
|
| 791 |
-
|
| 792 |
-
``` cpp
|
| 793 |
-
typedef typename Codecvt::state_type state_type;
|
| 794 |
-
```
|
| 795 |
-
|
| 796 |
-
The type shall be a synonym for `Codecvt::state_type`.
|
| 797 |
-
|
| 798 |
-
``` cpp
|
| 799 |
-
byte_string to_bytes(Elem wchar);
|
| 800 |
-
byte_string to_bytes(const Elem* wptr);
|
| 801 |
-
byte_string to_bytes(const wide_string& wstr);
|
| 802 |
-
byte_string to_bytes(const Elem* first, const Elem* last);
|
| 803 |
-
```
|
| 804 |
-
|
| 805 |
-
*Effects:* The first member function shall convert the single-element
|
| 806 |
-
sequence `wchar` to a byte string. The second member function shall
|
| 807 |
-
convert the null-terminated sequence beginning at `wptr` to a byte
|
| 808 |
-
string. The third member function shall convert the sequence stored in
|
| 809 |
-
`wstr` to a byte string. The fourth member function shall convert the
|
| 810 |
-
sequence defined by the range \[`first`, `last`) to a byte string.
|
| 811 |
-
|
| 812 |
-
In all cases:
|
| 813 |
-
|
| 814 |
-
- If the `cvtstate` object was not constructed with an explicit value,
|
| 815 |
-
it shall be set to its default value (the initial conversion state)
|
| 816 |
-
before the conversion begins. Otherwise it shall be left unchanged.
|
| 817 |
-
- The number of input elements successfully converted shall be stored in
|
| 818 |
-
`cvtcount`.
|
| 819 |
-
|
| 820 |
-
*Returns:* If no conversion error occurs, the member function shall
|
| 821 |
-
return the converted byte string. Otherwise, if the object was
|
| 822 |
-
constructed with a byte-error string, the member function shall return
|
| 823 |
-
the byte-error string. Otherwise, the member function shall throw an
|
| 824 |
-
object of class `std::range_error`.
|
| 825 |
-
|
| 826 |
-
``` cpp
|
| 827 |
-
typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
|
| 828 |
-
```
|
| 829 |
-
|
| 830 |
-
The type shall be a synonym for
|
| 831 |
-
`std::basic_string<Elem, char_traits<Elem>, Wide_alloc>`.
|
| 832 |
-
|
| 833 |
-
``` cpp
|
| 834 |
-
explicit wstring_convert(Codecvt* pcvt = new Codecvt);
|
| 835 |
-
wstring_convert(Codecvt* pcvt, state_type state);
|
| 836 |
-
explicit wstring_convert(const byte_string& byte_err,
|
| 837 |
-
const wide_string& wide_err = wide_string());
|
| 838 |
-
```
|
| 839 |
-
|
| 840 |
-
*Requires:* For the first and second constructors, `pcvt != nullptr`.
|
| 841 |
-
|
| 842 |
-
*Effects:* The first constructor shall store `pcvt` in `cvtptr` and
|
| 843 |
-
default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
|
| 844 |
-
The second constructor shall store `pcvt` in `cvtptr`, `state` in
|
| 845 |
-
`cvtstate`, and default values in `byte_err_string` and
|
| 846 |
-
`wide_err_string`; moreover the stored state shall be retained between
|
| 847 |
-
calls to `from_bytes` and `to_bytes`. The third constructor shall store
|
| 848 |
-
`new Codecvt` in `cvtptr`, `state_type()` in `cvtstate`, `byte_err` in
|
| 849 |
-
`byte_err_string`, and `wide_err` in `wide_err_string`.
|
| 850 |
-
|
| 851 |
-
``` cpp
|
| 852 |
-
~wstring_convert();
|
| 853 |
-
```
|
| 854 |
-
|
| 855 |
-
*Effects:* The destructor shall delete `cvtptr`.
|
| 856 |
-
|
| 857 |
-
##### Buffer conversions <a id="conversions.buffer">[[conversions.buffer]]</a>
|
| 858 |
-
|
| 859 |
-
Class template `wbuffer_convert` looks like a wide stream buffer, but
|
| 860 |
-
performs all its I/O through an underlying byte stream buffer that you
|
| 861 |
-
specify when you construct it. Like class template `wstring_convert`, it
|
| 862 |
-
lets you specify a code conversion facet to perform the conversions,
|
| 863 |
-
without affecting any streams or locales.
|
| 864 |
-
|
| 865 |
-
``` cpp
|
| 866 |
-
namespace std {
|
| 867 |
-
template<class Codecvt,
|
| 868 |
-
class Elem = wchar_t,
|
| 869 |
-
class Tr = std::char_traits<Elem> >
|
| 870 |
-
class wbuffer_convert
|
| 871 |
-
: public std::basic_streambuf<Elem, Tr> {
|
| 872 |
-
public:
|
| 873 |
-
typedef typename Codecvt::state_type state_type;
|
| 874 |
-
|
| 875 |
-
explicit wbuffer_convert(std::streambuf* bytebuf = 0,
|
| 876 |
-
Codecvt* pcvt = new Codecvt,
|
| 877 |
-
state_type state = state_type());
|
| 878 |
-
|
| 879 |
-
~wbuffer_convert();
|
| 880 |
-
|
| 881 |
-
wbuffer_convert(const wbuffer_convert&) = delete;
|
| 882 |
-
wbuffer_convert& operator=(const wbuffer_convert&) = delete;
|
| 883 |
-
|
| 884 |
-
std::streambuf* rdbuf() const;
|
| 885 |
-
std::streambuf* rdbuf(std::streambuf* bytebuf);
|
| 886 |
-
|
| 887 |
-
state_type state() const;
|
| 888 |
-
|
| 889 |
-
private:
|
| 890 |
-
std::streambuf* bufptr; // exposition only
|
| 891 |
-
Codecvt* cvtptr; // exposition only
|
| 892 |
-
state_type cvtstate; // exposition only
|
| 893 |
-
};
|
| 894 |
-
}
|
| 895 |
-
```
|
| 896 |
-
|
| 897 |
-
The class template describes a stream buffer that controls the
|
| 898 |
-
transmission of elements of type `Elem`, whose character traits are
|
| 899 |
-
described by the class `Tr`, to and from a byte stream buffer of type
|
| 900 |
-
`std::streambuf`. Conversion between a sequence of `Elem` values and
|
| 901 |
-
multibyte sequences is performed by an object of class `Codecvt`, which
|
| 902 |
-
shall meet the requirements of the standard code-conversion facet
|
| 903 |
-
`std::codecvt<Elem, char, std::mbstate_t>`.
|
| 904 |
-
|
| 905 |
-
An object of this class template stores:
|
| 906 |
-
|
| 907 |
-
- `bufptr` — a pointer to its underlying byte stream buffer
|
| 908 |
-
- `cvtptr` — a pointer to the allocated conversion object (which is
|
| 909 |
-
freed when the `wbuffer_convert` object is destroyed)
|
| 910 |
-
- `cvtstate` — a conversion state object
|
| 911 |
-
|
| 912 |
-
``` cpp
|
| 913 |
-
state_type state() const;
|
| 914 |
-
```
|
| 915 |
-
|
| 916 |
-
*Returns:* `cvtstate`.
|
| 917 |
-
|
| 918 |
-
``` cpp
|
| 919 |
-
std::streambuf* rdbuf() const;
|
| 920 |
-
```
|
| 921 |
-
|
| 922 |
-
*Returns:* `bufptr`.
|
| 923 |
-
|
| 924 |
-
``` cpp
|
| 925 |
-
std::streambuf* rdbuf(std::streambuf* bytebuf);
|
| 926 |
-
```
|
| 927 |
-
|
| 928 |
-
*Effects:* stores `bytebuf` in `bufptr`.
|
| 929 |
-
|
| 930 |
-
*Returns:* The previous value of `bufptr`.
|
| 931 |
-
|
| 932 |
-
``` cpp
|
| 933 |
-
typedef typename Codecvt::state_type state_type;
|
| 934 |
-
```
|
| 935 |
-
|
| 936 |
-
The type shall be a synonym for `Codecvt::state_type`.
|
| 937 |
-
|
| 938 |
-
``` cpp
|
| 939 |
-
explicit wbuffer_convert(std::streambuf* bytebuf = 0,
|
| 940 |
-
Codecvt* pcvt = new Codecvt, state_type state = state_type());
|
| 941 |
-
```
|
| 942 |
-
|
| 943 |
-
*Requires:* `pcvt != nullptr`.
|
| 944 |
-
|
| 945 |
-
*Effects:* The constructor constructs a stream buffer object,
|
| 946 |
-
initializes `bufptr` to `bytebuf`, initializes `cvtptr` to `pcvt`, and
|
| 947 |
-
initializes `cvtstate` to `state`.
|
| 948 |
-
|
| 949 |
-
``` cpp
|
| 950 |
-
~wbuffer_convert();
|
| 951 |
-
```
|
| 952 |
-
|
| 953 |
-
*Effects:* The destructor shall delete `cvtptr`.
|
| 954 |
-
|
| 955 |
## Standard `locale` categories <a id="locale.categories">[[locale.categories]]</a>
|
| 956 |
|
| 957 |
Each of the standard categories includes a family of facets. Some of
|
| 958 |
these implement formatting or parsing of a datum, for use by standard or
|
| 959 |
users’ iostream operators `<<` and `>>`, as members `put()` and `get()`,
|
|
@@ -977,11 +704,11 @@ another virtual function.
|
|
| 977 |
|
| 978 |
``` cpp
|
| 979 |
namespace std {
|
| 980 |
class ctype_base {
|
| 981 |
public:
|
| 982 |
-
|
| 983 |
|
| 984 |
// numeric values are for exposition only.
|
| 985 |
static const mask space = 1 << 0;
|
| 986 |
static const mask print = 1 << 1;
|
| 987 |
static const mask cntrl = 1 << 2;
|
|
@@ -1005,49 +732,42 @@ The type `mask` is a bitmask type ([[bitmask.types]]).
|
|
| 1005 |
``` cpp
|
| 1006 |
namespace std {
|
| 1007 |
template <class charT>
|
| 1008 |
class ctype : public locale::facet, public ctype_base {
|
| 1009 |
public:
|
| 1010 |
-
|
| 1011 |
|
| 1012 |
explicit ctype(size_t refs = 0);
|
| 1013 |
|
| 1014 |
bool is(mask m, charT c) const;
|
| 1015 |
const charT* is(const charT* low, const charT* high, mask* vec) const;
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
const charT* scan_not(mask m,
|
| 1019 |
-
const charT* low, const charT* high) const;
|
| 1020 |
charT toupper(charT c) const;
|
| 1021 |
const charT* toupper(charT* low, const charT* high) const;
|
| 1022 |
charT tolower(charT c) const;
|
| 1023 |
const charT* tolower(charT* low, const charT* high) const;
|
| 1024 |
|
| 1025 |
charT widen(char c) const;
|
| 1026 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 1027 |
char narrow(charT c, char dfault) const;
|
| 1028 |
-
|
| 1029 |
-
char* to) const;
|
| 1030 |
|
| 1031 |
static locale::id id;
|
| 1032 |
|
| 1033 |
protected:
|
| 1034 |
~ctype();
|
| 1035 |
virtual bool do_is(mask m, charT c) const;
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
const charT* low, const charT* high) const;
|
| 1040 |
-
virtual const charT* do_scan_not(mask m,
|
| 1041 |
-
const charT* low, const charT* high) const;
|
| 1042 |
virtual charT do_toupper(charT) const;
|
| 1043 |
virtual const charT* do_toupper(charT* low, const charT* high) const;
|
| 1044 |
virtual charT do_tolower(charT) const;
|
| 1045 |
virtual const charT* do_tolower(charT* low, const charT* high) const;
|
| 1046 |
virtual charT do_widen(char) const;
|
| 1047 |
-
|
| 1048 |
-
charT* dest) const;
|
| 1049 |
virtual char do_narrow(charT, char dfault) const;
|
| 1050 |
virtual const charT* do_narrow(const charT* low, const charT* high,
|
| 1051 |
char dfault, char* dest) const;
|
| 1052 |
};
|
| 1053 |
}
|
|
@@ -1068,54 +788,54 @@ appropriate to the implementation’s native character set.
|
|
| 1068 |
bool is(mask m, charT c) const;
|
| 1069 |
const charT* is(const charT* low, const charT* high,
|
| 1070 |
mask* vec) const;
|
| 1071 |
```
|
| 1072 |
|
| 1073 |
-
*Returns:* `do_is(m,c)` or `do_is(low,high,vec)`
|
| 1074 |
|
| 1075 |
``` cpp
|
| 1076 |
const charT* scan_is(mask m,
|
| 1077 |
const charT* low, const charT* high) const;
|
| 1078 |
```
|
| 1079 |
|
| 1080 |
-
*Returns:* `do_scan_is(m,low,high)`
|
| 1081 |
|
| 1082 |
``` cpp
|
| 1083 |
const charT* scan_not(mask m,
|
| 1084 |
const charT* low, const charT* high) const;
|
| 1085 |
```
|
| 1086 |
|
| 1087 |
-
*Returns:* `do_scan_not(m,low,high)`
|
| 1088 |
|
| 1089 |
``` cpp
|
| 1090 |
charT toupper(charT) const;
|
| 1091 |
const charT* toupper(charT* low, const charT* high) const;
|
| 1092 |
```
|
| 1093 |
|
| 1094 |
-
*Returns:* `do_toupper(c)` or `do_toupper(low,high)`
|
| 1095 |
|
| 1096 |
``` cpp
|
| 1097 |
charT tolower(charT c) const;
|
| 1098 |
const charT* tolower(charT* low, const charT* high) const;
|
| 1099 |
```
|
| 1100 |
|
| 1101 |
-
*Returns:* `do_tolower(c)` or `do_tolower(low,high)`
|
| 1102 |
|
| 1103 |
``` cpp
|
| 1104 |
charT widen(char c) const;
|
| 1105 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 1106 |
```
|
| 1107 |
|
| 1108 |
-
*Returns:* `do_widen(c)` or `do_widen(low,high,to)`
|
| 1109 |
|
| 1110 |
``` cpp
|
| 1111 |
char narrow(charT c, char dfault) const;
|
| 1112 |
-
const charT* narrow(const charT* low, const charT*, char dfault,
|
| 1113 |
char* to) const;
|
| 1114 |
```
|
| 1115 |
|
| 1116 |
-
*Returns:* `do_narrow(c,dfault)` or `do_narrow(low,high,dfault,to)`
|
| 1117 |
|
| 1118 |
##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
|
| 1119 |
|
| 1120 |
``` cpp
|
| 1121 |
bool do_is(mask m, charT c) const;
|
|
@@ -1124,30 +844,29 @@ const charT* do_is(const charT* low, const charT* high,
|
|
| 1124 |
```
|
| 1125 |
|
| 1126 |
*Effects:* Classifies a character or sequence of characters. For each
|
| 1127 |
argument character, identifies a value `M` of type `ctype_base::mask`.
|
| 1128 |
The second form identifies a value `M` of type `ctype_base::mask` for
|
| 1129 |
-
each `*p` where `(low<=p && p<high)`, and places it into
|
|
|
|
| 1130 |
|
| 1131 |
*Returns:* The first form returns the result of the expression
|
| 1132 |
`(M & m) != 0`; i.e., `true` if the character has the characteristics
|
| 1133 |
specified. The second form returns `high`.
|
| 1134 |
|
| 1135 |
``` cpp
|
| 1136 |
-
const charT* do_scan_is(mask m,
|
| 1137 |
-
const charT* low, const charT* high) const;
|
| 1138 |
```
|
| 1139 |
|
| 1140 |
*Effects:* Locates a character in a buffer that conforms to a
|
| 1141 |
classification `m`.
|
| 1142 |
|
| 1143 |
-
*Returns:* The smallest pointer `p` in the range
|
| 1144 |
-
`is(m,*p)` would return `true`; otherwise, returns `high`.
|
| 1145 |
|
| 1146 |
``` cpp
|
| 1147 |
-
const charT* do_scan_not(mask m,
|
| 1148 |
-
const charT* low, const charT* high) const;
|
| 1149 |
```
|
| 1150 |
|
| 1151 |
*Effects:* Locates a character in a buffer that fails to conform to a
|
| 1152 |
classification `m`.
|
| 1153 |
|
|
@@ -1187,16 +906,16 @@ const char* do_widen(const char* low, const char* high,
|
|
| 1187 |
charT* dest) const;
|
| 1188 |
```
|
| 1189 |
|
| 1190 |
*Effects:* Applies the simplest reasonable transformation from a `char`
|
| 1191 |
value or sequence of `char` values to the corresponding `charT` value or
|
| 1192 |
-
values.[^
|
| 1193 |
required are those in the basic source character set ([[lex.charset]]).
|
| 1194 |
|
| 1195 |
For any named `ctype` category with a `ctype <charT>` facet `ctc` and
|
| 1196 |
valid `ctype_base::mask` value `M`,
|
| 1197 |
-
`(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^
|
| 1198 |
|
| 1199 |
The second form transforms each character `*p` in the range \[`low`,
|
| 1200 |
`high`), placing the result in `dest[p - low]`.
|
| 1201 |
|
| 1202 |
*Returns:* The first form returns the transformed value. The second form
|
|
@@ -1241,11 +960,11 @@ no mapping is readily available. The second form returns `high`.
|
|
| 1241 |
``` cpp
|
| 1242 |
namespace std {
|
| 1243 |
template <class charT>
|
| 1244 |
class ctype_byname : public ctype<charT> {
|
| 1245 |
public:
|
| 1246 |
-
|
| 1247 |
explicit ctype_byname(const char*, size_t refs = 0);
|
| 1248 |
explicit ctype_byname(const string&, size_t refs = 0);
|
| 1249 |
protected:
|
| 1250 |
~ctype_byname();
|
| 1251 |
};
|
|
@@ -1254,14 +973,14 @@ namespace std {
|
|
| 1254 |
|
| 1255 |
#### `ctype` specializations <a id="facet.ctype.special">[[facet.ctype.special]]</a>
|
| 1256 |
|
| 1257 |
``` cpp
|
| 1258 |
namespace std {
|
| 1259 |
-
template <>
|
| 1260 |
-
: public locale::facet, public ctype_base {
|
| 1261 |
public:
|
| 1262 |
-
|
| 1263 |
|
| 1264 |
explicit ctype(const mask* tab = 0, bool del = false,
|
| 1265 |
size_t refs = 0);
|
| 1266 |
|
| 1267 |
bool is(mask m, char c) const;
|
|
@@ -1306,21 +1025,21 @@ namespace std {
|
|
| 1306 |
};
|
| 1307 |
}
|
| 1308 |
```
|
| 1309 |
|
| 1310 |
A specialization `ctype<char>` is provided so that the member functions
|
| 1311 |
-
on type `char` can be implemented `inline`.[^
|
| 1312 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 1313 |
|
| 1314 |
##### `ctype<char>` destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
|
| 1315 |
|
| 1316 |
``` cpp
|
| 1317 |
~ctype();
|
| 1318 |
```
|
| 1319 |
|
| 1320 |
*Effects:* If the constructor’s first argument was nonzero, and its
|
| 1321 |
-
second argument was true, does `delete [] table()`.
|
| 1322 |
|
| 1323 |
##### `ctype<char>` members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
|
| 1324 |
|
| 1325 |
In the following member descriptions, for `unsigned char` values `v`
|
| 1326 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
|
@@ -1330,22 +1049,23 @@ implementation-specific value (possibly different for each such value
|
|
| 1330 |
``` cpp
|
| 1331 |
explicit ctype(const mask* tbl = 0, bool del = false,
|
| 1332 |
size_t refs = 0);
|
| 1333 |
```
|
| 1334 |
|
| 1335 |
-
`tbl` either 0 or an array of at least `table_size`
|
|
|
|
| 1336 |
|
| 1337 |
*Effects:* Passes its `refs` argument to its base class constructor.
|
| 1338 |
|
| 1339 |
``` cpp
|
| 1340 |
bool is(mask m, char c) const;
|
| 1341 |
const char* is(const char* low, const char* high,
|
| 1342 |
mask* vec) const;
|
| 1343 |
```
|
| 1344 |
|
| 1345 |
*Effects:* The second form, for all `*p` in the range \[`low`, `high`),
|
| 1346 |
-
assigns into `vec[p-low]` the value `table()[
|
| 1347 |
|
| 1348 |
*Returns:* The first form returns `table()[(unsigned char)c] & m`; the
|
| 1349 |
second form returns `high`.
|
| 1350 |
|
| 1351 |
``` cpp
|
|
@@ -1407,22 +1127,22 @@ respectively.
|
|
| 1407 |
|
| 1408 |
``` cpp
|
| 1409 |
const mask* table() const noexcept;
|
| 1410 |
```
|
| 1411 |
|
| 1412 |
-
*Returns:* The first constructor argument, if it was
|
| 1413 |
`classic_table()`.
|
| 1414 |
|
| 1415 |
##### `ctype<char>` static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
|
| 1416 |
|
| 1417 |
``` cpp
|
| 1418 |
static const mask* classic_table() noexcept;
|
| 1419 |
```
|
| 1420 |
|
| 1421 |
*Returns:* A pointer to the initial element of an array of size
|
| 1422 |
`table_size` which represents the classifications of characters in the
|
| 1423 |
-
"C" locale.
|
| 1424 |
|
| 1425 |
##### `ctype<char>` virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
|
| 1426 |
|
| 1427 |
``` cpp
|
| 1428 |
char do_toupper(char) const;
|
|
@@ -1453,46 +1173,54 @@ namespace std {
|
|
| 1453 |
};
|
| 1454 |
|
| 1455 |
template <class internT, class externT, class stateT>
|
| 1456 |
class codecvt : public locale::facet, public codecvt_base {
|
| 1457 |
public:
|
| 1458 |
-
|
| 1459 |
-
|
| 1460 |
-
|
| 1461 |
|
| 1462 |
explicit codecvt(size_t refs = 0);
|
| 1463 |
|
| 1464 |
-
|
|
|
|
| 1465 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1466 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1467 |
-
|
|
|
|
|
|
|
| 1468 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1469 |
-
|
|
|
|
|
|
|
| 1470 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1471 |
internT* to, internT* to_end, internT*& to_next) const;
|
|
|
|
| 1472 |
int encoding() const noexcept;
|
| 1473 |
bool always_noconv() const noexcept;
|
| 1474 |
-
|
| 1475 |
-
size_t max) const;
|
| 1476 |
int max_length() const noexcept;
|
| 1477 |
|
| 1478 |
static locale::id id;
|
| 1479 |
|
| 1480 |
protected:
|
| 1481 |
~codecvt();
|
| 1482 |
-
|
|
|
|
| 1483 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1484 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1485 |
-
|
|
|
|
| 1486 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1487 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1488 |
-
|
|
|
|
| 1489 |
externT* to, externT* to_end, externT*& to_next) const;
|
|
|
|
| 1490 |
virtual int do_encoding() const noexcept;
|
| 1491 |
virtual bool do_always_noconv() const noexcept;
|
| 1492 |
-
|
| 1493 |
-
const externT* end, size_t max) const;
|
| 1494 |
virtual int do_max_length() const noexcept;
|
| 1495 |
};
|
| 1496 |
}
|
| 1497 |
```
|
| 1498 |
|
|
@@ -1506,103 +1234,105 @@ mapped between.
|
|
| 1506 |
|
| 1507 |
The specializations required in Table
|
| 1508 |
[[tab:localization.category.facets]] ([[locale.category]]) convert the
|
| 1509 |
implementation-defined native character set.
|
| 1510 |
`codecvt<char, char, mbstate_t>` implements a degenerate conversion; it
|
| 1511 |
-
does not convert at all. The specialization
|
| 1512 |
-
`char, mbstate_t>` converts between the UTF-16 and
|
| 1513 |
-
and the specialization `codecvt`
|
| 1514 |
-
between the UTF-32 and UTF-8
|
| 1515 |
-
`codecvt<wchar_t,char,mbstate_t>` converts between the
|
| 1516 |
-
sets for narrow and wide characters. Specializations on
|
| 1517 |
-
perform conversion between encodings known to the library
|
| 1518 |
-
Other encodings can be converted by specializing on a
|
| 1519 |
-
`stateT` type. Objects of type `stateT` can contain any
|
| 1520 |
-
useful to communicate to or from the specialized `do_in`
|
| 1521 |
-
members.
|
| 1522 |
|
| 1523 |
##### `codecvt` members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
|
| 1524 |
|
| 1525 |
``` cpp
|
| 1526 |
-
result out(
|
|
|
|
| 1527 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1528 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1529 |
```
|
| 1530 |
|
| 1531 |
*Returns:*
|
| 1532 |
-
`do_out(state, from, from_end, from_next, to, to_end, to_next)`
|
| 1533 |
|
| 1534 |
``` cpp
|
| 1535 |
-
result unshift(stateT& state,
|
| 1536 |
-
externT* to, externT* to_end, externT*& to_next) const;
|
| 1537 |
```
|
| 1538 |
|
| 1539 |
-
*Returns:* `do_unshift(state, to, to_end, to_next)`
|
| 1540 |
|
| 1541 |
``` cpp
|
| 1542 |
-
result in(
|
|
|
|
| 1543 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1544 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1545 |
```
|
| 1546 |
|
| 1547 |
*Returns:*
|
| 1548 |
-
`do_in(state, from, from_end, from_next, to, to_end, to_next)`
|
| 1549 |
|
| 1550 |
``` cpp
|
| 1551 |
int encoding() const noexcept;
|
| 1552 |
```
|
| 1553 |
|
| 1554 |
-
*Returns:* `do_encoding()`
|
| 1555 |
|
| 1556 |
``` cpp
|
| 1557 |
bool always_noconv() const noexcept;
|
| 1558 |
```
|
| 1559 |
|
| 1560 |
-
*Returns:* `do_always_noconv()`
|
| 1561 |
|
| 1562 |
``` cpp
|
| 1563 |
-
int length(stateT& state, const externT* from, const externT* from_end,
|
| 1564 |
-
size_t max) const;
|
| 1565 |
```
|
| 1566 |
|
| 1567 |
-
*Returns:* `do_length(state, from,from_end,max)`
|
| 1568 |
|
| 1569 |
``` cpp
|
| 1570 |
int max_length() const noexcept;
|
| 1571 |
```
|
| 1572 |
|
| 1573 |
-
*Returns:* `do_max_length()`
|
| 1574 |
|
| 1575 |
##### `codecvt` virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
|
| 1576 |
|
| 1577 |
``` cpp
|
| 1578 |
-
result do_out(
|
|
|
|
| 1579 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1580 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1581 |
|
| 1582 |
-
result do_in(
|
|
|
|
| 1583 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1584 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1585 |
```
|
| 1586 |
|
| 1587 |
-
*
|
| 1588 |
`true`; `state` initialized, if at the beginning of a sequence, or else
|
| 1589 |
equal to the result of converting the preceding characters in the
|
| 1590 |
sequence.
|
| 1591 |
|
| 1592 |
-
*Effects:* Translates characters in the source range
|
| 1593 |
-
placing the results in sequential positions starting at
|
| 1594 |
-
`to`. Converts no more than `(from_end-from)` source
|
| 1595 |
-
stores no more than `(to_end-to)` destination elements.
|
| 1596 |
|
| 1597 |
Stops if it encounters a character it cannot convert. It always leaves
|
| 1598 |
the `from_next` and `to_next` pointers pointing one beyond the last
|
| 1599 |
element successfully converted. If returns `noconv`, `internT` and
|
| 1600 |
`externT` are the same type and the converted sequence is identical to
|
| 1601 |
-
the input sequence
|
| 1602 |
-
the value of `state` is unchanged, and there are no changes to the
|
| 1603 |
-
values in
|
| 1604 |
|
| 1605 |
A `codecvt` facet that is used by `basic_filebuf` ([[file.streams]])
|
| 1606 |
shall have the property that if
|
| 1607 |
|
| 1608 |
``` cpp
|
|
@@ -1625,105 +1355,107 @@ would return `ok`, where `to != to_end`, then
|
|
| 1625 |
|
| 1626 |
``` cpp
|
| 1627 |
do_in(state, from, from_end, from_next, to, to + 1, to_next)
|
| 1628 |
```
|
| 1629 |
|
| 1630 |
-
shall also return `ok`.[^
|
| 1631 |
-
return `ok` or `partial` and set `from_next == from` and
|
| 1632 |
-
`to_next != to`.
|
| 1633 |
|
| 1634 |
-
*
|
| 1635 |
-
|
| 1636 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1637 |
|
| 1638 |
*Returns:* An enumeration value, as summarized in
|
| 1639 |
Table [[tab:localization.convert.result.values.out.in]].
|
| 1640 |
|
| 1641 |
**Table: `do_in/do_out` result values** <a id="tab:localization.convert.result.values.out.in">[tab:localization.convert.result.values.out.in]</a>
|
| 1642 |
|
| 1643 |
| Value | Meaning |
|
| 1644 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 1645 |
| `ok` | completed the conversion |
|
| 1646 |
| `partial` | not all source characters converted |
|
| 1647 |
-
| `error` | encountered a character in
|
| 1648 |
| `noconv` | `internT` and `externT` are the same type, and input sequence is identical to converted sequence |
|
| 1649 |
|
| 1650 |
|
| 1651 |
-
A return value of `partial`, if `(from_next==from_end)`, indicates
|
| 1652 |
-
either the destination sequence has not absorbed all the available
|
| 1653 |
destination elements, or that additional source elements are needed
|
| 1654 |
before another destination element can be produced.
|
| 1655 |
|
| 1656 |
``` cpp
|
| 1657 |
-
result do_unshift(stateT& state,
|
| 1658 |
-
externT* to, externT* to_end, externT*& to_next) const;
|
| 1659 |
```
|
| 1660 |
|
| 1661 |
-
*Requires:* `(to <= to_end)` well defined and true; state initialized,
|
| 1662 |
if at the beginning of a sequence, or else equal to the result of
|
| 1663 |
converting the preceding characters in the sequence.
|
| 1664 |
|
| 1665 |
*Effects:* Places characters starting at `to` that should be appended to
|
| 1666 |
-
terminate a sequence when the current `stateT` is given by `state`.[^
|
| 1667 |
Stores no more than `(to_end - to)` destination elements, and leaves the
|
| 1668 |
`to_next` pointer pointing one beyond the last element successfully
|
| 1669 |
stored.
|
| 1670 |
|
| 1671 |
*Returns:* An enumeration value, as summarized in
|
| 1672 |
Table [[tab:localization.convert.result.values.unshift]].
|
| 1673 |
|
| 1674 |
**Table: `do_unshift` result values** <a id="tab:localization.convert.result.values.unshift">[tab:localization.convert.result.values.unshift]</a>
|
| 1675 |
|
| 1676 |
| Value | Meaning |
|
| 1677 |
-
| --------- | ------------------------------------------------------------------------------------------------------------------ |
|
| 1678 |
| `ok` | completed the sequence |
|
| 1679 |
| `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
|
| 1680 |
| `error` | an unspecified error has occurred |
|
| 1681 |
| `noconv` | no termination is needed for this `state_type` |
|
| 1682 |
|
| 1683 |
``` cpp
|
| 1684 |
int do_encoding() const noexcept;
|
| 1685 |
```
|
| 1686 |
|
| 1687 |
-
*Returns:* -1 if the encoding of the `externT` sequence is
|
| 1688 |
state-dependent; else the constant number of `externT` characters needed
|
| 1689 |
-
to produce an internal character; or 0 if this number is not a
|
| 1690 |
-
constant.[^
|
| 1691 |
|
| 1692 |
``` cpp
|
| 1693 |
bool do_always_noconv() const noexcept;
|
| 1694 |
```
|
| 1695 |
|
| 1696 |
*Returns:* `true` if `do_in()` and `do_out()` return `noconv` for all
|
| 1697 |
valid argument values. `codecvt<char, char, mbstate_t>` returns `true`.
|
| 1698 |
|
| 1699 |
``` cpp
|
| 1700 |
-
int do_length(stateT& state, const externT* from, const externT* from_end,
|
| 1701 |
-
size_t max) const;
|
| 1702 |
```
|
| 1703 |
|
| 1704 |
-
*
|
| 1705 |
initialized, if at the beginning of a sequence, or else equal to the
|
| 1706 |
result of converting the preceding characters in the sequence.
|
| 1707 |
|
| 1708 |
*Effects:* The effect on the `state` argument is “as if” it called
|
| 1709 |
`do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
|
| 1710 |
to a buffer of at least `max` elements.
|
| 1711 |
|
| 1712 |
*Returns:* `(from_next-from)` where `from_next` is the largest value in
|
| 1713 |
-
the range
|
| 1714 |
range \[`from`, `from_next`) represents `max` or fewer valid complete
|
| 1715 |
characters of type `internT`. The specialization
|
| 1716 |
`codecvt<char, char, mbstate_t>`, returns the lesser of `max` and
|
| 1717 |
`(from_end-from)`.
|
| 1718 |
|
| 1719 |
``` cpp
|
| 1720 |
int do_max_length() const noexcept;
|
| 1721 |
```
|
| 1722 |
|
| 1723 |
*Returns:* The maximum value that `do_length(state, from, from_end, 1)`
|
| 1724 |
-
can return for any valid range
|
| 1725 |
`state`. The specialization
|
| 1726 |
`codecvt<char, char, mbstate_t>::do_max_length()` returns 1.
|
| 1727 |
|
| 1728 |
#### Class template `codecvt_byname` <a id="locale.codecvt.byname">[[locale.codecvt.byname]]</a>
|
| 1729 |
|
|
@@ -1743,11 +1475,11 @@ namespace std {
|
|
| 1743 |
### The numeric category <a id="category.numeric">[[category.numeric]]</a>
|
| 1744 |
|
| 1745 |
The classes `num_get<>` and `num_put<>` handle numeric formatting and
|
| 1746 |
parsing. Virtual functions are provided for several numeric types.
|
| 1747 |
Implementations may (but are not required to) delegate extraction of
|
| 1748 |
-
smaller types to extractors for larger types.[^
|
| 1749 |
|
| 1750 |
All specifications of member functions for `num_put` and `num_get` in
|
| 1751 |
the subclauses of [[category.numeric]] only apply to the
|
| 1752 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 1753 |
and [[tab:localization.required.specializations]] (
|
|
@@ -1768,12 +1500,12 @@ values ([[istream.formatted.reqmts]], [[ostream.formatted.reqmts]]).
|
|
| 1768 |
``` cpp
|
| 1769 |
namespace std {
|
| 1770 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 1771 |
class num_get : public locale::facet {
|
| 1772 |
public:
|
| 1773 |
-
|
| 1774 |
-
|
| 1775 |
|
| 1776 |
explicit num_get(size_t refs = 0);
|
| 1777 |
|
| 1778 |
iter_type get(iter_type in, iter_type end, ios_base&,
|
| 1779 |
ios_base::iostate& err, bool& v) const;
|
|
@@ -1945,12 +1677,12 @@ as indicated in Table [[tab:localization.length.modifier.in]].
|
|
| 1945 |
| `double` | `l` |
|
| 1946 |
| `long double` | `L` |
|
| 1947 |
|
| 1948 |
- **Stage 2:**
|
| 1949 |
|
| 1950 |
-
If `in==end` then stage 2 terminates. Otherwise a `charT` is taken
|
| 1951 |
-
`in` and local variables are initialized as if by
|
| 1952 |
|
| 1953 |
``` cpp
|
| 1954 |
char_type ct = *in;
|
| 1955 |
char c = src[find(atoms, atoms + sizeof(src) - 1, ct) - atoms];
|
| 1956 |
if (ct == use_facet<numpunct<charT>>(loc).decimal_point())
|
|
@@ -1968,11 +1700,11 @@ char_type atoms[sizeof(src)];
|
|
| 1968 |
use_facet<ctype<charT>>(loc).widen(src, src + sizeof(src), atoms);
|
| 1969 |
```
|
| 1970 |
|
| 1971 |
for this value of `loc`.
|
| 1972 |
|
| 1973 |
-
If `discard` is true, then if `’.’` has not yet been accumulated, then
|
| 1974 |
the position of the character is remembered, but the character is
|
| 1975 |
otherwise ignored. Otherwise, if `’.’` has already been accumulated, the
|
| 1976 |
character is discarded and Stage 2 terminates. If it is not discarded,
|
| 1977 |
then a check is made to determine if `c` is allowed as the next
|
| 1978 |
character of an input field of the conversion specifier returned by
|
|
@@ -1989,54 +1721,60 @@ header `<cstdlib>`:
|
|
| 1989 |
|
| 1990 |
- For a signed integer value, the function `strtoll`.
|
| 1991 |
|
| 1992 |
- For an unsigned integer value, the function `strtoull`.
|
| 1993 |
|
| 1994 |
-
- For a
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1995 |
|
| 1996 |
The numeric value to be stored can be one of:
|
| 1997 |
|
| 1998 |
-
- zero, if the conversion function
|
| 1999 |
-
`ios_base::failbit` is assigned to `err`.
|
| 2000 |
|
| 2001 |
-
- the most positive representable value, if the field
|
| 2002 |
-
|
| 2003 |
-
|
| 2004 |
|
| 2005 |
-
- the most
|
| 2006 |
-
|
| 2007 |
-
|
| 2008 |
|
| 2009 |
- the converted value, otherwise.
|
| 2010 |
|
| 2011 |
-
The resultant numeric value is stored in `val`.
|
|
|
|
|
|
|
|
|
|
| 2012 |
|
| 2013 |
Digit grouping is checked. That is, the positions of discarded
|
| 2014 |
separators is examined for consistency with
|
| 2015 |
-
`use_facet<numpunct<charT>
|
| 2016 |
-
|
| 2017 |
|
| 2018 |
In any case, if stage 2 processing was terminated by the test for
|
| 2019 |
`in == end` then `err |= ios_base::eofbit` is performed.
|
| 2020 |
|
| 2021 |
``` cpp
|
| 2022 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 2023 |
ios_base::iostate& err, bool& val) const;
|
| 2024 |
```
|
| 2025 |
|
| 2026 |
-
*Effects:* If `(str
|
| 2027 |
proceeds as it would for a `long` except that if a value is being stored
|
| 2028 |
into `val`, the value is determined according to the following: If the
|
| 2029 |
-
value to be stored is 0 then `false` is stored. If the value is 1 then
|
| 2030 |
`true` is stored. Otherwise `true` is stored and `ios_base::failbit` is
|
| 2031 |
assigned to `err`.
|
| 2032 |
|
| 2033 |
Otherwise target sequences are determined “as if” by calling the members
|
| 2034 |
`falsename()` and `truename()` of the facet obtained by
|
| 2035 |
-
`use_facet<numpunct<charT>
|
| 2036 |
-
|
| 2037 |
-
|
| 2038 |
necessary to identify a unique match. The input iterator `in` is
|
| 2039 |
compared to `end` only when necessary to obtain a character. If a target
|
| 2040 |
sequence is uniquely matched, `val` is set to the corresponding value.
|
| 2041 |
Otherwise `false` is stored and `ios_base::failbit` is assigned to
|
| 2042 |
`err`.
|
|
@@ -2044,127 +1782,102 @@ Otherwise `false` is stored and `ios_base::failbit` is assigned to
|
|
| 2044 |
The `in` iterator is always left pointing one position beyond the last
|
| 2045 |
character successfully matched. If `val` is set, then `err` is set to
|
| 2046 |
`str.goodbit`; or to `str.eofbit` if, when seeking another character to
|
| 2047 |
match, it is found that `(in == end)`. If `val` is not set, then `err`
|
| 2048 |
is set to `str.failbit`; or to `(str.failbit|str.eofbit)` if the reason
|
| 2049 |
-
for the failure was that `(in == end)`.
|
| 2050 |
-
|
| 2051 |
-
|
| 2052 |
-
`
|
| 2053 |
-
|
| 2054 |
-
`
|
| 2055 |
-
|
|
|
|
|
|
|
| 2056 |
|
| 2057 |
*Returns:* `in`.
|
| 2058 |
|
| 2059 |
#### Class template `num_put` <a id="locale.nm.put">[[locale.nm.put]]</a>
|
| 2060 |
|
| 2061 |
``` cpp
|
| 2062 |
namespace std {
|
| 2063 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2064 |
class num_put : public locale::facet {
|
| 2065 |
public:
|
| 2066 |
-
|
| 2067 |
-
|
| 2068 |
|
| 2069 |
explicit num_put(size_t refs = 0);
|
| 2070 |
|
| 2071 |
iter_type put(iter_type s, ios_base& f, char_type fill, bool v) const;
|
| 2072 |
iter_type put(iter_type s, ios_base& f, char_type fill, long v) const;
|
| 2073 |
iter_type put(iter_type s, ios_base& f, char_type fill, long long v) const;
|
| 2074 |
-
|
| 2075 |
-
|
| 2076 |
-
|
| 2077 |
-
|
| 2078 |
-
|
| 2079 |
-
double v) const;
|
| 2080 |
-
iter_type put(iter_type s, ios_base& f, char_type fill,
|
| 2081 |
-
long double v) const;
|
| 2082 |
-
iter_type put(iter_type s, ios_base& f, char_type fill,
|
| 2083 |
-
const void* v) const;
|
| 2084 |
|
| 2085 |
static locale::id id;
|
| 2086 |
|
| 2087 |
protected:
|
| 2088 |
~num_put();
|
| 2089 |
-
|
| 2090 |
-
|
| 2091 |
-
|
| 2092 |
-
|
| 2093 |
-
|
| 2094 |
-
|
| 2095 |
-
|
| 2096 |
-
|
| 2097 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 2098 |
-
unsigned long long) const;
|
| 2099 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 2100 |
-
double v) const;
|
| 2101 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 2102 |
-
long double v) const;
|
| 2103 |
-
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
|
| 2104 |
-
const void* v) const;
|
| 2105 |
};
|
| 2106 |
}
|
| 2107 |
```
|
| 2108 |
|
| 2109 |
The facet `num_put` is used to format numeric values to a character
|
| 2110 |
sequence such as an ostream.
|
| 2111 |
|
| 2112 |
##### `num_put` members <a id="facet.num.put.members">[[facet.num.put.members]]</a>
|
| 2113 |
|
| 2114 |
``` cpp
|
| 2115 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2116 |
-
|
| 2117 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2118 |
-
|
| 2119 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2120 |
-
|
| 2121 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2122 |
-
|
| 2123 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2124 |
-
unsigned long long val) const;
|
| 2125 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2126 |
-
double val) const;
|
| 2127 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2128 |
-
long double val) const;
|
| 2129 |
-
iter_type put(iter_type out, ios_base& str, char_type fill,
|
| 2130 |
-
const void* val) const;
|
| 2131 |
```
|
| 2132 |
|
| 2133 |
*Returns:* `do_put(out, str, fill, val)`.
|
| 2134 |
|
| 2135 |
##### `num_put` virtual functions <a id="facet.num.put.virtuals">[[facet.num.put.virtuals]]</a>
|
| 2136 |
|
| 2137 |
``` cpp
|
| 2138 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2139 |
-
|
| 2140 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2141 |
-
|
| 2142 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2143 |
-
|
| 2144 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2145 |
-
unsigned long long val) const;
|
| 2146 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2147 |
-
double val) const;
|
| 2148 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2149 |
-
long double val) const;
|
| 2150 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2151 |
-
const void* val) const;
|
| 2152 |
```
|
| 2153 |
|
| 2154 |
*Effects:* Writes characters to the sequence `out`, formatting `val` as
|
| 2155 |
-
desired. In the following description, a local variable initialized
|
|
|
|
| 2156 |
|
| 2157 |
``` cpp
|
| 2158 |
locale loc = str.getloc();
|
| 2159 |
```
|
| 2160 |
|
| 2161 |
The details of this operation occur in several stages:
|
| 2162 |
|
| 2163 |
-
- Stage 1: Determine a printf conversion specifier `spec` and
|
| 2164 |
-
|
| 2165 |
-
|
| 2166 |
``` cpp
|
| 2167 |
printf(spec, val)
|
| 2168 |
```
|
| 2169 |
|
| 2170 |
assuming that the current locale is the `"C"` locale.
|
|
@@ -2189,10 +1902,11 @@ fmtflags flags = str.flags() ;
|
|
| 2189 |
fmtflags basefield = (flags & (ios_base::basefield));
|
| 2190 |
fmtflags uppercase = (flags & (ios_base::uppercase));
|
| 2191 |
fmtflags floatfield = (flags & (ios_base::floatfield));
|
| 2192 |
fmtflags showpos = (flags & (ios_base::showpos));
|
| 2193 |
fmtflags showbase = (flags & (ios_base::showbase));
|
|
|
|
| 2194 |
```
|
| 2195 |
|
| 2196 |
All tables used in describing stage 1 are ordered. That is, the first
|
| 2197 |
line whose condition is true applies. A line without a condition is the
|
| 2198 |
default behavior when none of the earlier lines apply.
|
|
@@ -2250,15 +1964,15 @@ qualifiers prepended as indicated in
|
|
| 2250 |
Table [[tab:localization.numeric.conversions]].
|
| 2251 |
|
| 2252 |
**Table: Numeric conversions** <a id="tab:localization.numeric.conversions">[tab:localization.numeric.conversions]</a>
|
| 2253 |
|
| 2254 |
| Type(s) | State | `stdio` equivalent |
|
| 2255 |
-
| --------------------- | -----------
|
| 2256 |
-
| an integral type | `
|
| 2257 |
-
| | `
|
| 2258 |
-
| a floating-point type | `
|
| 2259 |
-
| | `
|
| 2260 |
|
| 2261 |
|
| 2262 |
For conversion from a floating-point type, if
|
| 2263 |
`floatfield != (ios_base::fixed | ios_base::scientific)`,
|
| 2264 |
`str.precision()` is specified as precision in the conversion
|
|
@@ -2294,11 +2008,11 @@ A local variable is initialized as
|
|
| 2294 |
|
| 2295 |
``` cpp
|
| 2296 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 2297 |
```
|
| 2298 |
|
| 2299 |
-
The location of any padding[^
|
| 2300 |
Table [[tab:localization.fill.padding]].
|
| 2301 |
|
| 2302 |
**Table: Fill padding** <a id="tab:localization.fill.padding">[tab:localization.fill.padding]</a>
|
| 2303 |
|
| 2304 |
| State | Location |
|
|
@@ -2324,12 +2038,11 @@ The sequence of `charT`’s at the end of stage 3 are output via
|
|
| 2324 |
``` cpp
|
| 2325 |
*out++ = c
|
| 2326 |
```
|
| 2327 |
|
| 2328 |
``` cpp
|
| 2329 |
-
iter_type do_put(iter_type out, ios_base& str, char_type fill,
|
| 2330 |
-
bool val) const;
|
| 2331 |
```
|
| 2332 |
|
| 2333 |
*Returns:* If `(str.flags() & ios_base::boolalpha) == 0` returns
|
| 2334 |
`do_put(out, str, fill,`
|
| 2335 |
`(int)val)`, otherwise obtains a string `s` as if by
|
|
@@ -2350,12 +2063,12 @@ and returns `out`.
|
|
| 2350 |
``` cpp
|
| 2351 |
namespace std {
|
| 2352 |
template <class charT>
|
| 2353 |
class numpunct : public locale::facet {
|
| 2354 |
public:
|
| 2355 |
-
|
| 2356 |
-
|
| 2357 |
|
| 2358 |
explicit numpunct(size_t refs = 0);
|
| 2359 |
|
| 2360 |
char_type decimal_point() const;
|
| 2361 |
char_type thousands_sep() const;
|
|
@@ -2414,23 +2127,23 @@ thousands-separators, no grouping constraint is applied.
|
|
| 2414 |
|
| 2415 |
``` cpp
|
| 2416 |
char_type decimal_point() const;
|
| 2417 |
```
|
| 2418 |
|
| 2419 |
-
*Returns:* `do_decimal_point()`
|
| 2420 |
|
| 2421 |
``` cpp
|
| 2422 |
char_type thousands_sep() const;
|
| 2423 |
```
|
| 2424 |
|
| 2425 |
-
*Returns:* `do_thousands_sep()`
|
| 2426 |
|
| 2427 |
``` cpp
|
| 2428 |
string grouping() const;
|
| 2429 |
```
|
| 2430 |
|
| 2431 |
-
*Returns:* `do_grouping()`
|
| 2432 |
|
| 2433 |
``` cpp
|
| 2434 |
string_type truename() const;
|
| 2435 |
string_type falsename() const;
|
| 2436 |
```
|
|
@@ -2457,14 +2170,14 @@ required specializations return `’,’` or `L’,’`.
|
|
| 2457 |
string do_grouping() const;
|
| 2458 |
```
|
| 2459 |
|
| 2460 |
*Returns:* A basic_string\<char\> `vec` used as a vector of integer
|
| 2461 |
values, in which each element `vec[i]` represents the number of
|
| 2462 |
-
digits[^
|
| 2463 |
the rightmost group. If `vec.size() <= i`, the number is the same as
|
| 2464 |
-
group `(i-1)`; if `(i<0 || vec[i]<=0 || vec[i]==CHAR_MAX)`, the
|
| 2465 |
-
the digit group is unlimited.
|
| 2466 |
|
| 2467 |
The required specializations return the empty string, indicating no
|
| 2468 |
grouping.
|
| 2469 |
|
| 2470 |
``` cpp
|
|
@@ -2484,12 +2197,13 @@ or `L"true"` and `L"false"`.
|
|
| 2484 |
namespace std {
|
| 2485 |
template <class charT>
|
| 2486 |
class numpunct_byname : public numpunct<charT> {
|
| 2487 |
// this class is specialized for char and wchar_t.
|
| 2488 |
public:
|
| 2489 |
-
|
| 2490 |
-
|
|
|
|
| 2491 |
explicit numpunct_byname(const char*, size_t refs = 0);
|
| 2492 |
explicit numpunct_byname(const string&, size_t refs = 0);
|
| 2493 |
protected:
|
| 2494 |
~numpunct_byname();
|
| 2495 |
};
|
|
@@ -2503,12 +2217,12 @@ namespace std {
|
|
| 2503 |
``` cpp
|
| 2504 |
namespace std {
|
| 2505 |
template <class charT>
|
| 2506 |
class collate : public locale::facet {
|
| 2507 |
public:
|
| 2508 |
-
|
| 2509 |
-
|
| 2510 |
|
| 2511 |
explicit collate(size_t refs = 0);
|
| 2512 |
|
| 2513 |
int compare(const charT* low1, const charT* high1,
|
| 2514 |
const charT* low2, const charT* high2) const;
|
|
@@ -2544,23 +2258,23 @@ Each function compares a string of characters `*p` in the range \[`low`,
|
|
| 2544 |
``` cpp
|
| 2545 |
int compare(const charT* low1, const charT* high1,
|
| 2546 |
const charT* low2, const charT* high2) const;
|
| 2547 |
```
|
| 2548 |
|
| 2549 |
-
*Returns:* `do_compare(low1, high1, low2, high2)`
|
| 2550 |
|
| 2551 |
``` cpp
|
| 2552 |
string_type transform(const charT* low, const charT* high) const;
|
| 2553 |
```
|
| 2554 |
|
| 2555 |
-
*Returns:* `do_transform(low, high)`
|
| 2556 |
|
| 2557 |
``` cpp
|
| 2558 |
long hash(const charT* low, const charT* high) const;
|
| 2559 |
```
|
| 2560 |
|
| 2561 |
-
*Returns:* `do_hash(low, high)`
|
| 2562 |
|
| 2563 |
##### `collate` virtual functions <a id="locale.collate.virtuals">[[locale.collate.virtuals]]</a>
|
| 2564 |
|
| 2565 |
``` cpp
|
| 2566 |
int do_compare(const charT* low1, const charT* high1,
|
|
@@ -2578,30 +2292,33 @@ string_type do_transform(const charT* low, const charT* high) const;
|
|
| 2578 |
```
|
| 2579 |
|
| 2580 |
*Returns:* A `basic_string<charT>` value that, compared
|
| 2581 |
lexicographically with the result of calling `transform()` on another
|
| 2582 |
string, yields the same result as calling `do_compare()` on the same two
|
| 2583 |
-
strings.[^
|
| 2584 |
|
| 2585 |
``` cpp
|
| 2586 |
long do_hash(const charT* low, const charT* high) const;
|
| 2587 |
```
|
| 2588 |
|
| 2589 |
*Returns:* An integer value equal to the result of calling `hash()` on
|
| 2590 |
any other string for which `do_compare()` returns 0 (equal) when passed
|
| 2591 |
-
the two strings.
|
|
|
|
|
|
|
| 2592 |
string which does not compare equal should be very small, approaching
|
| 2593 |
-
`(1.0/numeric_limits<unsigned long>::max())`.
|
| 2594 |
|
| 2595 |
#### Class template `collate_byname` <a id="locale.collate.byname">[[locale.collate.byname]]</a>
|
| 2596 |
|
| 2597 |
``` cpp
|
| 2598 |
namespace std {
|
| 2599 |
template <class charT>
|
| 2600 |
class collate_byname : public collate<charT> {
|
| 2601 |
public:
|
| 2602 |
-
|
|
|
|
| 2603 |
explicit collate_byname(const char*, size_t refs = 0);
|
| 2604 |
explicit collate_byname(const string&, size_t refs = 0);
|
| 2605 |
protected:
|
| 2606 |
~collate_byname();
|
| 2607 |
};
|
|
@@ -2615,12 +2332,12 @@ Templates `time_get<charT,InputIterator>` and
|
|
| 2615 |
parsing. All specifications of member functions for `time_put` and
|
| 2616 |
`time_get` in the subclauses of [[category.time]] only apply to the
|
| 2617 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 2618 |
and [[tab:localization.required.specializations]] (
|
| 2619 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 2620 |
-
`ios_base::iostate&`, and `fill` arguments as described in
|
| 2621 |
-
[[locale.categories]]
|
| 2622 |
details.
|
| 2623 |
|
| 2624 |
#### Class template `time_get` <a id="locale.time.get">[[locale.time.get]]</a>
|
| 2625 |
|
| 2626 |
``` cpp
|
|
@@ -2631,12 +2348,12 @@ namespace std {
|
|
| 2631 |
};
|
| 2632 |
|
| 2633 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 2634 |
class time_get : public locale::facet, public time_base {
|
| 2635 |
public:
|
| 2636 |
-
|
| 2637 |
-
|
| 2638 |
|
| 2639 |
explicit time_get(size_t refs = 0);
|
| 2640 |
|
| 2641 |
dateorder date_order() const { return do_date_order(); }
|
| 2642 |
iter_type get_time(iter_type s, iter_type end, ios_base& f,
|
|
@@ -2677,81 +2394,81 @@ namespace std {
|
|
| 2677 |
```
|
| 2678 |
|
| 2679 |
`time_get`
|
| 2680 |
|
| 2681 |
is used to parse a character sequence, extracting components of a time
|
| 2682 |
-
or date into a `struct tm`
|
| 2683 |
produced by a corresponding format specifier to `time_put<>::put`. If
|
| 2684 |
the sequence being parsed matches the correct format, the corresponding
|
| 2685 |
members of the `struct tm` argument are set to the values used to
|
| 2686 |
produce the sequence; otherwise either an error is reported or
|
| 2687 |
-
unspecified values are assigned.[^
|
| 2688 |
|
| 2689 |
If the end iterator is reached during parsing by any of the `get()`
|
| 2690 |
member functions, the member sets `ios_base::eofbit` in `err`.
|
| 2691 |
|
| 2692 |
##### `time_get` members <a id="locale.time.get.members">[[locale.time.get.members]]</a>
|
| 2693 |
|
| 2694 |
``` cpp
|
| 2695 |
dateorder date_order() const;
|
| 2696 |
```
|
| 2697 |
|
| 2698 |
-
*Returns:* `do_date_order()`
|
| 2699 |
|
| 2700 |
``` cpp
|
| 2701 |
iter_type get_time(iter_type s, iter_type end, ios_base& str,
|
| 2702 |
ios_base::iostate& err, tm* t) const;
|
| 2703 |
```
|
| 2704 |
|
| 2705 |
-
*Returns:* `do_get_time(s, end, str, err, t)`
|
| 2706 |
|
| 2707 |
``` cpp
|
| 2708 |
iter_type get_date(iter_type s, iter_type end, ios_base& str,
|
| 2709 |
ios_base::iostate& err, tm* t) const;
|
| 2710 |
```
|
| 2711 |
|
| 2712 |
-
*Returns:* `do_get_date(s, end, str, err, t)`
|
| 2713 |
|
| 2714 |
``` cpp
|
| 2715 |
iter_type get_weekday(iter_type s, iter_type end, ios_base& str,
|
| 2716 |
ios_base::iostate& err, tm* t) const;
|
| 2717 |
iter_type get_monthname(iter_type s, iter_type end, ios_base& str,
|
| 2718 |
ios_base::iostate& err, tm* t) const;
|
| 2719 |
```
|
| 2720 |
|
| 2721 |
*Returns:* `do_get_weekday(s, end, str, err, t)` or
|
| 2722 |
-
`do_get_monthname(s, end, str, err, t)`
|
| 2723 |
|
| 2724 |
``` cpp
|
| 2725 |
iter_type get_year(iter_type s, iter_type end, ios_base& str,
|
| 2726 |
ios_base::iostate& err, tm* t) const;
|
| 2727 |
```
|
| 2728 |
|
| 2729 |
-
*Returns:* `do_get_year(s, end, str, err, t)`
|
| 2730 |
|
| 2731 |
``` cpp
|
| 2732 |
-
iter_type get(iter_type s, iter_type end, ios_base& f,
|
| 2733 |
-
|
| 2734 |
```
|
| 2735 |
|
| 2736 |
-
*Returns:* `do_get(s, end, f, err, t, format, modifier)`
|
| 2737 |
|
| 2738 |
``` cpp
|
| 2739 |
-
iter_type get(iter_type s, iter_type end, ios_base& f,
|
| 2740 |
-
|
| 2741 |
```
|
| 2742 |
|
| 2743 |
*Requires:* \[`fmt`, `fmtend`) shall be a valid range.
|
| 2744 |
|
| 2745 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 2746 |
It then enters a loop, reading zero or more characters from `s` at each
|
| 2747 |
iteration. Unless otherwise specified below, the loop terminates when
|
| 2748 |
the first of the following conditions holds:
|
| 2749 |
|
| 2750 |
-
- The expression `fmt == fmtend` evaluates to true.
|
| 2751 |
-
- The expression `err == ios_base::goodbit` evaluates to false.
|
| 2752 |
-
- The expression `s == end` evaluates to true, in which case the
|
| 2753 |
function evaluates `err = ios_base::eofbit | ios_base::failbit`.
|
| 2754 |
- The next element of `fmt` is equal to `’%’`, optionally followed by a
|
| 2755 |
modifier character, followed by a conversion specifier character,
|
| 2756 |
`format`, together forming a conversion specification valid for the
|
| 2757 |
ISO/IEC 9945 function `strptime`. If the number of elements in the
|
|
@@ -2762,36 +2479,37 @@ the first of the following conditions holds:
|
|
| 2762 |
value of `modifier` is `’\0’` when the optional modifier is absent
|
| 2763 |
from the conversion specification. If `err == ios_base::goodbit` holds
|
| 2764 |
after the evaluation of the expression, the function increments `fmt`
|
| 2765 |
to point just past the end of the conversion specification and
|
| 2766 |
continues looping.
|
| 2767 |
-
- The expression `isspace(*fmt, f.getloc())` evaluates to true, in
|
| 2768 |
-
case the function first increments `fmt` until
|
| 2769 |
-
`fmt == fmtend || !isspace(*fmt, f.getloc())` evaluates to true,
|
| 2770 |
-
advances `s` until `s == end || !isspace(*s, f.getloc())` is
|
| 2771 |
-
finally resumes looping.
|
| 2772 |
- The next character read from `s` matches the element pointed to by
|
| 2773 |
`fmt` in a case-insensitive comparison, in which case the function
|
| 2774 |
evaluates `++fmt, ++s` and continues looping. Otherwise, the function
|
| 2775 |
evaluates `err = ios_base::failbit`.
|
| 2776 |
|
| 2777 |
-
The function uses the `ctype<charT>` facet installed in
|
| 2778 |
-
determine valid whitespace characters. It is unspecified
|
| 2779 |
-
the function performs case-insensitive comparison or
|
| 2780 |
-
multi-character sequences are considered while doing
|
|
|
|
| 2781 |
|
| 2782 |
-
*Returns:* `s`
|
| 2783 |
|
| 2784 |
##### `time_get` virtual functions <a id="locale.time.get.virtuals">[[locale.time.get.virtuals]]</a>
|
| 2785 |
|
| 2786 |
``` cpp
|
| 2787 |
dateorder do_date_order() const;
|
| 2788 |
```
|
| 2789 |
|
| 2790 |
*Returns:* An enumeration value indicating the preferred order of
|
| 2791 |
components for those date formats that are composed of day, month, and
|
| 2792 |
-
year.[^
|
| 2793 |
contains other variable components (e.g., Julian day, week number, week
|
| 2794 |
day).
|
| 2795 |
|
| 2796 |
``` cpp
|
| 2797 |
iter_type do_get_time(iter_type s, iter_type end, ios_base& str,
|
|
@@ -2878,24 +2596,24 @@ any remaining format characters, corresponding to a conversion directive
|
|
| 2878 |
appropriate for the ISO/IEC 9945 function `strptime`, formed by
|
| 2879 |
concatenating `’%’`, the `modifier` character, when non-NUL, and the
|
| 2880 |
`format` character. When the concatenation fails to yield a complete
|
| 2881 |
valid directive the function leaves the object pointed to by `t`
|
| 2882 |
unchanged and evaluates `err |= ios_base::failbit`. When `s == end`
|
| 2883 |
-
evaluates to true after reading a character the function evaluates
|
| 2884 |
`err |= ios_base::eofbit`.
|
| 2885 |
|
| 2886 |
For complex conversion directives such as `%c`, `%x`, or `%X`, or
|
| 2887 |
directives that involve the optional modifiers `E` or `O`, when the
|
| 2888 |
function is unable to unambiguously determine some or all `struct tm`
|
| 2889 |
members from the input sequence \[`s`, `end`), it evaluates
|
| 2890 |
`err |= ios_base::eofbit`. In such cases the values of those `struct tm`
|
| 2891 |
members are unspecified and may be outside their valid range.
|
| 2892 |
|
| 2893 |
-
It is unspecified whether multiple calls to `do_get()` with
|
| 2894 |
-
of the same `struct tm` object will update the current
|
| 2895 |
-
object or simply overwrite its members. Portable
|
| 2896 |
-
the object before invoking the function.
|
| 2897 |
|
| 2898 |
*Returns:* An iterator pointing immediately beyond the last character
|
| 2899 |
recognized as possibly part of a valid input sequence for the given
|
| 2900 |
`format` and `modifier`.
|
| 2901 |
|
|
@@ -2904,12 +2622,12 @@ recognized as possibly part of a valid input sequence for the given
|
|
| 2904 |
``` cpp
|
| 2905 |
namespace std {
|
| 2906 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 2907 |
class time_get_byname : public time_get<charT, InputIterator> {
|
| 2908 |
public:
|
| 2909 |
-
|
| 2910 |
-
|
| 2911 |
|
| 2912 |
explicit time_get_byname(const char*, size_t refs = 0);
|
| 2913 |
explicit time_get_byname(const string&, size_t refs = 0);
|
| 2914 |
protected:
|
| 2915 |
~time_get_byname();
|
|
@@ -2922,12 +2640,12 @@ namespace std {
|
|
| 2922 |
``` cpp
|
| 2923 |
namespace std {
|
| 2924 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2925 |
class time_put : public locale::facet {
|
| 2926 |
public:
|
| 2927 |
-
|
| 2928 |
-
|
| 2929 |
|
| 2930 |
explicit time_put(size_t refs = 0);
|
| 2931 |
|
| 2932 |
// the following is implemented in terms of other member functions.
|
| 2933 |
iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb,
|
|
@@ -2962,20 +2680,20 @@ call to `do_put`; thus, format elements and other characters are
|
|
| 2962 |
interleaved in the output in the order in which they appear in the
|
| 2963 |
pattern. Format sequences are identified by converting each character
|
| 2964 |
`c` to a `char` value as if by `ct.narrow(c, 0)`, where `ct` is a
|
| 2965 |
reference to `ctype<charT>` obtained from `str.getloc()`. The first
|
| 2966 |
character of each sequence is equal to `’%’`, followed by an optional
|
| 2967 |
-
modifier character `mod`[^
|
| 2968 |
defined for the function `strftime`. If no modifier character is
|
| 2969 |
present, `mod` is zero. For each valid format sequence identified, calls
|
| 2970 |
`do_put(s, str, fill, t, spec, mod)`.
|
| 2971 |
|
| 2972 |
The second form calls `do_put(s, str, fill, t, format, modifier)`.
|
| 2973 |
|
| 2974 |
-
The `fill` argument may be used in the
|
| 2975 |
-
by derivations. A space character is a
|
| 2976 |
-
argument.
|
| 2977 |
|
| 2978 |
*Returns:* An iterator pointing immediately after the last character
|
| 2979 |
produced.
|
| 2980 |
|
| 2981 |
##### `time_put` virtual functions <a id="locale.time.put.virtuals">[[locale.time.put.virtuals]]</a>
|
|
@@ -2987,29 +2705,31 @@ iter_type do_put(iter_type s, ios_base&, char_type fill, const tm* t,
|
|
| 2987 |
|
| 2988 |
*Effects:* Formats the contents of the parameter `t` into characters
|
| 2989 |
placed on the output sequence `s`. Formatting is controlled by the
|
| 2990 |
parameters `format` and `modifier`, interpreted identically as the
|
| 2991 |
format specifiers in the string argument to the standard library
|
| 2992 |
-
function `strftime()`[^
|
| 2993 |
produced for those specifiers that are described as depending on the C
|
| 2994 |
-
locale are instead *implementation-defined*.[^
|
| 2995 |
|
| 2996 |
*Returns:* An iterator pointing immediately after the last character
|
| 2997 |
-
produced.
|
| 2998 |
-
|
| 2999 |
-
|
|
|
|
|
|
|
| 3000 |
|
| 3001 |
#### Class template `time_put_byname` <a id="locale.time.put.byname">[[locale.time.put.byname]]</a>
|
| 3002 |
|
| 3003 |
``` cpp
|
| 3004 |
namespace std {
|
| 3005 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 3006 |
class time_put_byname : public time_put<charT, OutputIterator>
|
| 3007 |
{
|
| 3008 |
public:
|
| 3009 |
-
|
| 3010 |
-
|
| 3011 |
|
| 3012 |
explicit time_put_byname(const char*, size_t refs = 0);
|
| 3013 |
explicit time_put_byname(const string&, size_t refs = 0);
|
| 3014 |
protected:
|
| 3015 |
~time_put_byname();
|
|
@@ -3025,25 +2745,24 @@ whether local or international monetary formats are to be used.
|
|
| 3025 |
All specifications of member functions for `money_put` and `money_get`
|
| 3026 |
in the subclauses of [[category.monetary]] only apply to the
|
| 3027 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 3028 |
and [[tab:localization.required.specializations]] (
|
| 3029 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 3030 |
-
`ios_base
|
| 3031 |
-
[[locale.categories]]
|
| 3032 |
determine formatting details.
|
| 3033 |
|
| 3034 |
#### Class template `money_get` <a id="locale.money.get">[[locale.money.get]]</a>
|
| 3035 |
|
| 3036 |
``` cpp
|
| 3037 |
namespace std {
|
| 3038 |
-
template <class charT,
|
| 3039 |
-
class InputIterator = istreambuf_iterator<charT> >
|
| 3040 |
class money_get : public locale::facet {
|
| 3041 |
public:
|
| 3042 |
-
|
| 3043 |
-
|
| 3044 |
-
|
| 3045 |
|
| 3046 |
explicit money_get(size_t refs = 0);
|
| 3047 |
|
| 3048 |
iter_type get(iter_type s, iter_type end, bool intl,
|
| 3049 |
ios_base& f, ios_base::iostate& err,
|
|
@@ -3072,11 +2791,11 @@ iter_type get(iter_type s, iter_type end, bool intl,
|
|
| 3072 |
long double& quant) const;
|
| 3073 |
iter_type get(s, iter_type end, bool intl, ios_base&f,
|
| 3074 |
ios_base::iostate& err, string_type& quant) const;
|
| 3075 |
```
|
| 3076 |
|
| 3077 |
-
*Returns:* `do_get(s, end, intl, f, err, quant)`
|
| 3078 |
|
| 3079 |
##### `money_get` virtual functions <a id="locale.money.get.virtuals">[[locale.money.get.virtuals]]</a>
|
| 3080 |
|
| 3081 |
``` cpp
|
| 3082 |
iter_type do_get(iter_type s, iter_type end, bool intl,
|
|
@@ -3097,13 +2816,17 @@ does not change `err`; otherwise, sets `err` to `(err|str.failbit)`, or
|
|
| 3097 |
does not change `units` or `digits`. Uses the pattern returned by
|
| 3098 |
`mp.neg_format()` to parse all values. The result is returned as an
|
| 3099 |
integral value stored in `units` or as a sequence of digits possibly
|
| 3100 |
preceded by a minus sign (as produced by `ct.widen(c)` where `c` is
|
| 3101 |
`’-’` or in the range from `’0’` through `’9’`, inclusive) stored in
|
| 3102 |
-
`digits`.
|
| 3103 |
-
|
| 3104 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3105 |
any such characters are not read, and parsing is terminated at the point
|
| 3106 |
where they first appear. Otherwise, thousands separators are optional;
|
| 3107 |
if present, they are checked for correct placement only after all format
|
| 3108 |
components have been read.
|
| 3109 |
|
|
@@ -3119,27 +2842,30 @@ format; otherwise, the currency symbol is required.
|
|
| 3119 |
|
| 3120 |
If the first character (if any) in the string `pos` returned by
|
| 3121 |
`mp.positive_sign()` or the string `neg` returned by
|
| 3122 |
`mp.negative_sign()` is recognized in the position indicated by `sign`
|
| 3123 |
in the format pattern, it is consumed and any remaining characters in
|
| 3124 |
-
the string are required after all the other format components.
|
| 3125 |
-
|
| 3126 |
-
|
| 3127 |
-
|
| 3128 |
-
|
| 3129 |
-
|
| 3130 |
-
|
| 3131 |
-
|
| 3132 |
-
|
| 3133 |
-
|
| 3134 |
-
|
|
|
|
|
|
|
|
|
|
| 3135 |
|
| 3136 |
Digits in the numeric monetary component are extracted and placed in
|
| 3137 |
`digits`, or into a character buffer `buf1` for conversion to produce a
|
| 3138 |
value for `units`, in the order in which they appear, preceded by a
|
| 3139 |
minus sign if and only if the result is negative. The value `units` is
|
| 3140 |
-
produced as if by[^
|
| 3141 |
|
| 3142 |
``` cpp
|
| 3143 |
for (int i = 0; i < n; ++i)
|
| 3144 |
buf2[i] = src[find(atoms, atoms+sizeof(src), buf1[i]) - atoms];
|
| 3145 |
buf2[n] = 0;
|
|
@@ -3160,17 +2886,16 @@ recognized as part of a valid monetary quantity.
|
|
| 3160 |
|
| 3161 |
#### Class template `money_put` <a id="locale.money.put">[[locale.money.put]]</a>
|
| 3162 |
|
| 3163 |
``` cpp
|
| 3164 |
namespace std {
|
| 3165 |
-
template <class charT,
|
| 3166 |
-
class OutputIterator = ostreambuf_iterator<charT> >
|
| 3167 |
class money_put : public locale::facet {
|
| 3168 |
public:
|
| 3169 |
-
|
| 3170 |
-
|
| 3171 |
-
|
| 3172 |
|
| 3173 |
explicit money_put(size_t refs = 0);
|
| 3174 |
|
| 3175 |
iter_type put(iter_type s, bool intl, ios_base& f,
|
| 3176 |
char_type fill, long double units) const;
|
|
@@ -3196,11 +2921,11 @@ iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
|
| 3196 |
long double quant) const;
|
| 3197 |
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
| 3198 |
const string_type& quant) const;
|
| 3199 |
```
|
| 3200 |
|
| 3201 |
-
*Returns:* `do_put(s, intl, f, loc, quant)`
|
| 3202 |
|
| 3203 |
##### `money_put` virtual functions <a id="locale.money.put.virtuals">[[locale.money.put.virtuals]]</a>
|
| 3204 |
|
| 3205 |
``` cpp
|
| 3206 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
@@ -3235,16 +2960,18 @@ Calls `str.width(0)`.
|
|
| 3235 |
`(str.flags() & str.showbase)` is nonzero. If the number of characters
|
| 3236 |
generated for the specified format is less than the value returned by
|
| 3237 |
`str.width()` on entry to the function, then copies of `fill` are
|
| 3238 |
inserted as necessary to pad to the specified width. For the value `af`
|
| 3239 |
equal to `(str.flags() & str.adjustfield)`, if `(af == str.internal)` is
|
| 3240 |
-
true, the fill characters are placed where `none` or `space` appears
|
| 3241 |
-
the formatting pattern; otherwise if `(af == str.left)` is true,
|
| 3242 |
-
are placed after the other characters; otherwise, they are placed
|
| 3243 |
-
the other characters.
|
| 3244 |
-
|
| 3245 |
-
|
|
|
|
|
|
|
| 3246 |
|
| 3247 |
*Returns:* An iterator pointing immediately after the last character
|
| 3248 |
produced.
|
| 3249 |
|
| 3250 |
#### Class template `moneypunct` <a id="locale.moneypunct">[[locale.moneypunct]]</a>
|
|
@@ -3258,12 +2985,12 @@ namespace std {
|
|
| 3258 |
};
|
| 3259 |
|
| 3260 |
template <class charT, bool International = false>
|
| 3261 |
class moneypunct : public locale::facet, public money_base {
|
| 3262 |
public:
|
| 3263 |
-
|
| 3264 |
-
|
| 3265 |
|
| 3266 |
explicit moneypunct(size_t refs = 0);
|
| 3267 |
|
| 3268 |
charT decimal_point() const;
|
| 3269 |
charT thousands_sep() const;
|
|
@@ -3295,11 +3022,11 @@ namespace std {
|
|
| 3295 |
|
| 3296 |
The `moneypunct<>` facet defines monetary formatting parameters used by
|
| 3297 |
`money_get<>` and `money_put<>`. A monetary format is a sequence of four
|
| 3298 |
components, specified by a `pattern` value `p`, such that the `part`
|
| 3299 |
value `static_cast<part>(p.field[i])` determines the `i`th component of
|
| 3300 |
-
the format[^
|
| 3301 |
`symbol`, `sign`, `value`, and either `space` or `none` appears exactly
|
| 3302 |
once. The value `none`, if present, is not first; the value `space`, if
|
| 3303 |
present, is neither first nor last.
|
| 3304 |
|
| 3305 |
Where `none` or `space` appears, white space is permitted in the format,
|
|
@@ -3362,56 +3089,56 @@ int frac_digits() const;
|
|
| 3362 |
pattern pos_format() const;
|
| 3363 |
pattern neg_format() const;
|
| 3364 |
```
|
| 3365 |
|
| 3366 |
Each of these functions `F` returns the result of calling the
|
| 3367 |
-
corresponding virtual member function `
|
| 3368 |
|
| 3369 |
##### `moneypunct` virtual functions <a id="locale.moneypunct.virtuals">[[locale.moneypunct.virtuals]]</a>
|
| 3370 |
|
| 3371 |
``` cpp
|
| 3372 |
charT do_decimal_point() const;
|
| 3373 |
```
|
| 3374 |
|
| 3375 |
*Returns:* The radix separator to use in case `do_frac_digits()` is
|
| 3376 |
-
greater than zero.[^
|
| 3377 |
|
| 3378 |
``` cpp
|
| 3379 |
charT do_thousands_sep() const;
|
| 3380 |
```
|
| 3381 |
|
| 3382 |
*Returns:* The digit group separator to use in case `do_grouping()`
|
| 3383 |
-
specifies a digit grouping pattern.[^
|
| 3384 |
|
| 3385 |
``` cpp
|
| 3386 |
string do_grouping() const;
|
| 3387 |
```
|
| 3388 |
|
| 3389 |
*Returns:* A pattern defined identically as, but not necessarily equal
|
| 3390 |
-
to, the result of `numpunct<charT>::do_grouping()`.[^
|
| 3391 |
|
| 3392 |
``` cpp
|
| 3393 |
string_type do_curr_symbol() const;
|
| 3394 |
```
|
| 3395 |
|
| 3396 |
-
*Returns:* A string to use as the currency identifier symbol.[^
|
| 3397 |
|
| 3398 |
``` cpp
|
| 3399 |
string_type do_positive_sign() const;
|
| 3400 |
string_type do_negative_sign() const;
|
| 3401 |
```
|
| 3402 |
|
| 3403 |
*Returns:* `do_positive_sign()` returns the string to use to indicate a
|
| 3404 |
-
positive monetary value;[^
|
| 3405 |
use to indicate a negative value.
|
| 3406 |
|
| 3407 |
``` cpp
|
| 3408 |
int do_frac_digits() const;
|
| 3409 |
```
|
| 3410 |
|
| 3411 |
*Returns:* The number of digits after the decimal radix separator, if
|
| 3412 |
-
any.[^
|
| 3413 |
|
| 3414 |
``` cpp
|
| 3415 |
pattern do_pos_format() const;
|
| 3416 |
pattern do_neg_format() const;
|
| 3417 |
```
|
|
@@ -3419,21 +3146,21 @@ pattern do_neg_format() const;
|
|
| 3419 |
*Returns:* The specializations required in
|
| 3420 |
Table [[tab:localization.required.specializations]] ([[locale.category]]),
|
| 3421 |
namely `moneypunct<char>`, `moneypunct<wchar_t>`,
|
| 3422 |
`moneypunct<char, true>`, and `moneypunct<wchar_t, true>`, return an
|
| 3423 |
object of type `pattern` initialized to
|
| 3424 |
-
`{ symbol, sign, none, value }`.[^
|
| 3425 |
|
| 3426 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 3427 |
|
| 3428 |
``` cpp
|
| 3429 |
namespace std {
|
| 3430 |
template <class charT, bool Intl = false>
|
| 3431 |
class moneypunct_byname : public moneypunct<charT, Intl> {
|
| 3432 |
public:
|
| 3433 |
-
|
| 3434 |
-
|
| 3435 |
|
| 3436 |
explicit moneypunct_byname(const char*, size_t refs = 0);
|
| 3437 |
explicit moneypunct_byname(const string&, size_t refs = 0);
|
| 3438 |
protected:
|
| 3439 |
~moneypunct_byname();
|
|
@@ -3450,18 +3177,18 @@ catalogs.
|
|
| 3450 |
|
| 3451 |
``` cpp
|
| 3452 |
namespace std {
|
| 3453 |
class messages_base {
|
| 3454 |
public:
|
| 3455 |
-
|
| 3456 |
};
|
| 3457 |
|
| 3458 |
template <class charT>
|
| 3459 |
class messages : public locale::facet, public messages_base {
|
| 3460 |
public:
|
| 3461 |
-
|
| 3462 |
-
|
| 3463 |
|
| 3464 |
explicit messages(size_t refs = 0);
|
| 3465 |
|
| 3466 |
catalog open(const basic_string<char>& fn, const locale&) const;
|
| 3467 |
string_type get(catalog c, int set, int msgid,
|
|
@@ -3490,12 +3217,11 @@ catalog open(const basic_string<char>& name, const locale& loc) const;
|
|
| 3490 |
```
|
| 3491 |
|
| 3492 |
*Returns:* `do_open(name, loc)`.
|
| 3493 |
|
| 3494 |
``` cpp
|
| 3495 |
-
string_type get(catalog cat, int set, int msgid,
|
| 3496 |
-
const string_type& dfault) const;
|
| 3497 |
```
|
| 3498 |
|
| 3499 |
*Returns:* `do_get(cat, set, msgid, dfault)`.
|
| 3500 |
|
| 3501 |
``` cpp
|
|
@@ -3505,12 +3231,11 @@ void close(catalog cat) const;
|
|
| 3505 |
*Effects:* Calls `do_close(cat)`.
|
| 3506 |
|
| 3507 |
##### `messages` virtual functions <a id="locale.messages.virtuals">[[locale.messages.virtuals]]</a>
|
| 3508 |
|
| 3509 |
``` cpp
|
| 3510 |
-
catalog do_open(const basic_string<char>& name,
|
| 3511 |
-
const locale& loc) const;
|
| 3512 |
```
|
| 3513 |
|
| 3514 |
*Returns:* A value that may be passed to `get()` to retrieve a message
|
| 3515 |
from the message catalog identified by the string `name` according to an
|
| 3516 |
*implementation-defined* mapping. The result can be used until it is
|
|
@@ -3520,12 +3245,11 @@ Returns a value less than 0 if no such catalog can be opened.
|
|
| 3520 |
|
| 3521 |
*Remarks:* The locale argument `loc` is used for character set code
|
| 3522 |
conversion when retrieving messages, if needed.
|
| 3523 |
|
| 3524 |
``` cpp
|
| 3525 |
-
string_type do_get(catalog cat, int set, int msgid,
|
| 3526 |
-
const string_type& dfault) const;
|
| 3527 |
```
|
| 3528 |
|
| 3529 |
*Requires:* `cat` shall be a catalog obtained from `open()` and not yet
|
| 3530 |
closed.
|
| 3531 |
|
|
@@ -3541,21 +3265,21 @@ void do_close(catalog cat) const;
|
|
| 3541 |
closed.
|
| 3542 |
|
| 3543 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 3544 |
|
| 3545 |
*Remarks:* The limit on such resources, if any, is
|
| 3546 |
-
implementation-defined.
|
| 3547 |
|
| 3548 |
#### Class template `messages_byname` <a id="locale.messages.byname">[[locale.messages.byname]]</a>
|
| 3549 |
|
| 3550 |
``` cpp
|
| 3551 |
namespace std {
|
| 3552 |
template <class charT>
|
| 3553 |
class messages_byname : public messages<charT> {
|
| 3554 |
public:
|
| 3555 |
-
|
| 3556 |
-
|
| 3557 |
|
| 3558 |
explicit messages_byname(const char*, size_t refs = 0);
|
| 3559 |
explicit messages_byname(const string&, size_t refs = 0);
|
| 3560 |
protected:
|
| 3561 |
~messages_byname();
|
|
@@ -3568,11 +3292,14 @@ namespace std {
|
|
| 3568 |
A C++program may define facets to be added to a locale and used
|
| 3569 |
identically as the built-in facets. To create a new facet interface,
|
| 3570 |
C++programs simply derive from `locale::facet` a class containing a
|
| 3571 |
static member: `static locale::id id`.
|
| 3572 |
|
| 3573 |
-
The locale member function templates verify its type and
|
|
|
|
|
|
|
|
|
|
| 3574 |
|
| 3575 |
Traditional global localization is still easy:
|
| 3576 |
|
| 3577 |
``` cpp
|
| 3578 |
#include <iostream>
|
|
@@ -3590,10 +3317,14 @@ int main(int argc, char** argv) {
|
|
| 3590 |
|
| 3591 |
return MyObject(argc, argv).doit();
|
| 3592 |
}
|
| 3593 |
```
|
| 3594 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3595 |
Greater flexibility is possible:
|
| 3596 |
|
| 3597 |
``` cpp
|
| 3598 |
#include <iostream>
|
| 3599 |
#include <locale>
|
|
@@ -3607,13 +3338,17 @@ int main() {
|
|
| 3607 |
}
|
| 3608 |
```
|
| 3609 |
|
| 3610 |
In a European locale, with input `3.456,78`, output is `3456.78`.
|
| 3611 |
|
|
|
|
|
|
|
| 3612 |
This can be important even for simple programs, which may need to write
|
| 3613 |
a data file in a fixed format, regardless of a user’s preference.
|
| 3614 |
|
|
|
|
|
|
|
| 3615 |
Here is an example of the use of locales in a library interface.
|
| 3616 |
|
| 3617 |
``` cpp
|
| 3618 |
// file: Date.h
|
| 3619 |
#include <iosfwd>
|
|
@@ -3661,15 +3396,19 @@ std::istream& operator>>(std::istream& s, Date& d) {
|
|
| 3661 |
}
|
| 3662 |
return s;
|
| 3663 |
}
|
| 3664 |
```
|
| 3665 |
|
|
|
|
|
|
|
| 3666 |
A locale object may be extended with a new facet simply by constructing
|
| 3667 |
it with an instance of a class derived from `locale::facet`. The only
|
| 3668 |
member a C++program must define is the static member `id`, which
|
| 3669 |
identifies your class interface as a new facet.
|
| 3670 |
|
|
|
|
|
|
|
| 3671 |
Classifying Japanese characters:
|
| 3672 |
|
| 3673 |
``` cpp
|
| 3674 |
// file: <jctype>
|
| 3675 |
#include <locale>
|
|
@@ -3691,33 +3430,36 @@ namespace My {
|
|
| 3691 |
#include "jctype" // above
|
| 3692 |
std::locale::id My::JCtype::id; // the static JCtype member declared above.
|
| 3693 |
|
| 3694 |
int main() {
|
| 3695 |
using namespace std;
|
| 3696 |
-
|
| 3697 |
locale loc(locale(""), // the user's preferred locale ...
|
| 3698 |
new My::JCtype); // and a new feature ...
|
| 3699 |
wchar_t c = use_facet<wctype>(loc).widen('!');
|
| 3700 |
if (!use_facet<My::JCtype>(loc).is_kanji(c))
|
| 3701 |
cout << "no it isn't!" << endl;
|
| 3702 |
-
return 0;
|
| 3703 |
}
|
| 3704 |
```
|
| 3705 |
|
| 3706 |
The new facet is used exactly like the built-in facets.
|
| 3707 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3708 |
Replacing an existing facet is even easier. The code does not define a
|
| 3709 |
member `id` because it is reusing the `numpunct<charT>` facet interface:
|
| 3710 |
|
| 3711 |
``` cpp
|
| 3712 |
// file: my_bool.C
|
| 3713 |
#include <iostream>
|
| 3714 |
#include <locale>
|
| 3715 |
#include <string>
|
| 3716 |
namespace My {
|
| 3717 |
using namespace std;
|
| 3718 |
-
|
| 3719 |
class BoolNames : public cnumpunct {
|
| 3720 |
protected:
|
| 3721 |
string do_truename() const { return "Oui Oui!"; }
|
| 3722 |
string do_falsename() const { return "Mais Non!"; }
|
| 3723 |
~BoolNames() { }
|
|
@@ -3730,113 +3472,45 @@ int main(int argc, char** argv) {
|
|
| 3730 |
using namespace std;
|
| 3731 |
// make the user's preferred locale, except for...
|
| 3732 |
locale loc(locale(""), new My::BoolNames(""));
|
| 3733 |
cout.imbue(loc);
|
| 3734 |
cout << boolalpha << "Any arguments today? " << (argc > 1) << endl;
|
| 3735 |
-
return 0;
|
| 3736 |
}
|
| 3737 |
```
|
| 3738 |
|
| 3739 |
-
|
| 3740 |
-
|
| 3741 |
-
The header `<codecvt>` provides code conversion facets for various
|
| 3742 |
-
character encodings.
|
| 3743 |
-
|
| 3744 |
-
``` cpp
|
| 3745 |
-
namespace std {
|
| 3746 |
-
enum codecvt_mode {
|
| 3747 |
-
consume_header = 4,
|
| 3748 |
-
generate_header = 2,
|
| 3749 |
-
little_endian = 1
|
| 3750 |
-
};
|
| 3751 |
-
|
| 3752 |
-
template<class Elem, unsigned long Maxcode = 0x10ffff,
|
| 3753 |
-
codecvt_mode Mode = (codecvt_mode)0>
|
| 3754 |
-
class codecvt_utf8
|
| 3755 |
-
: public codecvt<Elem, char, mbstate_t> {
|
| 3756 |
-
public:
|
| 3757 |
-
explicit codecvt_utf8(size_t refs = 0);
|
| 3758 |
-
~codecvt_utf8();
|
| 3759 |
-
};
|
| 3760 |
-
|
| 3761 |
-
template<class Elem, unsigned long Maxcode = 0x10ffff,
|
| 3762 |
-
codecvt_mode Mode = (codecvt_mode)0>
|
| 3763 |
-
class codecvt_utf16
|
| 3764 |
-
: public codecvt<Elem, char, mbstate_t> {
|
| 3765 |
-
public:
|
| 3766 |
-
explicit codecvt_utf16(size_t refs = 0);
|
| 3767 |
-
~codecvt_utf16();
|
| 3768 |
-
};
|
| 3769 |
-
|
| 3770 |
-
template<class Elem, unsigned long Maxcode = 0x10ffff,
|
| 3771 |
-
codecvt_mode Mode = (codecvt_mode)0>
|
| 3772 |
-
class codecvt_utf8_utf16
|
| 3773 |
-
: public codecvt<Elem, char, mbstate_t> {
|
| 3774 |
-
public:
|
| 3775 |
-
explicit codecvt_utf8_utf16(size_t refs = 0);
|
| 3776 |
-
~codecvt_utf8_utf16();
|
| 3777 |
-
};
|
| 3778 |
-
}
|
| 3779 |
-
```
|
| 3780 |
-
|
| 3781 |
-
For each of the three code conversion facets `codecvt_utf8`,
|
| 3782 |
-
`codecvt_utf16`, and `codecvt_utf8_utf16`:
|
| 3783 |
-
|
| 3784 |
-
- `Elem` is the wide-character type, such as `wchar_t`, `char16_t`, or
|
| 3785 |
-
`char32_t`.
|
| 3786 |
-
- `Maxcode` is the largest wide-character code that the facet will read
|
| 3787 |
-
or write without reporting a conversion error.
|
| 3788 |
-
- If `(Mode & consume_header)`, the facet shall consume an initial
|
| 3789 |
-
header sequence, if present, when reading a multibyte sequence to
|
| 3790 |
-
determine the endianness of the subsequent multibyte sequence to be
|
| 3791 |
-
read.
|
| 3792 |
-
- If `(Mode & generate_header)`, the facet shall generate an initial
|
| 3793 |
-
header sequence when writing a multibyte sequence to advertise the
|
| 3794 |
-
endianness of the subsequent multibyte sequence to be written.
|
| 3795 |
-
- If `(Mode & little_endian)`, the facet shall generate a multibyte
|
| 3796 |
-
sequence in little-endian order, as opposed to the default big-endian
|
| 3797 |
-
order.
|
| 3798 |
-
|
| 3799 |
-
For the facet `codecvt_utf8`:
|
| 3800 |
-
|
| 3801 |
-
- The facet shall convert between UTF-8 multibyte sequences and UCS2 or
|
| 3802 |
-
UCS4 (depending on the size of `Elem`) within the program.
|
| 3803 |
-
- Endianness shall not affect how multibyte sequences are read or
|
| 3804 |
-
written.
|
| 3805 |
-
- The multibyte sequences may be written as either a text or a binary
|
| 3806 |
-
file.
|
| 3807 |
-
|
| 3808 |
-
For the facet `codecvt_utf16`:
|
| 3809 |
-
|
| 3810 |
-
- The facet shall convert between UTF-16 multibyte sequences and UCS2 or
|
| 3811 |
-
UCS4 (depending on the size of `Elem`) within the program.
|
| 3812 |
-
- Multibyte sequences shall be read or written according to the `Mode`
|
| 3813 |
-
flag, as set out above.
|
| 3814 |
-
- The multibyte sequences may be written only as a binary file.
|
| 3815 |
-
Attempting to write to a text file produces undefined behavior.
|
| 3816 |
-
|
| 3817 |
-
For the facet `codecvt_utf8_utf16`:
|
| 3818 |
-
|
| 3819 |
-
- The facet shall convert between UTF-8 multibyte sequences and UTF-16
|
| 3820 |
-
(one or two 16-bit codes) within the program.
|
| 3821 |
-
- Endianness shall not affect how multibyte sequences are read or
|
| 3822 |
-
written.
|
| 3823 |
-
- The multibyte sequences may be written as either a text or a binary
|
| 3824 |
-
file.
|
| 3825 |
-
|
| 3826 |
-
ISO/IEC 10646-1:1993.
|
| 3827 |
|
| 3828 |
## C library locales <a id="c.locales">[[c.locales]]</a>
|
| 3829 |
|
| 3830 |
-
|
| 3831 |
|
| 3832 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3833 |
|
| 3834 |
Calls to the function `setlocale` may introduce a data race (
|
| 3835 |
[[res.on.data.races]]) with other calls to `setlocale` or with calls to
|
| 3836 |
the functions listed in Table [[tab:setlocale.data.races]].
|
| 3837 |
|
|
|
|
|
|
|
| 3838 |
**Table: Potential `setlocale` data races** <a id="tab:setlocale.data.races">[tab:setlocale.data.races]</a>
|
| 3839 |
|
| 3840 |
| | | | | |
|
| 3841 |
| --------- | ---------- | ----------- | ------------ | ---------- |
|
| 3842 |
| `fprintf` | `isprint` | `iswdigit` | `localeconv` | `tolower` |
|
|
@@ -3848,31 +3522,29 @@ the functions listed in Table [[tab:setlocale.data.races]].
|
|
| 3848 |
| `isdigit` | `iswblank` | `iswupper` | `strerror` | `wcstombs` |
|
| 3849 |
| `isgraph` | `iswcntrl` | `iswxdigit` | `strtod` | `wcsxfrm` |
|
| 3850 |
| `islower` | `iswctype` | `isxdigit` | `strxfrm` | `wctomb` |
|
| 3851 |
|
| 3852 |
|
| 3853 |
-
ISO C Clause 7.4.
|
| 3854 |
|
| 3855 |
<!-- Link reference definitions -->
|
| 3856 |
[alg.lex.comparison]: algorithms.md#alg.lex.comparison
|
| 3857 |
[alg.sort]: algorithms.md#alg.sort
|
| 3858 |
[algorithms]: algorithms.md#algorithms
|
| 3859 |
-
[basic.start.
|
| 3860 |
[bitmask.types]: library.md#bitmask.types
|
| 3861 |
[c.files]: input.md#c.files
|
| 3862 |
[c.locales]: #c.locales
|
| 3863 |
[category.collate]: #category.collate
|
| 3864 |
[category.ctype]: #category.ctype
|
| 3865 |
[category.messages]: #category.messages
|
| 3866 |
[category.monetary]: #category.monetary
|
| 3867 |
[category.numeric]: #category.numeric
|
| 3868 |
[category.time]: #category.time
|
| 3869 |
[classification]: #classification
|
|
|
|
| 3870 |
[conversions]: #conversions
|
| 3871 |
-
[conversions.buffer]: #conversions.buffer
|
| 3872 |
[conversions.character]: #conversions.character
|
| 3873 |
-
[conversions.string]: #conversions.string
|
| 3874 |
[facet.ctype.char.dtor]: #facet.ctype.char.dtor
|
| 3875 |
[facet.ctype.char.members]: #facet.ctype.char.members
|
| 3876 |
[facet.ctype.char.statics]: #facet.ctype.char.statics
|
| 3877 |
[facet.ctype.char.virtuals]: #facet.ctype.char.virtuals
|
| 3878 |
[facet.ctype.special]: #facet.ctype.special
|
|
@@ -3929,11 +3601,10 @@ ISO C Clause 7.4.
|
|
| 3929 |
[locale.num.get]: #locale.num.get
|
| 3930 |
[locale.numpunct]: #locale.numpunct
|
| 3931 |
[locale.numpunct.byname]: #locale.numpunct.byname
|
| 3932 |
[locale.operators]: #locale.operators
|
| 3933 |
[locale.statics]: #locale.statics
|
| 3934 |
-
[locale.stdcvt]: #locale.stdcvt
|
| 3935 |
[locale.syn]: #locale.syn
|
| 3936 |
[locale.time.get]: #locale.time.get
|
| 3937 |
[locale.time.get.byname]: #locale.time.get.byname
|
| 3938 |
[locale.time.get.members]: #locale.time.get.members
|
| 3939 |
[locale.time.get.virtuals]: #locale.time.get.virtuals
|
|
@@ -3950,11 +3621,10 @@ ISO C Clause 7.4.
|
|
| 3950 |
[sequence.reqmts]: containers.md#sequence.reqmts
|
| 3951 |
[tab:lib.locale.time.get.virtuals.dogetdate]: #tab:lib.locale.time.get.virtuals.dogetdate
|
| 3952 |
[tab:localization.category.facets]: #tab:localization.category.facets
|
| 3953 |
[tab:localization.convert.result.values.out.in]: #tab:localization.convert.result.values.out.in
|
| 3954 |
[tab:localization.convert.result.values.unshift]: #tab:localization.convert.result.values.unshift
|
| 3955 |
-
[tab:localization.hdr.clocale]: #tab:localization.hdr.clocale
|
| 3956 |
[tab:localization.lib.summary]: #tab:localization.lib.summary
|
| 3957 |
[tab:localization.required.specializations]: #tab:localization.required.specializations
|
| 3958 |
[tab:setlocale.data.races]: #tab:setlocale.data.races
|
| 3959 |
[vector]: containers.md#vector
|
| 3960 |
|
|
@@ -3962,85 +3632,89 @@ ISO C Clause 7.4.
|
|
| 3962 |
that is defined in `<ctime>`.
|
| 3963 |
|
| 3964 |
[^2]: Note that in the call to `put` the stream is implicitly converted
|
| 3965 |
to an `ostreambuf_iterator<charT, traits>`.
|
| 3966 |
|
| 3967 |
-
[^3]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3968 |
use it directly, or use the vector form of `ctype<>::is`.
|
| 3969 |
|
| 3970 |
-
[^
|
| 3971 |
derived from character literals for conversion to the locale’s
|
| 3972 |
encoding.
|
| 3973 |
|
| 3974 |
-
[^
|
| 3975 |
character classification that `c` is not also a member of.
|
| 3976 |
|
| 3977 |
-
[^
|
| 3978 |
provided. The specialization is specified in the standard, and not
|
| 3979 |
left as an implementation detail, because it affects the derivation
|
| 3980 |
interface for `ctype<char>`.
|
| 3981 |
|
| 3982 |
-
[^
|
| 3983 |
mappings from internal to external characters is 1 to N: a `codecvt`
|
| 3984 |
facet that is used by `basic_filebuf` must be able to translate
|
| 3985 |
characters one internal character at a time.
|
| 3986 |
|
| 3987 |
-
[^
|
| 3988 |
-
`stateT()`
|
| 3989 |
|
| 3990 |
-
[^
|
| 3991 |
-
elements may be consumed when producing a single `internT`
|
| 3992 |
character, and additional `externT` elements may appear at the end
|
| 3993 |
of a sequence after those that yield the final `internT` character.
|
| 3994 |
|
| 3995 |
-
[^
|
| 3996 |
that the corresponding member `get()` at least extract the sign
|
| 3997 |
before delegating.
|
| 3998 |
|
| 3999 |
-
[^
|
| 4000 |
is *not* a padding character.
|
| 4001 |
|
| 4002 |
-
[^
|
| 4003 |
`"3"` probably indicates groups of 51 (!) digits each, because 51 is
|
| 4004 |
the ASCII value of `"3"`.
|
| 4005 |
|
| 4006 |
-
[^
|
| 4007 |
other strings.
|
| 4008 |
|
| 4009 |
-
[^
|
| 4010 |
parsing of user-entered dates and times, but machine-generated
|
| 4011 |
formats can be parsed reliably. This allows parsers to be aggressive
|
| 4012 |
about interpreting user variations on standard formats.
|
| 4013 |
|
| 4014 |
-
[^
|
| 4015 |
formats, and may return `no_order` in valid locales.
|
| 4016 |
|
| 4017 |
-
[^
|
| 4018 |
vendors do.
|
| 4019 |
|
| 4020 |
-
[^
|
| 4021 |
implementation-defined, but should follow POSIX conventions.
|
| 4022 |
|
| 4023 |
-
[^
|
| 4024 |
as POSIX for these definitions.
|
| 4025 |
|
| 4026 |
-
[^
|
| 4027 |
|
| 4028 |
-
[^
|
| 4029 |
for `pattern::field` purely for efficiency.
|
| 4030 |
|
| 4031 |
-
[^
|
| 4032 |
|
| 4033 |
-
[^
|
| 4034 |
|
| 4035 |
-
[^
|
| 4036 |
|
| 4037 |
-
[^
|
| 4038 |
`true`) this is typically four characters long, usually three
|
| 4039 |
letters and a space.
|
| 4040 |
|
| 4041 |
-
[^
|
| 4042 |
|
| 4043 |
-
[^
|
| 4044 |
|
| 4045 |
-
[^
|
| 4046 |
usually contains a space, itself; for example, `"USD "`.
|
|
|
|
| 13 |
Table [[tab:localization.lib.summary]].
|
| 14 |
|
| 15 |
**Table: Localization library summary** <a id="tab:localization.lib.summary">[tab:localization.lib.summary]</a>
|
| 16 |
|
| 17 |
| Subclause | | Header |
|
| 18 |
+
| --------------------- | ---------------------------- | ----------- |
|
| 19 |
| [[locales]] | Locales | `<locale>` |
|
| 20 |
| [[locale.categories]] | Standard `locale` Categories | |
|
|
|
|
| 21 |
| [[c.locales]] | C library locales | `<clocale>` |
|
| 22 |
|
| 23 |
|
| 24 |
## Header `<locale>` synopsis <a id="locale.syn">[[locale.syn]]</a>
|
| 25 |
|
| 26 |
``` cpp
|
| 27 |
namespace std {
|
| 28 |
+
// [locale], locale
|
| 29 |
class locale;
|
| 30 |
template <class Facet> const Facet& use_facet(const locale&);
|
| 31 |
template <class Facet> bool has_facet(const locale&) noexcept;
|
| 32 |
|
| 33 |
+
// [locale.convenience], convenience interfaces
|
| 34 |
template <class charT> bool isspace (charT c, const locale& loc);
|
| 35 |
template <class charT> bool isprint (charT c, const locale& loc);
|
| 36 |
template <class charT> bool iscntrl (charT c, const locale& loc);
|
| 37 |
template <class charT> bool isupper (charT c, const locale& loc);
|
| 38 |
template <class charT> bool islower (charT c, const locale& loc);
|
|
|
|
| 43 |
template <class charT> bool isalnum (charT c, const locale& loc);
|
| 44 |
template <class charT> bool isgraph (charT c, const locale& loc);
|
| 45 |
template <class charT> bool isblank (charT c, const locale& loc);
|
| 46 |
template <class charT> charT toupper(charT c, const locale& loc);
|
| 47 |
template <class charT> charT tolower(charT c, const locale& loc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
// [category.ctype], ctype
|
| 50 |
class ctype_base;
|
| 51 |
template <class charT> class ctype;
|
| 52 |
template <> class ctype<char>; // specialization
|
| 53 |
template <class charT> class ctype_byname;
|
| 54 |
class codecvt_base;
|
| 55 |
template <class internT, class externT, class stateT> class codecvt;
|
| 56 |
template <class internT, class externT, class stateT> class codecvt_byname;
|
| 57 |
|
| 58 |
+
// [category.numeric], numeric
|
| 59 |
+
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 60 |
+
class num_get;
|
| 61 |
+
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 62 |
+
class num_put;
|
| 63 |
+
template <class charT>
|
| 64 |
+
class numpunct;
|
| 65 |
+
template <class charT>
|
| 66 |
+
class numpunct_byname;
|
| 67 |
|
| 68 |
+
// [category.collate], collation
|
| 69 |
template <class charT> class collate;
|
| 70 |
template <class charT> class collate_byname;
|
| 71 |
|
| 72 |
+
// [category.time], date and time
|
| 73 |
class time_base;
|
| 74 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 75 |
class time_get;
|
| 76 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 77 |
class time_get_byname;
|
| 78 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 79 |
class time_put;
|
| 80 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 81 |
class time_put_byname;
|
| 82 |
|
| 83 |
+
// [category.monetary], money
|
| 84 |
class money_base;
|
| 85 |
+
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 86 |
+
class money_get;
|
| 87 |
+
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 88 |
+
class money_put;
|
| 89 |
+
template <class charT, bool Intl = false>
|
| 90 |
+
class moneypunct;
|
| 91 |
+
template <class charT, bool Intl = false>
|
| 92 |
+
class moneypunct_byname;
|
| 93 |
|
| 94 |
+
// [category.messages], message retrieval
|
| 95 |
class messages_base;
|
| 96 |
template <class charT> class messages;
|
| 97 |
template <class charT> class messages_byname;
|
| 98 |
}
|
| 99 |
```
|
|
|
|
| 110 |
class locale {
|
| 111 |
public:
|
| 112 |
// types:
|
| 113 |
class facet;
|
| 114 |
class id;
|
| 115 |
+
using category = int;
|
| 116 |
static const category // values assigned here are for exposition only
|
| 117 |
none = 0,
|
| 118 |
collate = 0x010, ctype = 0x020,
|
| 119 |
monetary = 0x040, numeric = 0x080,
|
| 120 |
time = 0x100, messages = 0x200,
|
|
|
|
| 156 |
locale’s set of facets.
|
| 157 |
|
| 158 |
Access to the facets of a `locale` is via two function templates,
|
| 159 |
`use_facet<>` and `has_facet<>`.
|
| 160 |
|
| 161 |
+
[*Example 1*:
|
| 162 |
+
|
| 163 |
An iostream `operator<<` might be implemented as:[^2]
|
| 164 |
|
| 165 |
``` cpp
|
| 166 |
template <class charT, class traits>
|
| 167 |
basic_ostream<charT, traits>&
|
|
|
|
| 176 |
}
|
| 177 |
return s;
|
| 178 |
}
|
| 179 |
```
|
| 180 |
|
| 181 |
+
— *end example*]
|
| 182 |
+
|
| 183 |
In the call to `use_facet<Facet>(loc)`, the type argument chooses a
|
| 184 |
facet, making available all members of the named type. If `Facet` is not
|
| 185 |
present in a locale, it throws the standard exception `bad_cast`. A
|
| 186 |
C++program can check if a locale implements a particular facet with the
|
| 187 |
function template `has_facet<Facet>()`. User-defined facets may be
|
| 188 |
installed in a locale, and used identically as may standard facets (
|
| 189 |
[[facets.examples]]).
|
| 190 |
|
| 191 |
+
[*Note 1*:
|
| 192 |
+
|
| 193 |
All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
|
| 194 |
except that:
|
| 195 |
|
| 196 |
- A member operator template
|
| 197 |
`operator()(const basic_string<C, T, A>&, const basic_string<{}C, T, A>&)`
|
|
|
|
| 200 |
- Convenient global interfaces are provided for traditional `ctype`
|
| 201 |
functions such as `isdigit()` and `isspace()`, so that given a locale
|
| 202 |
object `loc` a C++program can call `isspace(c, loc)`. (This eases
|
| 203 |
upgrading existing extractors ([[istream.formatted]]).)
|
| 204 |
|
| 205 |
+
— *end note*]
|
| 206 |
+
|
| 207 |
Once a facet reference is obtained from a locale object by calling
|
| 208 |
`use_facet<>`, that reference remains usable, and the results from
|
| 209 |
member functions of it may be cached and re-used, as long as some locale
|
| 210 |
object refers to that facet.
|
| 211 |
|
|
|
|
| 228 |
#### `locale` types <a id="locale.types">[[locale.types]]</a>
|
| 229 |
|
| 230 |
##### Type `locale::category` <a id="locale.category">[[locale.category]]</a>
|
| 231 |
|
| 232 |
``` cpp
|
| 233 |
+
using category = int;
|
| 234 |
```
|
| 235 |
|
| 236 |
*Valid* `category` values include the `locale` member bitmask elements
|
| 237 |
`collate`, `ctype`, `monetary`, `numeric`, `time`, and `messages`, each
|
| 238 |
of which represents a single locale category. In addition, `locale`
|
|
|
|
| 258 |
[[tab:localization.category.facets]].
|
| 259 |
|
| 260 |
**Table: Locale category facets** <a id="tab:localization.category.facets">[tab:localization.category.facets]</a>
|
| 261 |
|
| 262 |
| Category | Includes facets |
|
| 263 |
+
| -------- | ----------------------------------------------------- |
|
| 264 |
| collate | `collate<char>`, `collate<wchar_t>` |
|
| 265 |
| ctype | `ctype<char>`, `ctype<wchar_t>` |
|
| 266 |
| | `codecvt<char, char, mbstate_t>` |
|
| 267 |
| | `codecvt<char16_t, char, mbstate_t>` |
|
| 268 |
| | `codecvt<char32_t, char, mbstate_t>` |
|
|
|
|
| 279 |
| messages | `messages<char>`, `messages<wchar_t>` |
|
| 280 |
|
| 281 |
|
| 282 |
For any locale `loc` either constructed, or returned by
|
| 283 |
`locale::classic()`, and any facet `Facet` shown in Table
|
| 284 |
+
[[tab:localization.category.facets]], `has_facet<Facet>(loc)` is `true`.
|
| 285 |
Each `locale` member function which takes a `locale::category` argument
|
| 286 |
operates on the corresponding set of facets.
|
| 287 |
|
| 288 |
An implementation is required to provide those specializations for facet
|
| 289 |
templates identified as members of a category, and for those shown in
|
| 290 |
Table [[tab:localization.required.specializations]].
|
| 291 |
|
| 292 |
**Table: Required specializations** <a id="tab:localization.required.specializations">[tab:localization.required.specializations]</a>
|
| 293 |
|
| 294 |
| Category | Includes facets |
|
| 295 |
+
| -------- | --------------------------------------------------------- |
|
| 296 |
| collate | `collate_byname<char>`, `collate_byname<wchar_t>` |
|
| 297 |
| ctype | `ctype_byname<char>`, `ctype_byname<wchar_t>` |
|
| 298 |
| | `codecvt_byname<char, char, mbstate_t>` |
|
| 299 |
| | `codecvt_byname<char16_t, char, mbstate_t>` |
|
| 300 |
| | `codecvt_byname<char32_t, char, mbstate_t>` |
|
|
|
|
| 326 |
`InputIterator` or `OutputIterator` indicates the set of all possible
|
| 327 |
specializations on parameters that satisfy the requirements of an Input
|
| 328 |
Iterator or an Output Iterator, respectively (
|
| 329 |
[[iterator.requirements]]). A template parameter with name `C`
|
| 330 |
represents the set of types containing `char`, `wchar_t`, and any other
|
| 331 |
+
*implementation-defined* character types that satisfy the requirements
|
| 332 |
+
for a character on which any of the iostream components can be
|
| 333 |
+
instantiated. A template parameter with name `International` represents
|
| 334 |
+
the set of all possible specializations on a bool parameter.
|
| 335 |
|
| 336 |
##### Class `locale::facet` <a id="locale.facet">[[locale.facet]]</a>
|
| 337 |
|
| 338 |
``` cpp
|
| 339 |
namespace std {
|
|
|
|
| 345 |
void operator=(const facet&) = delete;
|
| 346 |
};
|
| 347 |
}
|
| 348 |
```
|
| 349 |
|
| 350 |
+
Class `facet` is the base class for locale feature sets. A class is a
|
| 351 |
+
*facet* if it is publicly derived from another facet, or if it is a
|
| 352 |
+
class derived from `locale::facet` and contains a publicly accessible
|
| 353 |
+
declaration as follows: [^3]
|
| 354 |
+
|
| 355 |
+
``` cpp
|
| 356 |
+
static ::std::locale::id id;
|
| 357 |
+
```
|
| 358 |
+
|
| 359 |
Template parameters in this Clause which are required to be facets are
|
| 360 |
those named `Facet` in declarations. A program that passes a type that
|
| 361 |
is *not* a facet, or a type that refers to a volatile-qualified facet,
|
| 362 |
as an (explicit or deduced) template parameter to a locale function
|
| 363 |
expecting a facet, is ill-formed. A const-qualified facet is a valid
|
| 364 |
template argument to any locale function that expects a Facet template
|
| 365 |
parameter.
|
| 366 |
|
| 367 |
The `refs` argument to the constructor is used for lifetime management.
|
| 368 |
+
For `refs == 0`, the implementation performs
|
|
|
|
| 369 |
`delete static_cast<locale::facet*>(f)` (where `f` is a pointer to the
|
| 370 |
+
facet) when the last `locale` object containing the facet is destroyed;
|
| 371 |
+
for `refs == 1`, the implementation never destroys the facet.
|
|
|
|
| 372 |
|
| 373 |
Constructors of all facets defined in this Clause take such an argument
|
| 374 |
and pass it along to their `facet` base class constructor. All
|
| 375 |
one-argument constructors defined in this Clause are *explicit*,
|
| 376 |
preventing their participation in automatic conversions.
|
|
|
|
| 398 |
id(const id&) = delete;
|
| 399 |
};
|
| 400 |
}
|
| 401 |
```
|
| 402 |
|
| 403 |
+
The class `locale::id` provides identification of a locale facet
|
| 404 |
interface, used as an index for lookup and to encapsulate
|
| 405 |
initialization.
|
| 406 |
|
| 407 |
+
[*Note 1*: Because facets are used by iostreams, potentially while
|
| 408 |
+
static constructors are running, their initialization cannot depend on
|
| 409 |
programmed static initialization. One initialization strategy is for
|
| 410 |
`locale` to initialize each facet’s `id` member the first time an
|
| 411 |
instance of the facet is installed into a locale. This depends only on
|
| 412 |
static storage being zero before constructors run (
|
| 413 |
+
[[basic.start.static]]). — *end note*]
|
| 414 |
|
| 415 |
#### `locale` constructors and destructor <a id="locale.cons">[[locale.cons]]</a>
|
| 416 |
|
| 417 |
``` cpp
|
| 418 |
locale() noexcept;
|
|
|
|
| 421 |
Default constructor: a snapshot of the current global locale.
|
| 422 |
|
| 423 |
*Effects:* Constructs a copy of the argument last passed to
|
| 424 |
`locale::global(locale&)`, if it has been called; else, the resulting
|
| 425 |
facets have virtual function semantics identical to those of
|
| 426 |
+
`locale::classic()`.
|
| 427 |
+
|
| 428 |
+
[*Note 1*: This constructor is commonly used as the default value for
|
| 429 |
+
arguments of functions that take a `const locale&`
|
| 430 |
+
argument. — *end note*]
|
| 431 |
|
| 432 |
``` cpp
|
| 433 |
locale(const locale& other) noexcept;
|
| 434 |
```
|
| 435 |
|
|
|
|
| 498 |
const locale& operator=(const locale& other) noexcept;
|
| 499 |
```
|
| 500 |
|
| 501 |
*Effects:* Creates a copy of `other`, replacing the current value.
|
| 502 |
|
| 503 |
+
*Returns:* `*this`.
|
| 504 |
|
| 505 |
``` cpp
|
| 506 |
~locale();
|
| 507 |
```
|
| 508 |
|
|
|
|
| 517 |
*Effects:* Constructs a locale incorporating all facets from `*this`
|
| 518 |
except for that one facet of `other` that is identified by `Facet`.
|
| 519 |
|
| 520 |
*Returns:* The newly created locale.
|
| 521 |
|
| 522 |
+
*Throws:* `runtime_error` if `has_facet<Facet>(other)` is `false`.
|
| 523 |
|
| 524 |
*Remarks:* The resulting locale has no name.
|
| 525 |
|
| 526 |
``` cpp
|
| 527 |
basic_string<char> name() const;
|
| 528 |
```
|
| 529 |
|
| 530 |
*Returns:* The name of `*this`, if it has one; otherwise, the string
|
| 531 |
+
`"*"`.
|
|
|
|
|
|
|
|
|
|
| 532 |
|
| 533 |
#### `locale` operators <a id="locale.operators">[[locale.operators]]</a>
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
bool operator==(const locale& other) const;
|
|
|
|
| 542 |
|
| 543 |
``` cpp
|
| 544 |
bool operator!=(const locale& other) const;
|
| 545 |
```
|
| 546 |
|
| 547 |
+
*Returns:* `!(*this == other)`.
|
| 548 |
|
| 549 |
``` cpp
|
| 550 |
template <class charT, class traits, class Allocator>
|
| 551 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 552 |
const basic_string<charT, traits, Allocator>& s2) const;
|
|
|
|
| 556 |
|
| 557 |
*Remarks:* This member operator template (and therefore `locale` itself)
|
| 558 |
satisfies requirements for a comparator predicate template argument
|
| 559 |
(Clause [[algorithms]]) applied to strings.
|
| 560 |
|
| 561 |
+
*Returns:*
|
| 562 |
|
| 563 |
``` cpp
|
| 564 |
+
use_facet<collate<charT>>(*this).compare(s1.data(), s1.data() + s1.size(),
|
| 565 |
+
s2.data(), s2.data() + s2.size()) < 0
|
| 566 |
```
|
| 567 |
|
| 568 |
+
[*Example 1*:
|
| 569 |
+
|
| 570 |
A vector of strings `v` can be collated according to collation rules in
|
| 571 |
locale `loc` simply by ([[alg.sort]], [[vector]]):
|
| 572 |
|
| 573 |
``` cpp
|
| 574 |
std::sort(v.begin(), v.end(), loc);
|
| 575 |
```
|
| 576 |
|
| 577 |
+
— *end example*]
|
| 578 |
+
|
| 579 |
#### `locale` static members <a id="locale.statics">[[locale.statics]]</a>
|
| 580 |
|
| 581 |
``` cpp
|
| 582 |
static locale global(const locale& loc);
|
| 583 |
```
|
|
|
|
| 586 |
|
| 587 |
*Effects:* Causes future calls to the constructor `locale()` to return a
|
| 588 |
copy of the argument. If the argument has a name, does
|
| 589 |
|
| 590 |
``` cpp
|
| 591 |
+
setlocale(LC_ALL, loc.name().c_str());
|
| 592 |
```
|
| 593 |
|
| 594 |
otherwise, the effect on the C locale, if any, is
|
| 595 |
*implementation-defined*. No library function other than
|
| 596 |
`locale::global()` shall affect the value returned by `locale()`.
|
| 597 |
+
|
| 598 |
+
[*Note 1*: See [[c.locales]] for data race considerations when
|
| 599 |
+
`setlocale` is invoked. — *end note*]
|
| 600 |
|
| 601 |
*Returns:* The previous value of `locale()`.
|
| 602 |
|
| 603 |
``` cpp
|
| 604 |
static const locale& classic();
|
|
|
|
| 630 |
|
| 631 |
``` cpp
|
| 632 |
template <class Facet> bool has_facet(const locale& loc) noexcept;
|
| 633 |
```
|
| 634 |
|
| 635 |
+
*Returns:* `true` if the facet requested is present in `loc`; otherwise
|
| 636 |
+
`false`.
|
| 637 |
|
| 638 |
### Convenience interfaces <a id="locale.convenience">[[locale.convenience]]</a>
|
| 639 |
|
| 640 |
#### Character classification <a id="classification">[[classification]]</a>
|
| 641 |
|
|
|
|
| 652 |
template <class charT> bool isalnum (charT c, const locale& loc);
|
| 653 |
template <class charT> bool isgraph (charT c, const locale& loc);
|
| 654 |
template <class charT> bool isblank (charT c, const locale& loc);
|
| 655 |
```
|
| 656 |
|
| 657 |
+
Each of these functions `isF` returns the result of the expression:
|
|
|
|
| 658 |
|
| 659 |
``` cpp
|
| 660 |
use_facet<ctype<charT>>(loc).is(ctype_base::F, c)
|
| 661 |
```
|
| 662 |
|
| 663 |
+
where `F` is the `ctype_base::mask` value corresponding to that
|
| 664 |
+
function ([[category.ctype]]).[^4]
|
| 665 |
|
| 666 |
#### Conversions <a id="conversions">[[conversions]]</a>
|
| 667 |
|
| 668 |
##### Character conversions <a id="conversions.character">[[conversions.character]]</a>
|
| 669 |
|
|
|
|
| 677 |
template <class charT> charT tolower(charT c, const locale& loc);
|
| 678 |
```
|
| 679 |
|
| 680 |
*Returns:* `use_facet<ctype<charT>>(loc).tolower(c)`.
|
| 681 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
## Standard `locale` categories <a id="locale.categories">[[locale.categories]]</a>
|
| 683 |
|
| 684 |
Each of the standard categories includes a family of facets. Some of
|
| 685 |
these implement formatting or parsing of a datum, for use by standard or
|
| 686 |
users’ iostream operators `<<` and `>>`, as members `put()` and `get()`,
|
|
|
|
| 704 |
|
| 705 |
``` cpp
|
| 706 |
namespace std {
|
| 707 |
class ctype_base {
|
| 708 |
public:
|
| 709 |
+
using mask = T;
|
| 710 |
|
| 711 |
// numeric values are for exposition only.
|
| 712 |
static const mask space = 1 << 0;
|
| 713 |
static const mask print = 1 << 1;
|
| 714 |
static const mask cntrl = 1 << 2;
|
|
|
|
| 732 |
``` cpp
|
| 733 |
namespace std {
|
| 734 |
template <class charT>
|
| 735 |
class ctype : public locale::facet, public ctype_base {
|
| 736 |
public:
|
| 737 |
+
using char_type = charT;
|
| 738 |
|
| 739 |
explicit ctype(size_t refs = 0);
|
| 740 |
|
| 741 |
bool is(mask m, charT c) const;
|
| 742 |
const charT* is(const charT* low, const charT* high, mask* vec) const;
|
| 743 |
+
const charT* scan_is(mask m, const charT* low, const charT* high) const;
|
| 744 |
+
const charT* scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
|
|
|
| 745 |
charT toupper(charT c) const;
|
| 746 |
const charT* toupper(charT* low, const charT* high) const;
|
| 747 |
charT tolower(charT c) const;
|
| 748 |
const charT* tolower(charT* low, const charT* high) const;
|
| 749 |
|
| 750 |
charT widen(char c) const;
|
| 751 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 752 |
char narrow(charT c, char dfault) const;
|
| 753 |
+
const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
|
|
|
|
| 754 |
|
| 755 |
static locale::id id;
|
| 756 |
|
| 757 |
protected:
|
| 758 |
~ctype();
|
| 759 |
virtual bool do_is(mask m, charT c) const;
|
| 760 |
+
virtual const charT* do_is(const charT* low, const charT* high, mask* vec) const;
|
| 761 |
+
virtual const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
|
| 762 |
+
virtual const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
|
|
|
|
|
|
| 763 |
virtual charT do_toupper(charT) const;
|
| 764 |
virtual const charT* do_toupper(charT* low, const charT* high) const;
|
| 765 |
virtual charT do_tolower(charT) const;
|
| 766 |
virtual const charT* do_tolower(charT* low, const charT* high) const;
|
| 767 |
virtual charT do_widen(char) const;
|
| 768 |
+
virtual const char* do_widen(const char* low, const char* high, charT* dest) const;
|
|
|
|
| 769 |
virtual char do_narrow(charT, char dfault) const;
|
| 770 |
virtual const charT* do_narrow(const charT* low, const charT* high,
|
| 771 |
char dfault, char* dest) const;
|
| 772 |
};
|
| 773 |
}
|
|
|
|
| 788 |
bool is(mask m, charT c) const;
|
| 789 |
const charT* is(const charT* low, const charT* high,
|
| 790 |
mask* vec) const;
|
| 791 |
```
|
| 792 |
|
| 793 |
+
*Returns:* `do_is(m, c)` or `do_is(low, high, vec)`.
|
| 794 |
|
| 795 |
``` cpp
|
| 796 |
const charT* scan_is(mask m,
|
| 797 |
const charT* low, const charT* high) const;
|
| 798 |
```
|
| 799 |
|
| 800 |
+
*Returns:* `do_scan_is(m, low, high)`.
|
| 801 |
|
| 802 |
``` cpp
|
| 803 |
const charT* scan_not(mask m,
|
| 804 |
const charT* low, const charT* high) const;
|
| 805 |
```
|
| 806 |
|
| 807 |
+
*Returns:* `do_scan_not(m, low, high)`.
|
| 808 |
|
| 809 |
``` cpp
|
| 810 |
charT toupper(charT) const;
|
| 811 |
const charT* toupper(charT* low, const charT* high) const;
|
| 812 |
```
|
| 813 |
|
| 814 |
+
*Returns:* `do_toupper(c)` or `do_toupper(low, high)`.
|
| 815 |
|
| 816 |
``` cpp
|
| 817 |
charT tolower(charT c) const;
|
| 818 |
const charT* tolower(charT* low, const charT* high) const;
|
| 819 |
```
|
| 820 |
|
| 821 |
+
*Returns:* `do_tolower(c)` or `do_tolower(low, high)`.
|
| 822 |
|
| 823 |
``` cpp
|
| 824 |
charT widen(char c) const;
|
| 825 |
const char* widen(const char* low, const char* high, charT* to) const;
|
| 826 |
```
|
| 827 |
|
| 828 |
+
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`.
|
| 829 |
|
| 830 |
``` cpp
|
| 831 |
char narrow(charT c, char dfault) const;
|
| 832 |
+
const charT* narrow(const charT* low, const charT* high, char dfault,
|
| 833 |
char* to) const;
|
| 834 |
```
|
| 835 |
|
| 836 |
+
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`.
|
| 837 |
|
| 838 |
##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
|
| 839 |
|
| 840 |
``` cpp
|
| 841 |
bool do_is(mask m, charT c) const;
|
|
|
|
| 844 |
```
|
| 845 |
|
| 846 |
*Effects:* Classifies a character or sequence of characters. For each
|
| 847 |
argument character, identifies a value `M` of type `ctype_base::mask`.
|
| 848 |
The second form identifies a value `M` of type `ctype_base::mask` for
|
| 849 |
+
each `*p` where `(low <= p && p < high)`, and places it into
|
| 850 |
+
`vec[p - low]`.
|
| 851 |
|
| 852 |
*Returns:* The first form returns the result of the expression
|
| 853 |
`(M & m) != 0`; i.e., `true` if the character has the characteristics
|
| 854 |
specified. The second form returns `high`.
|
| 855 |
|
| 856 |
``` cpp
|
| 857 |
+
const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 858 |
```
|
| 859 |
|
| 860 |
*Effects:* Locates a character in a buffer that conforms to a
|
| 861 |
classification `m`.
|
| 862 |
|
| 863 |
+
*Returns:* The smallest pointer `p` in the range \[`low`, `high`) such
|
| 864 |
+
that `is(m, *p)` would return `true`; otherwise, returns `high`.
|
| 865 |
|
| 866 |
``` cpp
|
| 867 |
+
const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 868 |
```
|
| 869 |
|
| 870 |
*Effects:* Locates a character in a buffer that fails to conform to a
|
| 871 |
classification `m`.
|
| 872 |
|
|
|
|
| 906 |
charT* dest) const;
|
| 907 |
```
|
| 908 |
|
| 909 |
*Effects:* Applies the simplest reasonable transformation from a `char`
|
| 910 |
value or sequence of `char` values to the corresponding `charT` value or
|
| 911 |
+
values.[^5] The only characters for which unique transformations are
|
| 912 |
required are those in the basic source character set ([[lex.charset]]).
|
| 913 |
|
| 914 |
For any named `ctype` category with a `ctype <charT>` facet `ctc` and
|
| 915 |
valid `ctype_base::mask` value `M`,
|
| 916 |
+
`(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^6]
|
| 917 |
|
| 918 |
The second form transforms each character `*p` in the range \[`low`,
|
| 919 |
`high`), placing the result in `dest[p - low]`.
|
| 920 |
|
| 921 |
*Returns:* The first form returns the transformed value. The second form
|
|
|
|
| 960 |
``` cpp
|
| 961 |
namespace std {
|
| 962 |
template <class charT>
|
| 963 |
class ctype_byname : public ctype<charT> {
|
| 964 |
public:
|
| 965 |
+
using mask = typename ctype<charT>::mask;
|
| 966 |
explicit ctype_byname(const char*, size_t refs = 0);
|
| 967 |
explicit ctype_byname(const string&, size_t refs = 0);
|
| 968 |
protected:
|
| 969 |
~ctype_byname();
|
| 970 |
};
|
|
|
|
| 973 |
|
| 974 |
#### `ctype` specializations <a id="facet.ctype.special">[[facet.ctype.special]]</a>
|
| 975 |
|
| 976 |
``` cpp
|
| 977 |
namespace std {
|
| 978 |
+
template <>
|
| 979 |
+
class ctype<char> : public locale::facet, public ctype_base {
|
| 980 |
public:
|
| 981 |
+
using char_type = char;
|
| 982 |
|
| 983 |
explicit ctype(const mask* tab = 0, bool del = false,
|
| 984 |
size_t refs = 0);
|
| 985 |
|
| 986 |
bool is(mask m, char c) const;
|
|
|
|
| 1025 |
};
|
| 1026 |
}
|
| 1027 |
```
|
| 1028 |
|
| 1029 |
A specialization `ctype<char>` is provided so that the member functions
|
| 1030 |
+
on type `char` can be implemented `inline`.[^7] The
|
| 1031 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 1032 |
|
| 1033 |
##### `ctype<char>` destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
|
| 1034 |
|
| 1035 |
``` cpp
|
| 1036 |
~ctype();
|
| 1037 |
```
|
| 1038 |
|
| 1039 |
*Effects:* If the constructor’s first argument was nonzero, and its
|
| 1040 |
+
second argument was `true`, does `delete [] table()`.
|
| 1041 |
|
| 1042 |
##### `ctype<char>` members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
|
| 1043 |
|
| 1044 |
In the following member descriptions, for `unsigned char` values `v`
|
| 1045 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
|
|
|
| 1049 |
``` cpp
|
| 1050 |
explicit ctype(const mask* tbl = 0, bool del = false,
|
| 1051 |
size_t refs = 0);
|
| 1052 |
```
|
| 1053 |
|
| 1054 |
+
*Requires:* `tbl` either 0 or an array of at least `table_size`
|
| 1055 |
+
elements.
|
| 1056 |
|
| 1057 |
*Effects:* Passes its `refs` argument to its base class constructor.
|
| 1058 |
|
| 1059 |
``` cpp
|
| 1060 |
bool is(mask m, char c) const;
|
| 1061 |
const char* is(const char* low, const char* high,
|
| 1062 |
mask* vec) const;
|
| 1063 |
```
|
| 1064 |
|
| 1065 |
*Effects:* The second form, for all `*p` in the range \[`low`, `high`),
|
| 1066 |
+
assigns into `vec[p - low]` the value `table()[(unsigned char)*p]`.
|
| 1067 |
|
| 1068 |
*Returns:* The first form returns `table()[(unsigned char)c] & m`; the
|
| 1069 |
second form returns `high`.
|
| 1070 |
|
| 1071 |
``` cpp
|
|
|
|
| 1127 |
|
| 1128 |
``` cpp
|
| 1129 |
const mask* table() const noexcept;
|
| 1130 |
```
|
| 1131 |
|
| 1132 |
+
*Returns:* The first constructor argument, if it was nonzero, otherwise
|
| 1133 |
`classic_table()`.
|
| 1134 |
|
| 1135 |
##### `ctype<char>` static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
|
| 1136 |
|
| 1137 |
``` cpp
|
| 1138 |
static const mask* classic_table() noexcept;
|
| 1139 |
```
|
| 1140 |
|
| 1141 |
*Returns:* A pointer to the initial element of an array of size
|
| 1142 |
`table_size` which represents the classifications of characters in the
|
| 1143 |
+
`"C"` locale.
|
| 1144 |
|
| 1145 |
##### `ctype<char>` virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
|
| 1146 |
|
| 1147 |
``` cpp
|
| 1148 |
char do_toupper(char) const;
|
|
|
|
| 1173 |
};
|
| 1174 |
|
| 1175 |
template <class internT, class externT, class stateT>
|
| 1176 |
class codecvt : public locale::facet, public codecvt_base {
|
| 1177 |
public:
|
| 1178 |
+
using intern_type = internT;
|
| 1179 |
+
using extern_type = externT;
|
| 1180 |
+
using state_type = stateT;
|
| 1181 |
|
| 1182 |
explicit codecvt(size_t refs = 0);
|
| 1183 |
|
| 1184 |
+
result out(
|
| 1185 |
+
stateT& state,
|
| 1186 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1187 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1188 |
+
|
| 1189 |
+
result unshift(
|
| 1190 |
+
stateT& state,
|
| 1191 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1192 |
+
|
| 1193 |
+
result in(
|
| 1194 |
+
stateT& state,
|
| 1195 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1196 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1197 |
+
|
| 1198 |
int encoding() const noexcept;
|
| 1199 |
bool always_noconv() const noexcept;
|
| 1200 |
+
int length(stateT&, const externT* from, const externT* end, size_t max) const;
|
|
|
|
| 1201 |
int max_length() const noexcept;
|
| 1202 |
|
| 1203 |
static locale::id id;
|
| 1204 |
|
| 1205 |
protected:
|
| 1206 |
~codecvt();
|
| 1207 |
+
virtual result do_out(
|
| 1208 |
+
stateT& state,
|
| 1209 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1210 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1211 |
+
virtual result do_in(
|
| 1212 |
+
stateT& state,
|
| 1213 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1214 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1215 |
+
virtual result do_unshift(
|
| 1216 |
+
stateT& state,
|
| 1217 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1218 |
+
|
| 1219 |
virtual int do_encoding() const noexcept;
|
| 1220 |
virtual bool do_always_noconv() const noexcept;
|
| 1221 |
+
virtual int do_length(stateT&, const externT* from, const externT* end, size_t max) const;
|
|
|
|
| 1222 |
virtual int do_max_length() const noexcept;
|
| 1223 |
};
|
| 1224 |
}
|
| 1225 |
```
|
| 1226 |
|
|
|
|
| 1234 |
|
| 1235 |
The specializations required in Table
|
| 1236 |
[[tab:localization.category.facets]] ([[locale.category]]) convert the
|
| 1237 |
implementation-defined native character set.
|
| 1238 |
`codecvt<char, char, mbstate_t>` implements a degenerate conversion; it
|
| 1239 |
+
does not convert at all. The specialization
|
| 1240 |
+
`codecvt<char16_t, char, mbstate_t>` converts between the UTF-16 and
|
| 1241 |
+
UTF-8 encoding forms, and the specialization `codecvt`
|
| 1242 |
+
`<char32_t, char, mbstate_t>` converts between the UTF-32 and UTF-8
|
| 1243 |
+
encoding forms. `codecvt<wchar_t, char, mbstate_t>` converts between the
|
| 1244 |
+
native character sets for narrow and wide characters. Specializations on
|
| 1245 |
+
`mbstate_t` perform conversion between encodings known to the library
|
| 1246 |
+
implementer. Other encodings can be converted by specializing on a
|
| 1247 |
+
user-defined `stateT` type. Objects of type `stateT` can contain any
|
| 1248 |
+
state that is useful to communicate to or from the specialized `do_in`
|
| 1249 |
+
or `do_out` members.
|
| 1250 |
|
| 1251 |
##### `codecvt` members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
|
| 1252 |
|
| 1253 |
``` cpp
|
| 1254 |
+
result out(
|
| 1255 |
+
stateT& state,
|
| 1256 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1257 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1258 |
```
|
| 1259 |
|
| 1260 |
*Returns:*
|
| 1261 |
+
`do_out(state, from, from_end, from_next, to, to_end, to_next)`.
|
| 1262 |
|
| 1263 |
``` cpp
|
| 1264 |
+
result unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
|
|
|
|
| 1265 |
```
|
| 1266 |
|
| 1267 |
+
*Returns:* `do_unshift(state, to, to_end, to_next)`.
|
| 1268 |
|
| 1269 |
``` cpp
|
| 1270 |
+
result in(
|
| 1271 |
+
stateT& state,
|
| 1272 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1273 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1274 |
```
|
| 1275 |
|
| 1276 |
*Returns:*
|
| 1277 |
+
`do_in(state, from, from_end, from_next, to, to_end, to_next)`.
|
| 1278 |
|
| 1279 |
``` cpp
|
| 1280 |
int encoding() const noexcept;
|
| 1281 |
```
|
| 1282 |
|
| 1283 |
+
*Returns:* `do_encoding()`.
|
| 1284 |
|
| 1285 |
``` cpp
|
| 1286 |
bool always_noconv() const noexcept;
|
| 1287 |
```
|
| 1288 |
|
| 1289 |
+
*Returns:* `do_always_noconv()`.
|
| 1290 |
|
| 1291 |
``` cpp
|
| 1292 |
+
int length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
|
|
|
|
| 1293 |
```
|
| 1294 |
|
| 1295 |
+
*Returns:* `do_length(state, from, from_end, max)`.
|
| 1296 |
|
| 1297 |
``` cpp
|
| 1298 |
int max_length() const noexcept;
|
| 1299 |
```
|
| 1300 |
|
| 1301 |
+
*Returns:* `do_max_length()`.
|
| 1302 |
|
| 1303 |
##### `codecvt` virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
|
| 1304 |
|
| 1305 |
``` cpp
|
| 1306 |
+
result do_out(
|
| 1307 |
+
stateT& state,
|
| 1308 |
const internT* from, const internT* from_end, const internT*& from_next,
|
| 1309 |
externT* to, externT* to_end, externT*& to_next) const;
|
| 1310 |
|
| 1311 |
+
result do_in(
|
| 1312 |
+
stateT& state,
|
| 1313 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1314 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1315 |
```
|
| 1316 |
|
| 1317 |
+
*Requires:* `(from <= from_end && to <= to_end)` well-defined and
|
| 1318 |
`true`; `state` initialized, if at the beginning of a sequence, or else
|
| 1319 |
equal to the result of converting the preceding characters in the
|
| 1320 |
sequence.
|
| 1321 |
|
| 1322 |
+
*Effects:* Translates characters in the source range \[`from`,
|
| 1323 |
+
`from_end`), placing the results in sequential positions starting at
|
| 1324 |
+
destination `to`. Converts no more than `(from_end - from)` source
|
| 1325 |
+
elements, and stores no more than `(to_end - to)` destination elements.
|
| 1326 |
|
| 1327 |
Stops if it encounters a character it cannot convert. It always leaves
|
| 1328 |
the `from_next` and `to_next` pointers pointing one beyond the last
|
| 1329 |
element successfully converted. If returns `noconv`, `internT` and
|
| 1330 |
`externT` are the same type and the converted sequence is identical to
|
| 1331 |
+
the input sequence \[`from`, `from``next`). `to_next` is set equal to
|
| 1332 |
+
`to`, the value of `state` is unchanged, and there are no changes to the
|
| 1333 |
+
values in \[`to`, `to_end`).
|
| 1334 |
|
| 1335 |
A `codecvt` facet that is used by `basic_filebuf` ([[file.streams]])
|
| 1336 |
shall have the property that if
|
| 1337 |
|
| 1338 |
``` cpp
|
|
|
|
| 1355 |
|
| 1356 |
``` cpp
|
| 1357 |
do_in(state, from, from_end, from_next, to, to + 1, to_next)
|
| 1358 |
```
|
| 1359 |
|
| 1360 |
+
shall also return `ok`.[^8]
|
|
|
|
|
|
|
| 1361 |
|
| 1362 |
+
[*Note 1*: As a result of operations on `state`, it can return `ok` or
|
| 1363 |
+
`partial` and set `from_next == from` and
|
| 1364 |
+
`to_next != to`. — *end note*]
|
| 1365 |
+
|
| 1366 |
+
*Remarks:* Its operations on `state` are unspecified.
|
| 1367 |
+
|
| 1368 |
+
[*Note 2*: This argument can be used, for example, to maintain shift
|
| 1369 |
+
state, to specify conversion options (such as count only), or to
|
| 1370 |
+
identify a cache of seek offsets. — *end note*]
|
| 1371 |
|
| 1372 |
*Returns:* An enumeration value, as summarized in
|
| 1373 |
Table [[tab:localization.convert.result.values.out.in]].
|
| 1374 |
|
| 1375 |
**Table: `do_in/do_out` result values** <a id="tab:localization.convert.result.values.out.in">[tab:localization.convert.result.values.out.in]</a>
|
| 1376 |
|
| 1377 |
| Value | Meaning |
|
| 1378 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 1379 |
| `ok` | completed the conversion |
|
| 1380 |
| `partial` | not all source characters converted |
|
| 1381 |
+
| `error` | encountered a character in {[}`from`, `from_end`{)} that it could not convert |
|
| 1382 |
| `noconv` | `internT` and `externT` are the same type, and input sequence is identical to converted sequence |
|
| 1383 |
|
| 1384 |
|
| 1385 |
+
A return value of `partial`, if `(from_next == from_end)`, indicates
|
| 1386 |
+
that either the destination sequence has not absorbed all the available
|
| 1387 |
destination elements, or that additional source elements are needed
|
| 1388 |
before another destination element can be produced.
|
| 1389 |
|
| 1390 |
``` cpp
|
| 1391 |
+
result do_unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
|
|
|
|
| 1392 |
```
|
| 1393 |
|
| 1394 |
+
*Requires:* `(to <= to_end)` well defined and `true`; state initialized,
|
| 1395 |
if at the beginning of a sequence, or else equal to the result of
|
| 1396 |
converting the preceding characters in the sequence.
|
| 1397 |
|
| 1398 |
*Effects:* Places characters starting at `to` that should be appended to
|
| 1399 |
+
terminate a sequence when the current `stateT` is given by `state`.[^9]
|
| 1400 |
Stores no more than `(to_end - to)` destination elements, and leaves the
|
| 1401 |
`to_next` pointer pointing one beyond the last element successfully
|
| 1402 |
stored.
|
| 1403 |
|
| 1404 |
*Returns:* An enumeration value, as summarized in
|
| 1405 |
Table [[tab:localization.convert.result.values.unshift]].
|
| 1406 |
|
| 1407 |
**Table: `do_unshift` result values** <a id="tab:localization.convert.result.values.unshift">[tab:localization.convert.result.values.unshift]</a>
|
| 1408 |
|
| 1409 |
| Value | Meaning |
|
| 1410 |
+
| --------- | -------------------------------------------------------------------------------------------------------------------- |
|
| 1411 |
| `ok` | completed the sequence |
|
| 1412 |
| `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
|
| 1413 |
| `error` | an unspecified error has occurred |
|
| 1414 |
| `noconv` | no termination is needed for this `state_type` |
|
| 1415 |
|
| 1416 |
``` cpp
|
| 1417 |
int do_encoding() const noexcept;
|
| 1418 |
```
|
| 1419 |
|
| 1420 |
+
*Returns:* `-1` if the encoding of the `externT` sequence is
|
| 1421 |
state-dependent; else the constant number of `externT` characters needed
|
| 1422 |
+
to produce an internal character; or `0` if this number is not a
|
| 1423 |
+
constant.[^10]
|
| 1424 |
|
| 1425 |
``` cpp
|
| 1426 |
bool do_always_noconv() const noexcept;
|
| 1427 |
```
|
| 1428 |
|
| 1429 |
*Returns:* `true` if `do_in()` and `do_out()` return `noconv` for all
|
| 1430 |
valid argument values. `codecvt<char, char, mbstate_t>` returns `true`.
|
| 1431 |
|
| 1432 |
``` cpp
|
| 1433 |
+
int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
|
|
|
|
| 1434 |
```
|
| 1435 |
|
| 1436 |
+
*Requires:* `(from <= from_end)` well-defined and `true`; `state`
|
| 1437 |
initialized, if at the beginning of a sequence, or else equal to the
|
| 1438 |
result of converting the preceding characters in the sequence.
|
| 1439 |
|
| 1440 |
*Effects:* The effect on the `state` argument is “as if” it called
|
| 1441 |
`do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
|
| 1442 |
to a buffer of at least `max` elements.
|
| 1443 |
|
| 1444 |
*Returns:* `(from_next-from)` where `from_next` is the largest value in
|
| 1445 |
+
the range \[`from`, `from_end`\] such that the sequence of values in the
|
| 1446 |
range \[`from`, `from_next`) represents `max` or fewer valid complete
|
| 1447 |
characters of type `internT`. The specialization
|
| 1448 |
`codecvt<char, char, mbstate_t>`, returns the lesser of `max` and
|
| 1449 |
`(from_end-from)`.
|
| 1450 |
|
| 1451 |
``` cpp
|
| 1452 |
int do_max_length() const noexcept;
|
| 1453 |
```
|
| 1454 |
|
| 1455 |
*Returns:* The maximum value that `do_length(state, from, from_end, 1)`
|
| 1456 |
+
can return for any valid range \[`from`, `from_end`) and `stateT` value
|
| 1457 |
`state`. The specialization
|
| 1458 |
`codecvt<char, char, mbstate_t>::do_max_length()` returns 1.
|
| 1459 |
|
| 1460 |
#### Class template `codecvt_byname` <a id="locale.codecvt.byname">[[locale.codecvt.byname]]</a>
|
| 1461 |
|
|
|
|
| 1475 |
### The numeric category <a id="category.numeric">[[category.numeric]]</a>
|
| 1476 |
|
| 1477 |
The classes `num_get<>` and `num_put<>` handle numeric formatting and
|
| 1478 |
parsing. Virtual functions are provided for several numeric types.
|
| 1479 |
Implementations may (but are not required to) delegate extraction of
|
| 1480 |
+
smaller types to extractors for larger types.[^11]
|
| 1481 |
|
| 1482 |
All specifications of member functions for `num_put` and `num_get` in
|
| 1483 |
the subclauses of [[category.numeric]] only apply to the
|
| 1484 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 1485 |
and [[tab:localization.required.specializations]] (
|
|
|
|
| 1500 |
``` cpp
|
| 1501 |
namespace std {
|
| 1502 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 1503 |
class num_get : public locale::facet {
|
| 1504 |
public:
|
| 1505 |
+
using char_type = charT;
|
| 1506 |
+
using iter_type = InputIterator;
|
| 1507 |
|
| 1508 |
explicit num_get(size_t refs = 0);
|
| 1509 |
|
| 1510 |
iter_type get(iter_type in, iter_type end, ios_base&,
|
| 1511 |
ios_base::iostate& err, bool& v) const;
|
|
|
|
| 1677 |
| `double` | `l` |
|
| 1678 |
| `long double` | `L` |
|
| 1679 |
|
| 1680 |
- **Stage 2:**
|
| 1681 |
|
| 1682 |
+
If `in == end` then stage 2 terminates. Otherwise a `charT` is taken
|
| 1683 |
+
from `in` and local variables are initialized as if by
|
| 1684 |
|
| 1685 |
``` cpp
|
| 1686 |
char_type ct = *in;
|
| 1687 |
char c = src[find(atoms, atoms + sizeof(src) - 1, ct) - atoms];
|
| 1688 |
if (ct == use_facet<numpunct<charT>>(loc).decimal_point())
|
|
|
|
| 1700 |
use_facet<ctype<charT>>(loc).widen(src, src + sizeof(src), atoms);
|
| 1701 |
```
|
| 1702 |
|
| 1703 |
for this value of `loc`.
|
| 1704 |
|
| 1705 |
+
If `discard` is `true`, then if `’.’` has not yet been accumulated, then
|
| 1706 |
the position of the character is remembered, but the character is
|
| 1707 |
otherwise ignored. Otherwise, if `’.’` has already been accumulated, the
|
| 1708 |
character is discarded and Stage 2 terminates. If it is not discarded,
|
| 1709 |
then a check is made to determine if `c` is allowed as the next
|
| 1710 |
character of an input field of the conversion specifier returned by
|
|
|
|
| 1721 |
|
| 1722 |
- For a signed integer value, the function `strtoll`.
|
| 1723 |
|
| 1724 |
- For an unsigned integer value, the function `strtoull`.
|
| 1725 |
|
| 1726 |
+
- For a `float` value, the function `strtof`.
|
| 1727 |
+
|
| 1728 |
+
- For a `double` value, the function `strtod`.
|
| 1729 |
+
|
| 1730 |
+
- For a `long double` value, the function `strtold`.
|
| 1731 |
|
| 1732 |
The numeric value to be stored can be one of:
|
| 1733 |
|
| 1734 |
+
- zero, if the conversion function does not convert the entire field.
|
|
|
|
| 1735 |
|
| 1736 |
+
- the most positive (or negative) representable value, if the field to
|
| 1737 |
+
be converted to a signed integer type represents a value too large
|
| 1738 |
+
positive (or negative) to be represented in `val`.
|
| 1739 |
|
| 1740 |
+
- the most positive representable value, if the field to be converted to
|
| 1741 |
+
an unsigned integer type represents a value that cannot be represented
|
| 1742 |
+
in `val`.
|
| 1743 |
|
| 1744 |
- the converted value, otherwise.
|
| 1745 |
|
| 1746 |
+
The resultant numeric value is stored in `val`. If the conversion
|
| 1747 |
+
function does not convert the entire field, or if the field represents a
|
| 1748 |
+
value outside the range of representable values, `ios_base::failbit` is
|
| 1749 |
+
assigned to `err`.
|
| 1750 |
|
| 1751 |
Digit grouping is checked. That is, the positions of discarded
|
| 1752 |
separators is examined for consistency with
|
| 1753 |
+
`use_facet<numpunct<charT>>(loc).grouping()`. If they are not consistent
|
| 1754 |
+
then `ios_base::failbit` is assigned to `err`.
|
| 1755 |
|
| 1756 |
In any case, if stage 2 processing was terminated by the test for
|
| 1757 |
`in == end` then `err |= ios_base::eofbit` is performed.
|
| 1758 |
|
| 1759 |
``` cpp
|
| 1760 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 1761 |
ios_base::iostate& err, bool& val) const;
|
| 1762 |
```
|
| 1763 |
|
| 1764 |
+
*Effects:* If `(str.flags()&ios_base::boolalpha) == 0` then input
|
| 1765 |
proceeds as it would for a `long` except that if a value is being stored
|
| 1766 |
into `val`, the value is determined according to the following: If the
|
| 1767 |
+
value to be stored is 0 then `false` is stored. If the value is `1` then
|
| 1768 |
`true` is stored. Otherwise `true` is stored and `ios_base::failbit` is
|
| 1769 |
assigned to `err`.
|
| 1770 |
|
| 1771 |
Otherwise target sequences are determined “as if” by calling the members
|
| 1772 |
`falsename()` and `truename()` of the facet obtained by
|
| 1773 |
+
`use_facet<numpunct<charT>>(str.getloc())`. Successive characters in the
|
| 1774 |
+
range \[`in`, `end`) (see [[sequence.reqmts]]) are obtained and matched
|
| 1775 |
+
against corresponding positions in the target sequences only as
|
| 1776 |
necessary to identify a unique match. The input iterator `in` is
|
| 1777 |
compared to `end` only when necessary to obtain a character. If a target
|
| 1778 |
sequence is uniquely matched, `val` is set to the corresponding value.
|
| 1779 |
Otherwise `false` is stored and `ios_base::failbit` is assigned to
|
| 1780 |
`err`.
|
|
|
|
| 1782 |
The `in` iterator is always left pointing one position beyond the last
|
| 1783 |
character successfully matched. If `val` is set, then `err` is set to
|
| 1784 |
`str.goodbit`; or to `str.eofbit` if, when seeking another character to
|
| 1785 |
match, it is found that `(in == end)`. If `val` is not set, then `err`
|
| 1786 |
is set to `str.failbit`; or to `(str.failbit|str.eofbit)` if the reason
|
| 1787 |
+
for the failure was that `(in == end)`.
|
| 1788 |
+
|
| 1789 |
+
[*Example 1*: For targets `true`: `"a"` and `false`: `"abb"`, the input
|
| 1790 |
+
sequence `"a"` yields `val == true` and `err == str.eofbit`; the input
|
| 1791 |
+
sequence `"abc"` yields `err = str.failbit`, with `in` ending at the
|
| 1792 |
+
`’c’` element. For targets `true`: `"1"` and `false`: `"0"`, the input
|
| 1793 |
+
sequence `"1"` yields `val == true` and `err == str.goodbit`. For empty
|
| 1794 |
+
targets `("")`, any input sequence yields
|
| 1795 |
+
`err == str.failbit`. — *end example*]
|
| 1796 |
|
| 1797 |
*Returns:* `in`.
|
| 1798 |
|
| 1799 |
#### Class template `num_put` <a id="locale.nm.put">[[locale.nm.put]]</a>
|
| 1800 |
|
| 1801 |
``` cpp
|
| 1802 |
namespace std {
|
| 1803 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 1804 |
class num_put : public locale::facet {
|
| 1805 |
public:
|
| 1806 |
+
using char_type = charT;
|
| 1807 |
+
using iter_type = OutputIterator;
|
| 1808 |
|
| 1809 |
explicit num_put(size_t refs = 0);
|
| 1810 |
|
| 1811 |
iter_type put(iter_type s, ios_base& f, char_type fill, bool v) const;
|
| 1812 |
iter_type put(iter_type s, ios_base& f, char_type fill, long v) const;
|
| 1813 |
iter_type put(iter_type s, ios_base& f, char_type fill, long long v) const;
|
| 1814 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long v) const;
|
| 1815 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long long v) const;
|
| 1816 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, double v) const;
|
| 1817 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, long double v) const;
|
| 1818 |
+
iter_type put(iter_type s, ios_base& f, char_type fill, const void* v) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1819 |
|
| 1820 |
static locale::id id;
|
| 1821 |
|
| 1822 |
protected:
|
| 1823 |
~num_put();
|
| 1824 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, bool v) const;
|
| 1825 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, long v) const;
|
| 1826 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, long long v) const;
|
| 1827 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long) const;
|
| 1828 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long long) const;
|
| 1829 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, double v) const;
|
| 1830 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, long double v) const;
|
| 1831 |
+
virtual iter_type do_put(iter_type, ios_base&, char_type fill, const void* v) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1832 |
};
|
| 1833 |
}
|
| 1834 |
```
|
| 1835 |
|
| 1836 |
The facet `num_put` is used to format numeric values to a character
|
| 1837 |
sequence such as an ostream.
|
| 1838 |
|
| 1839 |
##### `num_put` members <a id="facet.num.put.members">[[facet.num.put.members]]</a>
|
| 1840 |
|
| 1841 |
``` cpp
|
| 1842 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, bool val) const;
|
| 1843 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1844 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
| 1845 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
|
| 1846 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
|
| 1847 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, double val) const;
|
| 1848 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, long double val) const;
|
| 1849 |
+
iter_type put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1850 |
```
|
| 1851 |
|
| 1852 |
*Returns:* `do_put(out, str, fill, val)`.
|
| 1853 |
|
| 1854 |
##### `num_put` virtual functions <a id="facet.num.put.virtuals">[[facet.num.put.virtuals]]</a>
|
| 1855 |
|
| 1856 |
``` cpp
|
| 1857 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1858 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
| 1859 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
|
| 1860 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
|
| 1861 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, double val) const;
|
| 1862 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, long double val) const;
|
| 1863 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1864 |
```
|
| 1865 |
|
| 1866 |
*Effects:* Writes characters to the sequence `out`, formatting `val` as
|
| 1867 |
+
desired. In the following description, a local variable initialized
|
| 1868 |
+
with:
|
| 1869 |
|
| 1870 |
``` cpp
|
| 1871 |
locale loc = str.getloc();
|
| 1872 |
```
|
| 1873 |
|
| 1874 |
The details of this operation occur in several stages:
|
| 1875 |
|
| 1876 |
+
- Stage 1: Determine a printf conversion specifier `spec` and determine
|
| 1877 |
+
the characters that would be printed by `printf` ([[c.files]]) given
|
| 1878 |
+
this conversion specifier for
|
| 1879 |
``` cpp
|
| 1880 |
printf(spec, val)
|
| 1881 |
```
|
| 1882 |
|
| 1883 |
assuming that the current locale is the `"C"` locale.
|
|
|
|
| 1902 |
fmtflags basefield = (flags & (ios_base::basefield));
|
| 1903 |
fmtflags uppercase = (flags & (ios_base::uppercase));
|
| 1904 |
fmtflags floatfield = (flags & (ios_base::floatfield));
|
| 1905 |
fmtflags showpos = (flags & (ios_base::showpos));
|
| 1906 |
fmtflags showbase = (flags & (ios_base::showbase));
|
| 1907 |
+
fmtflags showpoint = (flags & (ios_base::showpoint));
|
| 1908 |
```
|
| 1909 |
|
| 1910 |
All tables used in describing stage 1 are ordered. That is, the first
|
| 1911 |
line whose condition is true applies. A line without a condition is the
|
| 1912 |
default behavior when none of the earlier lines apply.
|
|
|
|
| 1964 |
Table [[tab:localization.numeric.conversions]].
|
| 1965 |
|
| 1966 |
**Table: Numeric conversions** <a id="tab:localization.numeric.conversions">[tab:localization.numeric.conversions]</a>
|
| 1967 |
|
| 1968 |
| Type(s) | State | `stdio` equivalent |
|
| 1969 |
+
| --------------------- | ----------- | ------------------ |
|
| 1970 |
+
| an integral type | `showpos` | `+` |
|
| 1971 |
+
| | `showbase` | `#` |
|
| 1972 |
+
| a floating-point type | `showpos` | `+` |
|
| 1973 |
+
| | `showpoint` | `#` |
|
| 1974 |
|
| 1975 |
|
| 1976 |
For conversion from a floating-point type, if
|
| 1977 |
`floatfield != (ios_base::fixed | ios_base::scientific)`,
|
| 1978 |
`str.precision()` is specified as precision in the conversion
|
|
|
|
| 2008 |
|
| 2009 |
``` cpp
|
| 2010 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 2011 |
```
|
| 2012 |
|
| 2013 |
+
The location of any padding[^12] is determined according to
|
| 2014 |
Table [[tab:localization.fill.padding]].
|
| 2015 |
|
| 2016 |
**Table: Fill padding** <a id="tab:localization.fill.padding">[tab:localization.fill.padding]</a>
|
| 2017 |
|
| 2018 |
| State | Location |
|
|
|
|
| 2038 |
``` cpp
|
| 2039 |
*out++ = c
|
| 2040 |
```
|
| 2041 |
|
| 2042 |
``` cpp
|
| 2043 |
+
iter_type do_put(iter_type out, ios_base& str, char_type fill, bool val) const;
|
|
|
|
| 2044 |
```
|
| 2045 |
|
| 2046 |
*Returns:* If `(str.flags() & ios_base::boolalpha) == 0` returns
|
| 2047 |
`do_put(out, str, fill,`
|
| 2048 |
`(int)val)`, otherwise obtains a string `s` as if by
|
|
|
|
| 2063 |
``` cpp
|
| 2064 |
namespace std {
|
| 2065 |
template <class charT>
|
| 2066 |
class numpunct : public locale::facet {
|
| 2067 |
public:
|
| 2068 |
+
using char_type = charT;
|
| 2069 |
+
using string_type = basic_string<charT>;
|
| 2070 |
|
| 2071 |
explicit numpunct(size_t refs = 0);
|
| 2072 |
|
| 2073 |
char_type decimal_point() const;
|
| 2074 |
char_type thousands_sep() const;
|
|
|
|
| 2127 |
|
| 2128 |
``` cpp
|
| 2129 |
char_type decimal_point() const;
|
| 2130 |
```
|
| 2131 |
|
| 2132 |
+
*Returns:* `do_decimal_point()`.
|
| 2133 |
|
| 2134 |
``` cpp
|
| 2135 |
char_type thousands_sep() const;
|
| 2136 |
```
|
| 2137 |
|
| 2138 |
+
*Returns:* `do_thousands_sep()`.
|
| 2139 |
|
| 2140 |
``` cpp
|
| 2141 |
string grouping() const;
|
| 2142 |
```
|
| 2143 |
|
| 2144 |
+
*Returns:* `do_grouping()`.
|
| 2145 |
|
| 2146 |
``` cpp
|
| 2147 |
string_type truename() const;
|
| 2148 |
string_type falsename() const;
|
| 2149 |
```
|
|
|
|
| 2170 |
string do_grouping() const;
|
| 2171 |
```
|
| 2172 |
|
| 2173 |
*Returns:* A basic_string\<char\> `vec` used as a vector of integer
|
| 2174 |
values, in which each element `vec[i]` represents the number of
|
| 2175 |
+
digits[^13] in the group at position `i`, starting with position 0 as
|
| 2176 |
the rightmost group. If `vec.size() <= i`, the number is the same as
|
| 2177 |
+
group `(i - 1)`; if `(i < 0 || vec[i] <= 0 || vec[i] == CHAR_MAX)`, the
|
| 2178 |
+
size of the digit group is unlimited.
|
| 2179 |
|
| 2180 |
The required specializations return the empty string, indicating no
|
| 2181 |
grouping.
|
| 2182 |
|
| 2183 |
``` cpp
|
|
|
|
| 2197 |
namespace std {
|
| 2198 |
template <class charT>
|
| 2199 |
class numpunct_byname : public numpunct<charT> {
|
| 2200 |
// this class is specialized for char and wchar_t.
|
| 2201 |
public:
|
| 2202 |
+
using char_type = charT;
|
| 2203 |
+
using string_type = basic_string<charT>;
|
| 2204 |
+
|
| 2205 |
explicit numpunct_byname(const char*, size_t refs = 0);
|
| 2206 |
explicit numpunct_byname(const string&, size_t refs = 0);
|
| 2207 |
protected:
|
| 2208 |
~numpunct_byname();
|
| 2209 |
};
|
|
|
|
| 2217 |
``` cpp
|
| 2218 |
namespace std {
|
| 2219 |
template <class charT>
|
| 2220 |
class collate : public locale::facet {
|
| 2221 |
public:
|
| 2222 |
+
using char_type = charT;
|
| 2223 |
+
using string_type = basic_string<charT>;
|
| 2224 |
|
| 2225 |
explicit collate(size_t refs = 0);
|
| 2226 |
|
| 2227 |
int compare(const charT* low1, const charT* high1,
|
| 2228 |
const charT* low2, const charT* high2) const;
|
|
|
|
| 2258 |
``` cpp
|
| 2259 |
int compare(const charT* low1, const charT* high1,
|
| 2260 |
const charT* low2, const charT* high2) const;
|
| 2261 |
```
|
| 2262 |
|
| 2263 |
+
*Returns:* `do_compare(low1, high1, low2, high2)`.
|
| 2264 |
|
| 2265 |
``` cpp
|
| 2266 |
string_type transform(const charT* low, const charT* high) const;
|
| 2267 |
```
|
| 2268 |
|
| 2269 |
+
*Returns:* `do_transform(low, high)`.
|
| 2270 |
|
| 2271 |
``` cpp
|
| 2272 |
long hash(const charT* low, const charT* high) const;
|
| 2273 |
```
|
| 2274 |
|
| 2275 |
+
*Returns:* `do_hash(low, high)`.
|
| 2276 |
|
| 2277 |
##### `collate` virtual functions <a id="locale.collate.virtuals">[[locale.collate.virtuals]]</a>
|
| 2278 |
|
| 2279 |
``` cpp
|
| 2280 |
int do_compare(const charT* low1, const charT* high1,
|
|
|
|
| 2292 |
```
|
| 2293 |
|
| 2294 |
*Returns:* A `basic_string<charT>` value that, compared
|
| 2295 |
lexicographically with the result of calling `transform()` on another
|
| 2296 |
string, yields the same result as calling `do_compare()` on the same two
|
| 2297 |
+
strings.[^14]
|
| 2298 |
|
| 2299 |
``` cpp
|
| 2300 |
long do_hash(const charT* low, const charT* high) const;
|
| 2301 |
```
|
| 2302 |
|
| 2303 |
*Returns:* An integer value equal to the result of calling `hash()` on
|
| 2304 |
any other string for which `do_compare()` returns 0 (equal) when passed
|
| 2305 |
+
the two strings.
|
| 2306 |
+
|
| 2307 |
+
[*Note 1*: The probability that the result equals that for another
|
| 2308 |
string which does not compare equal should be very small, approaching
|
| 2309 |
+
`(1.0/numeric_limits<unsigned long>::max())`. — *end note*]
|
| 2310 |
|
| 2311 |
#### Class template `collate_byname` <a id="locale.collate.byname">[[locale.collate.byname]]</a>
|
| 2312 |
|
| 2313 |
``` cpp
|
| 2314 |
namespace std {
|
| 2315 |
template <class charT>
|
| 2316 |
class collate_byname : public collate<charT> {
|
| 2317 |
public:
|
| 2318 |
+
using string_type = basic_string<charT>;
|
| 2319 |
+
|
| 2320 |
explicit collate_byname(const char*, size_t refs = 0);
|
| 2321 |
explicit collate_byname(const string&, size_t refs = 0);
|
| 2322 |
protected:
|
| 2323 |
~collate_byname();
|
| 2324 |
};
|
|
|
|
| 2332 |
parsing. All specifications of member functions for `time_put` and
|
| 2333 |
`time_get` in the subclauses of [[category.time]] only apply to the
|
| 2334 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 2335 |
and [[tab:localization.required.specializations]] (
|
| 2336 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 2337 |
+
`ios_base::iostate&`, and `fill` arguments as described in
|
| 2338 |
+
[[locale.categories]], and the `ctype<>` facet, to determine formatting
|
| 2339 |
details.
|
| 2340 |
|
| 2341 |
#### Class template `time_get` <a id="locale.time.get">[[locale.time.get]]</a>
|
| 2342 |
|
| 2343 |
``` cpp
|
|
|
|
| 2348 |
};
|
| 2349 |
|
| 2350 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 2351 |
class time_get : public locale::facet, public time_base {
|
| 2352 |
public:
|
| 2353 |
+
using char_type = charT;
|
| 2354 |
+
using iter_type = InputIterator;
|
| 2355 |
|
| 2356 |
explicit time_get(size_t refs = 0);
|
| 2357 |
|
| 2358 |
dateorder date_order() const { return do_date_order(); }
|
| 2359 |
iter_type get_time(iter_type s, iter_type end, ios_base& f,
|
|
|
|
| 2394 |
```
|
| 2395 |
|
| 2396 |
`time_get`
|
| 2397 |
|
| 2398 |
is used to parse a character sequence, extracting components of a time
|
| 2399 |
+
or date into a `struct tm` object. Each `get` member parses a format as
|
| 2400 |
produced by a corresponding format specifier to `time_put<>::put`. If
|
| 2401 |
the sequence being parsed matches the correct format, the corresponding
|
| 2402 |
members of the `struct tm` argument are set to the values used to
|
| 2403 |
produce the sequence; otherwise either an error is reported or
|
| 2404 |
+
unspecified values are assigned.[^15]
|
| 2405 |
|
| 2406 |
If the end iterator is reached during parsing by any of the `get()`
|
| 2407 |
member functions, the member sets `ios_base::eofbit` in `err`.
|
| 2408 |
|
| 2409 |
##### `time_get` members <a id="locale.time.get.members">[[locale.time.get.members]]</a>
|
| 2410 |
|
| 2411 |
``` cpp
|
| 2412 |
dateorder date_order() const;
|
| 2413 |
```
|
| 2414 |
|
| 2415 |
+
*Returns:* `do_date_order()`.
|
| 2416 |
|
| 2417 |
``` cpp
|
| 2418 |
iter_type get_time(iter_type s, iter_type end, ios_base& str,
|
| 2419 |
ios_base::iostate& err, tm* t) const;
|
| 2420 |
```
|
| 2421 |
|
| 2422 |
+
*Returns:* `do_get_time(s, end, str, err, t)`.
|
| 2423 |
|
| 2424 |
``` cpp
|
| 2425 |
iter_type get_date(iter_type s, iter_type end, ios_base& str,
|
| 2426 |
ios_base::iostate& err, tm* t) const;
|
| 2427 |
```
|
| 2428 |
|
| 2429 |
+
*Returns:* `do_get_date(s, end, str, err, t)`.
|
| 2430 |
|
| 2431 |
``` cpp
|
| 2432 |
iter_type get_weekday(iter_type s, iter_type end, ios_base& str,
|
| 2433 |
ios_base::iostate& err, tm* t) const;
|
| 2434 |
iter_type get_monthname(iter_type s, iter_type end, ios_base& str,
|
| 2435 |
ios_base::iostate& err, tm* t) const;
|
| 2436 |
```
|
| 2437 |
|
| 2438 |
*Returns:* `do_get_weekday(s, end, str, err, t)` or
|
| 2439 |
+
`do_get_monthname(s, end, str, err, t)`.
|
| 2440 |
|
| 2441 |
``` cpp
|
| 2442 |
iter_type get_year(iter_type s, iter_type end, ios_base& str,
|
| 2443 |
ios_base::iostate& err, tm* t) const;
|
| 2444 |
```
|
| 2445 |
|
| 2446 |
+
*Returns:* `do_get_year(s, end, str, err, t)`.
|
| 2447 |
|
| 2448 |
``` cpp
|
| 2449 |
+
iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
| 2450 |
+
tm* t, char format, char modifier = 0) const;
|
| 2451 |
```
|
| 2452 |
|
| 2453 |
+
*Returns:* `do_get(s, end, f, err, t, format, modifier)`.
|
| 2454 |
|
| 2455 |
``` cpp
|
| 2456 |
+
iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
| 2457 |
+
tm* t, const char_type* fmt, const char_type* fmtend) const;
|
| 2458 |
```
|
| 2459 |
|
| 2460 |
*Requires:* \[`fmt`, `fmtend`) shall be a valid range.
|
| 2461 |
|
| 2462 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 2463 |
It then enters a loop, reading zero or more characters from `s` at each
|
| 2464 |
iteration. Unless otherwise specified below, the loop terminates when
|
| 2465 |
the first of the following conditions holds:
|
| 2466 |
|
| 2467 |
+
- The expression `fmt == fmtend` evaluates to `true`.
|
| 2468 |
+
- The expression `err == ios_base::goodbit` evaluates to `false`.
|
| 2469 |
+
- The expression `s == end` evaluates to `true`, in which case the
|
| 2470 |
function evaluates `err = ios_base::eofbit | ios_base::failbit`.
|
| 2471 |
- The next element of `fmt` is equal to `’%’`, optionally followed by a
|
| 2472 |
modifier character, followed by a conversion specifier character,
|
| 2473 |
`format`, together forming a conversion specification valid for the
|
| 2474 |
ISO/IEC 9945 function `strptime`. If the number of elements in the
|
|
|
|
| 2479 |
value of `modifier` is `’\0’` when the optional modifier is absent
|
| 2480 |
from the conversion specification. If `err == ios_base::goodbit` holds
|
| 2481 |
after the evaluation of the expression, the function increments `fmt`
|
| 2482 |
to point just past the end of the conversion specification and
|
| 2483 |
continues looping.
|
| 2484 |
+
- The expression `isspace(*fmt, f.getloc())` evaluates to `true`, in
|
| 2485 |
+
which case the function first increments `fmt` until
|
| 2486 |
+
`fmt == fmtend || !isspace(*fmt, f.getloc())` evaluates to `true`,
|
| 2487 |
+
then advances `s` until `s == end || !isspace(*s, f.getloc())` is
|
| 2488 |
+
`true`, and finally resumes looping.
|
| 2489 |
- The next character read from `s` matches the element pointed to by
|
| 2490 |
`fmt` in a case-insensitive comparison, in which case the function
|
| 2491 |
evaluates `++fmt, ++s` and continues looping. Otherwise, the function
|
| 2492 |
evaluates `err = ios_base::failbit`.
|
| 2493 |
|
| 2494 |
+
[*Note 1*: The function uses the `ctype<charT>` facet installed in
|
| 2495 |
+
`f`’s locale to determine valid whitespace characters. It is unspecified
|
| 2496 |
+
by what means the function performs case-insensitive comparison or
|
| 2497 |
+
whether multi-character sequences are considered while doing
|
| 2498 |
+
so. — *end note*]
|
| 2499 |
|
| 2500 |
+
*Returns:* `s`.
|
| 2501 |
|
| 2502 |
##### `time_get` virtual functions <a id="locale.time.get.virtuals">[[locale.time.get.virtuals]]</a>
|
| 2503 |
|
| 2504 |
``` cpp
|
| 2505 |
dateorder do_date_order() const;
|
| 2506 |
```
|
| 2507 |
|
| 2508 |
*Returns:* An enumeration value indicating the preferred order of
|
| 2509 |
components for those date formats that are composed of day, month, and
|
| 2510 |
+
year.[^16] Returns `no_order` if the date format specified by `’x’`
|
| 2511 |
contains other variable components (e.g., Julian day, week number, week
|
| 2512 |
day).
|
| 2513 |
|
| 2514 |
``` cpp
|
| 2515 |
iter_type do_get_time(iter_type s, iter_type end, ios_base& str,
|
|
|
|
| 2596 |
appropriate for the ISO/IEC 9945 function `strptime`, formed by
|
| 2597 |
concatenating `’%’`, the `modifier` character, when non-NUL, and the
|
| 2598 |
`format` character. When the concatenation fails to yield a complete
|
| 2599 |
valid directive the function leaves the object pointed to by `t`
|
| 2600 |
unchanged and evaluates `err |= ios_base::failbit`. When `s == end`
|
| 2601 |
+
evaluates to `true` after reading a character the function evaluates
|
| 2602 |
`err |= ios_base::eofbit`.
|
| 2603 |
|
| 2604 |
For complex conversion directives such as `%c`, `%x`, or `%X`, or
|
| 2605 |
directives that involve the optional modifiers `E` or `O`, when the
|
| 2606 |
function is unable to unambiguously determine some or all `struct tm`
|
| 2607 |
members from the input sequence \[`s`, `end`), it evaluates
|
| 2608 |
`err |= ios_base::eofbit`. In such cases the values of those `struct tm`
|
| 2609 |
members are unspecified and may be outside their valid range.
|
| 2610 |
|
| 2611 |
+
*Remarks:* It is unspecified whether multiple calls to `do_get()` with
|
| 2612 |
+
the address of the same `struct tm` object will update the current
|
| 2613 |
+
contents of the object or simply overwrite its members. Portable
|
| 2614 |
+
programs must zero out the object before invoking the function.
|
| 2615 |
|
| 2616 |
*Returns:* An iterator pointing immediately beyond the last character
|
| 2617 |
recognized as possibly part of a valid input sequence for the given
|
| 2618 |
`format` and `modifier`.
|
| 2619 |
|
|
|
|
| 2622 |
``` cpp
|
| 2623 |
namespace std {
|
| 2624 |
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 2625 |
class time_get_byname : public time_get<charT, InputIterator> {
|
| 2626 |
public:
|
| 2627 |
+
using dateorder = time_base::dateorder;
|
| 2628 |
+
using iter_type = InputIterator;
|
| 2629 |
|
| 2630 |
explicit time_get_byname(const char*, size_t refs = 0);
|
| 2631 |
explicit time_get_byname(const string&, size_t refs = 0);
|
| 2632 |
protected:
|
| 2633 |
~time_get_byname();
|
|
|
|
| 2640 |
``` cpp
|
| 2641 |
namespace std {
|
| 2642 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2643 |
class time_put : public locale::facet {
|
| 2644 |
public:
|
| 2645 |
+
using char_type = charT;
|
| 2646 |
+
using iter_type = OutputIterator;
|
| 2647 |
|
| 2648 |
explicit time_put(size_t refs = 0);
|
| 2649 |
|
| 2650 |
// the following is implemented in terms of other member functions.
|
| 2651 |
iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb,
|
|
|
|
| 2680 |
interleaved in the output in the order in which they appear in the
|
| 2681 |
pattern. Format sequences are identified by converting each character
|
| 2682 |
`c` to a `char` value as if by `ct.narrow(c, 0)`, where `ct` is a
|
| 2683 |
reference to `ctype<charT>` obtained from `str.getloc()`. The first
|
| 2684 |
character of each sequence is equal to `’%’`, followed by an optional
|
| 2685 |
+
modifier character `mod`[^17] and a format specifier character `spec` as
|
| 2686 |
defined for the function `strftime`. If no modifier character is
|
| 2687 |
present, `mod` is zero. For each valid format sequence identified, calls
|
| 2688 |
`do_put(s, str, fill, t, spec, mod)`.
|
| 2689 |
|
| 2690 |
The second form calls `do_put(s, str, fill, t, format, modifier)`.
|
| 2691 |
|
| 2692 |
+
[*Note 1*: The `fill` argument may be used in the
|
| 2693 |
+
implementation-defined formats or by derivations. A space character is a
|
| 2694 |
+
reasonable default for this argument. — *end note*]
|
| 2695 |
|
| 2696 |
*Returns:* An iterator pointing immediately after the last character
|
| 2697 |
produced.
|
| 2698 |
|
| 2699 |
##### `time_put` virtual functions <a id="locale.time.put.virtuals">[[locale.time.put.virtuals]]</a>
|
|
|
|
| 2705 |
|
| 2706 |
*Effects:* Formats the contents of the parameter `t` into characters
|
| 2707 |
placed on the output sequence `s`. Formatting is controlled by the
|
| 2708 |
parameters `format` and `modifier`, interpreted identically as the
|
| 2709 |
format specifiers in the string argument to the standard library
|
| 2710 |
+
function `strftime()`[^18], except that the sequence of characters
|
| 2711 |
produced for those specifiers that are described as depending on the C
|
| 2712 |
+
locale are instead *implementation-defined*.[^19]
|
| 2713 |
|
| 2714 |
*Returns:* An iterator pointing immediately after the last character
|
| 2715 |
+
produced.
|
| 2716 |
+
|
| 2717 |
+
[*Note 2*: The `fill` argument may be used in the
|
| 2718 |
+
implementation-defined formats or by derivations. A space character is a
|
| 2719 |
+
reasonable default for this argument. — *end note*]
|
| 2720 |
|
| 2721 |
#### Class template `time_put_byname` <a id="locale.time.put.byname">[[locale.time.put.byname]]</a>
|
| 2722 |
|
| 2723 |
``` cpp
|
| 2724 |
namespace std {
|
| 2725 |
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2726 |
class time_put_byname : public time_put<charT, OutputIterator>
|
| 2727 |
{
|
| 2728 |
public:
|
| 2729 |
+
using char_type = charT;
|
| 2730 |
+
using iter_type = OutputIterator;
|
| 2731 |
|
| 2732 |
explicit time_put_byname(const char*, size_t refs = 0);
|
| 2733 |
explicit time_put_byname(const string&, size_t refs = 0);
|
| 2734 |
protected:
|
| 2735 |
~time_put_byname();
|
|
|
|
| 2745 |
All specifications of member functions for `money_put` and `money_get`
|
| 2746 |
in the subclauses of [[category.monetary]] only apply to the
|
| 2747 |
specializations required in Tables [[tab:localization.category.facets]]
|
| 2748 |
and [[tab:localization.required.specializations]] (
|
| 2749 |
[[locale.category]]). Their members use their `ios_base&`,
|
| 2750 |
+
`ios_base::iostate&`, and `fill` arguments as described in
|
| 2751 |
+
[[locale.categories]], and the `moneypunct<>` and `ctype<>` facets, to
|
| 2752 |
determine formatting details.
|
| 2753 |
|
| 2754 |
#### Class template `money_get` <a id="locale.money.get">[[locale.money.get]]</a>
|
| 2755 |
|
| 2756 |
``` cpp
|
| 2757 |
namespace std {
|
| 2758 |
+
template <class charT, class InputIterator = istreambuf_iterator<charT>>
|
|
|
|
| 2759 |
class money_get : public locale::facet {
|
| 2760 |
public:
|
| 2761 |
+
using char_type = charT;
|
| 2762 |
+
using iter_type = InputIterator;
|
| 2763 |
+
using string_type = basic_string<charT>;
|
| 2764 |
|
| 2765 |
explicit money_get(size_t refs = 0);
|
| 2766 |
|
| 2767 |
iter_type get(iter_type s, iter_type end, bool intl,
|
| 2768 |
ios_base& f, ios_base::iostate& err,
|
|
|
|
| 2791 |
long double& quant) const;
|
| 2792 |
iter_type get(s, iter_type end, bool intl, ios_base&f,
|
| 2793 |
ios_base::iostate& err, string_type& quant) const;
|
| 2794 |
```
|
| 2795 |
|
| 2796 |
+
*Returns:* `do_get(s, end, intl, f, err, quant)`.
|
| 2797 |
|
| 2798 |
##### `money_get` virtual functions <a id="locale.money.get.virtuals">[[locale.money.get.virtuals]]</a>
|
| 2799 |
|
| 2800 |
``` cpp
|
| 2801 |
iter_type do_get(iter_type s, iter_type end, bool intl,
|
|
|
|
| 2816 |
does not change `units` or `digits`. Uses the pattern returned by
|
| 2817 |
`mp.neg_format()` to parse all values. The result is returned as an
|
| 2818 |
integral value stored in `units` or as a sequence of digits possibly
|
| 2819 |
preceded by a minus sign (as produced by `ct.widen(c)` where `c` is
|
| 2820 |
`’-’` or in the range from `’0’` through `’9’`, inclusive) stored in
|
| 2821 |
+
`digits`.
|
| 2822 |
+
|
| 2823 |
+
[*Example 1*: The sequence `$1,056.23` in a common United States locale
|
| 2824 |
+
would yield, for `units`, `105623`, or, for `digits`,
|
| 2825 |
+
`"105623"`. — *end example*]
|
| 2826 |
+
|
| 2827 |
+
If `mp.grouping()` indicates that no thousands separators are permitted,
|
| 2828 |
any such characters are not read, and parsing is terminated at the point
|
| 2829 |
where they first appear. Otherwise, thousands separators are optional;
|
| 2830 |
if present, they are checked for correct placement only after all format
|
| 2831 |
components have been read.
|
| 2832 |
|
|
|
|
| 2842 |
|
| 2843 |
If the first character (if any) in the string `pos` returned by
|
| 2844 |
`mp.positive_sign()` or the string `neg` returned by
|
| 2845 |
`mp.negative_sign()` is recognized in the position indicated by `sign`
|
| 2846 |
in the format pattern, it is consumed and any remaining characters in
|
| 2847 |
+
the string are required after all the other format components.
|
| 2848 |
+
|
| 2849 |
+
[*Example 2*: If `showbase` is off, then for a `neg` value of `"()"`
|
| 2850 |
+
and a currency symbol of `"L"`, in `"(100 L)"` the `"L"` is consumed;
|
| 2851 |
+
but if `neg` is `"-"`, the `"L"` in `"-100 L"` is not
|
| 2852 |
+
consumed. — *end example*]
|
| 2853 |
+
|
| 2854 |
+
If `pos` or `neg` is empty, the sign component is optional, and if no
|
| 2855 |
+
sign is detected, the result is given the sign that corresponds to the
|
| 2856 |
+
source of the empty string. Otherwise, the character in the indicated
|
| 2857 |
+
position must match the first character of `pos` or `neg`, and the
|
| 2858 |
+
result is given the corresponding sign. If the first character of `pos`
|
| 2859 |
+
is equal to the first character of `neg`, or if both strings are empty,
|
| 2860 |
+
the result is given a positive sign.
|
| 2861 |
|
| 2862 |
Digits in the numeric monetary component are extracted and placed in
|
| 2863 |
`digits`, or into a character buffer `buf1` for conversion to produce a
|
| 2864 |
value for `units`, in the order in which they appear, preceded by a
|
| 2865 |
minus sign if and only if the result is negative. The value `units` is
|
| 2866 |
+
produced as if by[^20]
|
| 2867 |
|
| 2868 |
``` cpp
|
| 2869 |
for (int i = 0; i < n; ++i)
|
| 2870 |
buf2[i] = src[find(atoms, atoms+sizeof(src), buf1[i]) - atoms];
|
| 2871 |
buf2[n] = 0;
|
|
|
|
| 2886 |
|
| 2887 |
#### Class template `money_put` <a id="locale.money.put">[[locale.money.put]]</a>
|
| 2888 |
|
| 2889 |
``` cpp
|
| 2890 |
namespace std {
|
| 2891 |
+
template <class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
|
|
|
| 2892 |
class money_put : public locale::facet {
|
| 2893 |
public:
|
| 2894 |
+
using char_type = charT;
|
| 2895 |
+
using iter_type = OutputIterator;
|
| 2896 |
+
using string_type = basic_string<charT>;
|
| 2897 |
|
| 2898 |
explicit money_put(size_t refs = 0);
|
| 2899 |
|
| 2900 |
iter_type put(iter_type s, bool intl, ios_base& f,
|
| 2901 |
char_type fill, long double units) const;
|
|
|
|
| 2921 |
long double quant) const;
|
| 2922 |
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
| 2923 |
const string_type& quant) const;
|
| 2924 |
```
|
| 2925 |
|
| 2926 |
+
*Returns:* `do_put(s, intl, f, loc, quant)`.
|
| 2927 |
|
| 2928 |
##### `money_put` virtual functions <a id="locale.money.put.virtuals">[[locale.money.put.virtuals]]</a>
|
| 2929 |
|
| 2930 |
``` cpp
|
| 2931 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
|
|
| 2960 |
`(str.flags() & str.showbase)` is nonzero. If the number of characters
|
| 2961 |
generated for the specified format is less than the value returned by
|
| 2962 |
`str.width()` on entry to the function, then copies of `fill` are
|
| 2963 |
inserted as necessary to pad to the specified width. For the value `af`
|
| 2964 |
equal to `(str.flags() & str.adjustfield)`, if `(af == str.internal)` is
|
| 2965 |
+
`true`, the fill characters are placed where `none` or `space` appears
|
| 2966 |
+
in the formatting pattern; otherwise if `(af == str.left)` is `true`,
|
| 2967 |
+
they are placed after the other characters; otherwise, they are placed
|
| 2968 |
+
before the other characters.
|
| 2969 |
+
|
| 2970 |
+
[*Note 1*: It is possible, with some combinations of format patterns
|
| 2971 |
+
and flag values, to produce output that cannot be parsed using
|
| 2972 |
+
`num_get<>::get`. — *end note*]
|
| 2973 |
|
| 2974 |
*Returns:* An iterator pointing immediately after the last character
|
| 2975 |
produced.
|
| 2976 |
|
| 2977 |
#### Class template `moneypunct` <a id="locale.moneypunct">[[locale.moneypunct]]</a>
|
|
|
|
| 2985 |
};
|
| 2986 |
|
| 2987 |
template <class charT, bool International = false>
|
| 2988 |
class moneypunct : public locale::facet, public money_base {
|
| 2989 |
public:
|
| 2990 |
+
using char_type = charT;
|
| 2991 |
+
using string_type = basic_string<charT>;
|
| 2992 |
|
| 2993 |
explicit moneypunct(size_t refs = 0);
|
| 2994 |
|
| 2995 |
charT decimal_point() const;
|
| 2996 |
charT thousands_sep() const;
|
|
|
|
| 3022 |
|
| 3023 |
The `moneypunct<>` facet defines monetary formatting parameters used by
|
| 3024 |
`money_get<>` and `money_put<>`. A monetary format is a sequence of four
|
| 3025 |
components, specified by a `pattern` value `p`, such that the `part`
|
| 3026 |
value `static_cast<part>(p.field[i])` determines the `i`th component of
|
| 3027 |
+
the format[^21] In the `field` member of a `pattern` object, each value
|
| 3028 |
`symbol`, `sign`, `value`, and either `space` or `none` appears exactly
|
| 3029 |
once. The value `none`, if present, is not first; the value `space`, if
|
| 3030 |
present, is neither first nor last.
|
| 3031 |
|
| 3032 |
Where `none` or `space` appears, white space is permitted in the format,
|
|
|
|
| 3089 |
pattern pos_format() const;
|
| 3090 |
pattern neg_format() const;
|
| 3091 |
```
|
| 3092 |
|
| 3093 |
Each of these functions `F` returns the result of calling the
|
| 3094 |
+
corresponding virtual member function `do_F()`.
|
| 3095 |
|
| 3096 |
##### `moneypunct` virtual functions <a id="locale.moneypunct.virtuals">[[locale.moneypunct.virtuals]]</a>
|
| 3097 |
|
| 3098 |
``` cpp
|
| 3099 |
charT do_decimal_point() const;
|
| 3100 |
```
|
| 3101 |
|
| 3102 |
*Returns:* The radix separator to use in case `do_frac_digits()` is
|
| 3103 |
+
greater than zero.[^22]
|
| 3104 |
|
| 3105 |
``` cpp
|
| 3106 |
charT do_thousands_sep() const;
|
| 3107 |
```
|
| 3108 |
|
| 3109 |
*Returns:* The digit group separator to use in case `do_grouping()`
|
| 3110 |
+
specifies a digit grouping pattern.[^23]
|
| 3111 |
|
| 3112 |
``` cpp
|
| 3113 |
string do_grouping() const;
|
| 3114 |
```
|
| 3115 |
|
| 3116 |
*Returns:* A pattern defined identically as, but not necessarily equal
|
| 3117 |
+
to, the result of `numpunct<charT>::do_grouping()`.[^24]
|
| 3118 |
|
| 3119 |
``` cpp
|
| 3120 |
string_type do_curr_symbol() const;
|
| 3121 |
```
|
| 3122 |
|
| 3123 |
+
*Returns:* A string to use as the currency identifier symbol.[^25]
|
| 3124 |
|
| 3125 |
``` cpp
|
| 3126 |
string_type do_positive_sign() const;
|
| 3127 |
string_type do_negative_sign() const;
|
| 3128 |
```
|
| 3129 |
|
| 3130 |
*Returns:* `do_positive_sign()` returns the string to use to indicate a
|
| 3131 |
+
positive monetary value;[^26] `do_negative_sign()` returns the string to
|
| 3132 |
use to indicate a negative value.
|
| 3133 |
|
| 3134 |
``` cpp
|
| 3135 |
int do_frac_digits() const;
|
| 3136 |
```
|
| 3137 |
|
| 3138 |
*Returns:* The number of digits after the decimal radix separator, if
|
| 3139 |
+
any.[^27]
|
| 3140 |
|
| 3141 |
``` cpp
|
| 3142 |
pattern do_pos_format() const;
|
| 3143 |
pattern do_neg_format() const;
|
| 3144 |
```
|
|
|
|
| 3146 |
*Returns:* The specializations required in
|
| 3147 |
Table [[tab:localization.required.specializations]] ([[locale.category]]),
|
| 3148 |
namely `moneypunct<char>`, `moneypunct<wchar_t>`,
|
| 3149 |
`moneypunct<char, true>`, and `moneypunct<wchar_t, true>`, return an
|
| 3150 |
object of type `pattern` initialized to
|
| 3151 |
+
`{ symbol, sign, none, value }`.[^28]
|
| 3152 |
|
| 3153 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 3154 |
|
| 3155 |
``` cpp
|
| 3156 |
namespace std {
|
| 3157 |
template <class charT, bool Intl = false>
|
| 3158 |
class moneypunct_byname : public moneypunct<charT, Intl> {
|
| 3159 |
public:
|
| 3160 |
+
using pattern = money_base::pattern;
|
| 3161 |
+
using string_type = basic_string<charT>;
|
| 3162 |
|
| 3163 |
explicit moneypunct_byname(const char*, size_t refs = 0);
|
| 3164 |
explicit moneypunct_byname(const string&, size_t refs = 0);
|
| 3165 |
protected:
|
| 3166 |
~moneypunct_byname();
|
|
|
|
| 3177 |
|
| 3178 |
``` cpp
|
| 3179 |
namespace std {
|
| 3180 |
class messages_base {
|
| 3181 |
public:
|
| 3182 |
+
using catalog = unspecified signed integer type;
|
| 3183 |
};
|
| 3184 |
|
| 3185 |
template <class charT>
|
| 3186 |
class messages : public locale::facet, public messages_base {
|
| 3187 |
public:
|
| 3188 |
+
using char_type = charT;
|
| 3189 |
+
using string_type = basic_string<charT>;
|
| 3190 |
|
| 3191 |
explicit messages(size_t refs = 0);
|
| 3192 |
|
| 3193 |
catalog open(const basic_string<char>& fn, const locale&) const;
|
| 3194 |
string_type get(catalog c, int set, int msgid,
|
|
|
|
| 3217 |
```
|
| 3218 |
|
| 3219 |
*Returns:* `do_open(name, loc)`.
|
| 3220 |
|
| 3221 |
``` cpp
|
| 3222 |
+
string_type get(catalog cat, int set, int msgid, const string_type& dfault) const;
|
|
|
|
| 3223 |
```
|
| 3224 |
|
| 3225 |
*Returns:* `do_get(cat, set, msgid, dfault)`.
|
| 3226 |
|
| 3227 |
``` cpp
|
|
|
|
| 3231 |
*Effects:* Calls `do_close(cat)`.
|
| 3232 |
|
| 3233 |
##### `messages` virtual functions <a id="locale.messages.virtuals">[[locale.messages.virtuals]]</a>
|
| 3234 |
|
| 3235 |
``` cpp
|
| 3236 |
+
catalog do_open(const basic_string<char>& name, const locale& loc) const;
|
|
|
|
| 3237 |
```
|
| 3238 |
|
| 3239 |
*Returns:* A value that may be passed to `get()` to retrieve a message
|
| 3240 |
from the message catalog identified by the string `name` according to an
|
| 3241 |
*implementation-defined* mapping. The result can be used until it is
|
|
|
|
| 3245 |
|
| 3246 |
*Remarks:* The locale argument `loc` is used for character set code
|
| 3247 |
conversion when retrieving messages, if needed.
|
| 3248 |
|
| 3249 |
``` cpp
|
| 3250 |
+
string_type do_get(catalog cat, int set, int msgid, const string_type& dfault) const;
|
|
|
|
| 3251 |
```
|
| 3252 |
|
| 3253 |
*Requires:* `cat` shall be a catalog obtained from `open()` and not yet
|
| 3254 |
closed.
|
| 3255 |
|
|
|
|
| 3265 |
closed.
|
| 3266 |
|
| 3267 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 3268 |
|
| 3269 |
*Remarks:* The limit on such resources, if any, is
|
| 3270 |
+
*implementation-defined*.
|
| 3271 |
|
| 3272 |
#### Class template `messages_byname` <a id="locale.messages.byname">[[locale.messages.byname]]</a>
|
| 3273 |
|
| 3274 |
``` cpp
|
| 3275 |
namespace std {
|
| 3276 |
template <class charT>
|
| 3277 |
class messages_byname : public messages<charT> {
|
| 3278 |
public:
|
| 3279 |
+
using catalog = messages_base::catalog;
|
| 3280 |
+
using string_type = basic_string<charT>;
|
| 3281 |
|
| 3282 |
explicit messages_byname(const char*, size_t refs = 0);
|
| 3283 |
explicit messages_byname(const string&, size_t refs = 0);
|
| 3284 |
protected:
|
| 3285 |
~messages_byname();
|
|
|
|
| 3292 |
A C++program may define facets to be added to a locale and used
|
| 3293 |
identically as the built-in facets. To create a new facet interface,
|
| 3294 |
C++programs simply derive from `locale::facet` a class containing a
|
| 3295 |
static member: `static locale::id id`.
|
| 3296 |
|
| 3297 |
+
[*Note 1*: The locale member function templates verify its type and
|
| 3298 |
+
storage class. — *end note*]
|
| 3299 |
+
|
| 3300 |
+
[*Example 1*:
|
| 3301 |
|
| 3302 |
Traditional global localization is still easy:
|
| 3303 |
|
| 3304 |
``` cpp
|
| 3305 |
#include <iostream>
|
|
|
|
| 3317 |
|
| 3318 |
return MyObject(argc, argv).doit();
|
| 3319 |
}
|
| 3320 |
```
|
| 3321 |
|
| 3322 |
+
— *end example*]
|
| 3323 |
+
|
| 3324 |
+
[*Example 2*:
|
| 3325 |
+
|
| 3326 |
Greater flexibility is possible:
|
| 3327 |
|
| 3328 |
``` cpp
|
| 3329 |
#include <iostream>
|
| 3330 |
#include <locale>
|
|
|
|
| 3338 |
}
|
| 3339 |
```
|
| 3340 |
|
| 3341 |
In a European locale, with input `3.456,78`, output is `3456.78`.
|
| 3342 |
|
| 3343 |
+
— *end example*]
|
| 3344 |
+
|
| 3345 |
This can be important even for simple programs, which may need to write
|
| 3346 |
a data file in a fixed format, regardless of a user’s preference.
|
| 3347 |
|
| 3348 |
+
[*Example 3*:
|
| 3349 |
+
|
| 3350 |
Here is an example of the use of locales in a library interface.
|
| 3351 |
|
| 3352 |
``` cpp
|
| 3353 |
// file: Date.h
|
| 3354 |
#include <iosfwd>
|
|
|
|
| 3396 |
}
|
| 3397 |
return s;
|
| 3398 |
}
|
| 3399 |
```
|
| 3400 |
|
| 3401 |
+
— *end example*]
|
| 3402 |
+
|
| 3403 |
A locale object may be extended with a new facet simply by constructing
|
| 3404 |
it with an instance of a class derived from `locale::facet`. The only
|
| 3405 |
member a C++program must define is the static member `id`, which
|
| 3406 |
identifies your class interface as a new facet.
|
| 3407 |
|
| 3408 |
+
[*Example 4*:
|
| 3409 |
+
|
| 3410 |
Classifying Japanese characters:
|
| 3411 |
|
| 3412 |
``` cpp
|
| 3413 |
// file: <jctype>
|
| 3414 |
#include <locale>
|
|
|
|
| 3430 |
#include "jctype" // above
|
| 3431 |
std::locale::id My::JCtype::id; // the static JCtype member declared above.
|
| 3432 |
|
| 3433 |
int main() {
|
| 3434 |
using namespace std;
|
| 3435 |
+
using wctype = ctype<wchar_t>;
|
| 3436 |
locale loc(locale(""), // the user's preferred locale ...
|
| 3437 |
new My::JCtype); // and a new feature ...
|
| 3438 |
wchar_t c = use_facet<wctype>(loc).widen('!');
|
| 3439 |
if (!use_facet<My::JCtype>(loc).is_kanji(c))
|
| 3440 |
cout << "no it isn't!" << endl;
|
|
|
|
| 3441 |
}
|
| 3442 |
```
|
| 3443 |
|
| 3444 |
The new facet is used exactly like the built-in facets.
|
| 3445 |
|
| 3446 |
+
— *end example*]
|
| 3447 |
+
|
| 3448 |
+
[*Example 5*:
|
| 3449 |
+
|
| 3450 |
Replacing an existing facet is even easier. The code does not define a
|
| 3451 |
member `id` because it is reusing the `numpunct<charT>` facet interface:
|
| 3452 |
|
| 3453 |
``` cpp
|
| 3454 |
// file: my_bool.C
|
| 3455 |
#include <iostream>
|
| 3456 |
#include <locale>
|
| 3457 |
#include <string>
|
| 3458 |
namespace My {
|
| 3459 |
using namespace std;
|
| 3460 |
+
using cnumpunct = numpunct_byname<char>;
|
| 3461 |
class BoolNames : public cnumpunct {
|
| 3462 |
protected:
|
| 3463 |
string do_truename() const { return "Oui Oui!"; }
|
| 3464 |
string do_falsename() const { return "Mais Non!"; }
|
| 3465 |
~BoolNames() { }
|
|
|
|
| 3472 |
using namespace std;
|
| 3473 |
// make the user's preferred locale, except for...
|
| 3474 |
locale loc(locale(""), new My::BoolNames(""));
|
| 3475 |
cout.imbue(loc);
|
| 3476 |
cout << boolalpha << "Any arguments today? " << (argc > 1) << endl;
|
|
|
|
| 3477 |
}
|
| 3478 |
```
|
| 3479 |
|
| 3480 |
+
— *end example*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3481 |
|
| 3482 |
## C library locales <a id="c.locales">[[c.locales]]</a>
|
| 3483 |
|
| 3484 |
+
### Header `<clocale>` synopsis <a id="clocale.syn">[[clocale.syn]]</a>
|
| 3485 |
|
| 3486 |
+
``` cpp
|
| 3487 |
+
namespace std {
|
| 3488 |
+
struct lconv;
|
| 3489 |
+
|
| 3490 |
+
char* setlocale(int category, const char* locale);
|
| 3491 |
+
lconv* localeconv();
|
| 3492 |
+
}
|
| 3493 |
+
|
| 3494 |
+
#define NULL see [support.types.nullptr]
|
| 3495 |
+
#define LC_ALL see below
|
| 3496 |
+
#define LC_COLLATE see below
|
| 3497 |
+
#define LC_CTYPE see below
|
| 3498 |
+
#define LC_MONETARY see below
|
| 3499 |
+
#define LC_NUMERIC see below
|
| 3500 |
+
#define LC_TIME see below
|
| 3501 |
+
```
|
| 3502 |
+
|
| 3503 |
+
The contents and meaning of the header `<clocale>` are the same as the C
|
| 3504 |
+
standard library header `<locale.h>`.
|
| 3505 |
|
| 3506 |
Calls to the function `setlocale` may introduce a data race (
|
| 3507 |
[[res.on.data.races]]) with other calls to `setlocale` or with calls to
|
| 3508 |
the functions listed in Table [[tab:setlocale.data.races]].
|
| 3509 |
|
| 3510 |
+
ISO C 7.11.
|
| 3511 |
+
|
| 3512 |
**Table: Potential `setlocale` data races** <a id="tab:setlocale.data.races">[tab:setlocale.data.races]</a>
|
| 3513 |
|
| 3514 |
| | | | | |
|
| 3515 |
| --------- | ---------- | ----------- | ------------ | ---------- |
|
| 3516 |
| `fprintf` | `isprint` | `iswdigit` | `localeconv` | `tolower` |
|
|
|
|
| 3522 |
| `isdigit` | `iswblank` | `iswupper` | `strerror` | `wcstombs` |
|
| 3523 |
| `isgraph` | `iswcntrl` | `iswxdigit` | `strtod` | `wcsxfrm` |
|
| 3524 |
| `islower` | `iswctype` | `isxdigit` | `strxfrm` | `wctomb` |
|
| 3525 |
|
| 3526 |
|
|
|
|
| 3527 |
|
| 3528 |
<!-- Link reference definitions -->
|
| 3529 |
[alg.lex.comparison]: algorithms.md#alg.lex.comparison
|
| 3530 |
[alg.sort]: algorithms.md#alg.sort
|
| 3531 |
[algorithms]: algorithms.md#algorithms
|
| 3532 |
+
[basic.start.static]: basic.md#basic.start.static
|
| 3533 |
[bitmask.types]: library.md#bitmask.types
|
| 3534 |
[c.files]: input.md#c.files
|
| 3535 |
[c.locales]: #c.locales
|
| 3536 |
[category.collate]: #category.collate
|
| 3537 |
[category.ctype]: #category.ctype
|
| 3538 |
[category.messages]: #category.messages
|
| 3539 |
[category.monetary]: #category.monetary
|
| 3540 |
[category.numeric]: #category.numeric
|
| 3541 |
[category.time]: #category.time
|
| 3542 |
[classification]: #classification
|
| 3543 |
+
[clocale.syn]: #clocale.syn
|
| 3544 |
[conversions]: #conversions
|
|
|
|
| 3545 |
[conversions.character]: #conversions.character
|
|
|
|
| 3546 |
[facet.ctype.char.dtor]: #facet.ctype.char.dtor
|
| 3547 |
[facet.ctype.char.members]: #facet.ctype.char.members
|
| 3548 |
[facet.ctype.char.statics]: #facet.ctype.char.statics
|
| 3549 |
[facet.ctype.char.virtuals]: #facet.ctype.char.virtuals
|
| 3550 |
[facet.ctype.special]: #facet.ctype.special
|
|
|
|
| 3601 |
[locale.num.get]: #locale.num.get
|
| 3602 |
[locale.numpunct]: #locale.numpunct
|
| 3603 |
[locale.numpunct.byname]: #locale.numpunct.byname
|
| 3604 |
[locale.operators]: #locale.operators
|
| 3605 |
[locale.statics]: #locale.statics
|
|
|
|
| 3606 |
[locale.syn]: #locale.syn
|
| 3607 |
[locale.time.get]: #locale.time.get
|
| 3608 |
[locale.time.get.byname]: #locale.time.get.byname
|
| 3609 |
[locale.time.get.members]: #locale.time.get.members
|
| 3610 |
[locale.time.get.virtuals]: #locale.time.get.virtuals
|
|
|
|
| 3621 |
[sequence.reqmts]: containers.md#sequence.reqmts
|
| 3622 |
[tab:lib.locale.time.get.virtuals.dogetdate]: #tab:lib.locale.time.get.virtuals.dogetdate
|
| 3623 |
[tab:localization.category.facets]: #tab:localization.category.facets
|
| 3624 |
[tab:localization.convert.result.values.out.in]: #tab:localization.convert.result.values.out.in
|
| 3625 |
[tab:localization.convert.result.values.unshift]: #tab:localization.convert.result.values.unshift
|
|
|
|
| 3626 |
[tab:localization.lib.summary]: #tab:localization.lib.summary
|
| 3627 |
[tab:localization.required.specializations]: #tab:localization.required.specializations
|
| 3628 |
[tab:setlocale.data.races]: #tab:setlocale.data.races
|
| 3629 |
[vector]: containers.md#vector
|
| 3630 |
|
|
|
|
| 3632 |
that is defined in `<ctime>`.
|
| 3633 |
|
| 3634 |
[^2]: Note that in the call to `put` the stream is implicitly converted
|
| 3635 |
to an `ostreambuf_iterator<charT, traits>`.
|
| 3636 |
|
| 3637 |
+
[^3]: This is a complete list of requirements; there are no other
|
| 3638 |
+
requirements. Thus, a facet class need not have a public copy
|
| 3639 |
+
constructor, assignment, default constructor, destructor, etc.
|
| 3640 |
+
|
| 3641 |
+
[^4]: When used in a loop, it is faster to cache the `ctype<>` facet and
|
| 3642 |
use it directly, or use the vector form of `ctype<>::is`.
|
| 3643 |
|
| 3644 |
+
[^5]: The char argument of `do_widen` is intended to accept values
|
| 3645 |
derived from character literals for conversion to the locale’s
|
| 3646 |
encoding.
|
| 3647 |
|
| 3648 |
+
[^6]: In other words, the transformed character is not a member of any
|
| 3649 |
character classification that `c` is not also a member of.
|
| 3650 |
|
| 3651 |
+
[^7]: Only the `char` (not `unsigned char` and `signed char`) form is
|
| 3652 |
provided. The specialization is specified in the standard, and not
|
| 3653 |
left as an implementation detail, because it affects the derivation
|
| 3654 |
interface for `ctype<char>`.
|
| 3655 |
|
| 3656 |
+
[^8]: Informally, this means that `basic_filebuf` assumes that the
|
| 3657 |
mappings from internal to external characters is 1 to N: a `codecvt`
|
| 3658 |
facet that is used by `basic_filebuf` must be able to translate
|
| 3659 |
characters one internal character at a time.
|
| 3660 |
|
| 3661 |
+
[^9]: Typically these will be characters to return the state to
|
| 3662 |
+
`stateT()`.
|
| 3663 |
|
| 3664 |
+
[^10]: If `encoding()` yields `-1`, then more than `max_length()`
|
| 3665 |
+
`externT` elements may be consumed when producing a single `internT`
|
| 3666 |
character, and additional `externT` elements may appear at the end
|
| 3667 |
of a sequence after those that yield the final `internT` character.
|
| 3668 |
|
| 3669 |
+
[^11]: Parsing `"-1"` correctly into, e.g., an `unsigned short` requires
|
| 3670 |
that the corresponding member `get()` at least extract the sign
|
| 3671 |
before delegating.
|
| 3672 |
|
| 3673 |
+
[^12]: The conversion specification `#o` generates a leading `0` which
|
| 3674 |
is *not* a padding character.
|
| 3675 |
|
| 3676 |
+
[^13]: Thus, the string `"\003"` specifies groups of 3 digits each, and
|
| 3677 |
`"3"` probably indicates groups of 51 (!) digits each, because 51 is
|
| 3678 |
the ASCII value of `"3"`.
|
| 3679 |
|
| 3680 |
+
[^14]: This function is useful when one string is being compared to many
|
| 3681 |
other strings.
|
| 3682 |
|
| 3683 |
+
[^15]: In other words, user confirmation is required for reliable
|
| 3684 |
parsing of user-entered dates and times, but machine-generated
|
| 3685 |
formats can be parsed reliably. This allows parsers to be aggressive
|
| 3686 |
about interpreting user variations on standard formats.
|
| 3687 |
|
| 3688 |
+
[^16]: This function is intended as a convenience only, for common
|
| 3689 |
formats, and may return `no_order` in valid locales.
|
| 3690 |
|
| 3691 |
+
[^17]: Although the C programming language defines no modifiers, most
|
| 3692 |
vendors do.
|
| 3693 |
|
| 3694 |
+
[^18]: Interpretation of the `modifier` argument is
|
| 3695 |
implementation-defined, but should follow POSIX conventions.
|
| 3696 |
|
| 3697 |
+
[^19]: Implementations are encouraged to refer to other standards such
|
| 3698 |
as POSIX for these definitions.
|
| 3699 |
|
| 3700 |
+
[^20]: The semantics here are different from `ct.narrow`.
|
| 3701 |
|
| 3702 |
+
[^21]: An array of `char`, rather than an array of `part`, is specified
|
| 3703 |
for `pattern::field` purely for efficiency.
|
| 3704 |
|
| 3705 |
+
[^22]: In common U.S. locales this is `’.’`.
|
| 3706 |
|
| 3707 |
+
[^23]: In common U.S. locales this is `’,’`.
|
| 3708 |
|
| 3709 |
+
[^24]: To specify grouping by 3s, the value is `"\003"` *not* `"3"`.
|
| 3710 |
|
| 3711 |
+
[^25]: For international specializations (second template parameter
|
| 3712 |
`true`) this is typically four characters long, usually three
|
| 3713 |
letters and a space.
|
| 3714 |
|
| 3715 |
+
[^26]: This is usually the empty string.
|
| 3716 |
|
| 3717 |
+
[^27]: In common U.S. locales, this is 2.
|
| 3718 |
|
| 3719 |
+
[^28]: Note that the international symbol returned by `do_curr_sym()`
|
| 3720 |
usually contains a space, itself; for example, `"USD "`.
|