- tmp/tmp3jjhceud/{from.md → to.md} +363 -550
tmp/tmp3jjhceud/{from.md → to.md}
RENAMED
|
@@ -1,25 +1,25 @@
|
|
| 1 |
# Localization library <a id="localization">[[localization]]</a>
|
| 2 |
|
| 3 |
## General <a id="localization.general">[[localization.general]]</a>
|
| 4 |
|
| 5 |
-
This Clause describes components that C++programs may use to
|
| 6 |
-
(and therefore be more portable when confronting) cultural
|
| 7 |
-
The locale facility includes internationalization support
|
| 8 |
-
classification and string collation, numeric, monetary,
|
| 9 |
-
formatting and parsing, and message retrieval.
|
| 10 |
|
| 11 |
The following subclauses describe components for locales themselves, the
|
| 12 |
standard facets, and facilities from the ISO C library, as summarized in
|
| 13 |
-
|
| 14 |
|
| 15 |
-
**Table: Localization library summary** <a id="
|
| 16 |
|
| 17 |
| Subclause | | Header |
|
| 18 |
| --------------------- | ---------------------------- | ----------- |
|
| 19 |
| [[locales]] | Locales | `<locale>` |
|
| 20 |
-
| [[locale.categories]] | Standard `locale`
|
| 21 |
| [[c.locales]] | C library locales | `<clocale>` |
|
| 22 |
|
| 23 |
|
| 24 |
## Header `<locale>` synopsis <a id="locale.syn">[[locale.syn]]</a>
|
| 25 |
|
|
@@ -107,22 +107,22 @@ encapsulate and manipulate the information peculiar to a locale.[^1]
|
|
| 107 |
|
| 108 |
``` cpp
|
| 109 |
namespace std {
|
| 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,
|
| 121 |
all = collate | ctype | monetary | numeric | time | messages;
|
| 122 |
|
| 123 |
-
// construct/copy/destroy
|
| 124 |
locale() noexcept;
|
| 125 |
locale(const locale& other) noexcept;
|
| 126 |
explicit locale(const char* std_name);
|
| 127 |
explicit locale(const string& std_name);
|
| 128 |
locale(const locale& other, const char* std_name, category);
|
|
@@ -131,21 +131,20 @@ namespace std {
|
|
| 131 |
locale(const locale& other, const locale& one, category);
|
| 132 |
~locale(); // not virtual
|
| 133 |
const locale& operator=(const locale& other) noexcept;
|
| 134 |
template<class Facet> locale combine(const locale& other) const;
|
| 135 |
|
| 136 |
-
// locale operations
|
| 137 |
-
|
| 138 |
|
| 139 |
bool operator==(const locale& other) const;
|
| 140 |
-
bool operator!=(const locale& other) const;
|
| 141 |
|
| 142 |
template<class charT, class traits, class Allocator>
|
| 143 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 144 |
const basic_string<charT, traits, Allocator>& s2) const;
|
| 145 |
|
| 146 |
-
// global locale objects
|
| 147 |
static locale global(const locale&);
|
| 148 |
static const locale& classic();
|
| 149 |
};
|
| 150 |
}
|
| 151 |
```
|
|
@@ -166,29 +165,29 @@ An iostream `operator<<` might be implemented as:[^2]
|
|
| 166 |
template<class charT, class traits>
|
| 167 |
basic_ostream<charT, traits>&
|
| 168 |
operator<< (basic_ostream<charT, traits>& s, Date d) {
|
| 169 |
typename basic_ostream<charT, traits>::sentry cerberos(s);
|
| 170 |
if (cerberos) {
|
| 171 |
-
ios_base::iostate err = ios_base::iostate::goodbit;
|
| 172 |
tm tmbuf; d.extract(tmbuf);
|
|
|
|
| 173 |
use_facet<time_put<charT, ostreambuf_iterator<charT, traits>>>(
|
| 174 |
-
|
| 175 |
-
|
|
|
|
| 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 |
-
|
| 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:
|
|
@@ -198,11 +197,11 @@ except that:
|
|
| 198 |
is provided so that a locale may be used as a predicate argument to
|
| 199 |
the standard collections, to collate strings.
|
| 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
|
| 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
|
|
@@ -220,14 +219,14 @@ of) itself. For an unnamed locale, `locale::name()` returns the string
|
|
| 220 |
|
| 221 |
Whether there is one global locale object for the entire program or one
|
| 222 |
global locale object per thread is *implementation-defined*.
|
| 223 |
Implementations should provide one global locale object per thread. If
|
| 224 |
there is a single global locale object for the entire program,
|
| 225 |
-
implementations are not required to avoid data races on it
|
| 226 |
-
[[res.on.data.races]]
|
| 227 |
|
| 228 |
-
####
|
| 229 |
|
| 230 |
##### Type `locale::category` <a id="locale.category">[[locale.category]]</a>
|
| 231 |
|
| 232 |
``` cpp
|
| 233 |
using category = int;
|
|
@@ -252,22 +251,21 @@ category, represents the union of the two categories.
|
|
| 252 |
|
| 253 |
member functions expecting a `category` argument require one of the
|
| 254 |
`category` values defined above, or the union of two or more such
|
| 255 |
values. Such a `category` value identifies a set of locale categories.
|
| 256 |
Each locale category, in turn, identifies a set of locale facets,
|
| 257 |
-
including at least those shown in
|
| 258 |
-
[[tab:localization.category.facets]].
|
| 259 |
|
| 260 |
-
**Table: Locale category facets** <a id="
|
| 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,
|
| 268 |
-
| | `codecvt<char32_t,
|
| 269 |
| | `codecvt<wchar_t, char, mbstate_t>` |
|
| 270 |
| monetary | `moneypunct<char>`, `moneypunct<wchar_t>` |
|
| 271 |
| | `moneypunct<char, true>`, `moneypunct<wchar_t, true>` |
|
| 272 |
| | `money_get<char>`, `money_get<wchar_t>` |
|
| 273 |
| | `money_put<char>`, `money_put<wchar_t>` |
|
|
@@ -278,28 +276,28 @@ including at least those shown in Table
|
|
| 278 |
| | `time_put<char>`, `time_put<wchar_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
|
| 284 |
-
[[
|
| 285 |
-
|
| 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 |
-
|
| 291 |
|
| 292 |
-
**Table: Required specializations** <a id="
|
| 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,
|
| 300 |
-
| | `codecvt_byname<char32_t,
|
| 301 |
| | `codecvt_byname<wchar_t, char, mbstate_t>` |
|
| 302 |
| monetary | `moneypunct_byname<char, International>` |
|
| 303 |
| | `moneypunct_byname<wchar_t, International>` |
|
| 304 |
| | `money_get<C, InputIterator>` |
|
| 305 |
| | `money_put<C, OutputIterator>` |
|
|
@@ -322,18 +320,18 @@ The provided implementation of members of facets `num_get<charT>` and
|
|
| 322 |
obtained by calling member `getloc()` on the `ios_base&` argument to
|
| 323 |
these functions.
|
| 324 |
|
| 325 |
In declarations of facets, a template parameter with name
|
| 326 |
`InputIterator` or `OutputIterator` indicates the set of all possible
|
| 327 |
-
specializations on parameters that
|
| 328 |
-
|
| 329 |
-
[[iterator.requirements]]
|
| 330 |
-
|
| 331 |
-
*implementation-defined* character types that
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
|
| 336 |
##### Class `locale::facet` <a id="locale.facet">[[locale.facet]]</a>
|
| 337 |
|
| 338 |
``` cpp
|
| 339 |
namespace std {
|
|
@@ -359,11 +357,11 @@ static ::std::locale::id id;
|
|
| 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
|
|
@@ -407,35 +405,27 @@ initialization.
|
|
| 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]]
|
| 414 |
|
| 415 |
-
####
|
| 416 |
|
| 417 |
``` cpp
|
| 418 |
locale() noexcept;
|
| 419 |
```
|
| 420 |
|
| 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
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
``` cpp
|
| 433 |
-
locale(const locale& other) noexcept;
|
| 434 |
-
```
|
| 435 |
-
|
| 436 |
-
*Effects:* Constructs a locale which is a copy of `other`.
|
| 437 |
|
| 438 |
``` cpp
|
| 439 |
explicit locale(const char* std_name);
|
| 440 |
```
|
| 441 |
|
|
@@ -500,17 +490,11 @@ const locale& operator=(const locale& other) noexcept;
|
|
| 500 |
|
| 501 |
*Effects:* Creates a copy of `other`, replacing the current value.
|
| 502 |
|
| 503 |
*Returns:* `*this`.
|
| 504 |
|
| 505 |
-
|
| 506 |
-
~locale();
|
| 507 |
-
```
|
| 508 |
-
|
| 509 |
-
A non-virtual destructor that throws no exceptions.
|
| 510 |
-
|
| 511 |
-
#### `locale` members <a id="locale.members">[[locale.members]]</a>
|
| 512 |
|
| 513 |
``` cpp
|
| 514 |
template<class Facet> locale combine(const locale& other) const;
|
| 515 |
```
|
| 516 |
|
|
@@ -522,43 +506,37 @@ except for that one facet of `other` that is identified by `Facet`.
|
|
| 522 |
*Throws:* `runtime_error` if `has_facet<Facet>(other)` is `false`.
|
| 523 |
|
| 524 |
*Remarks:* The resulting locale has no name.
|
| 525 |
|
| 526 |
``` cpp
|
| 527 |
-
|
| 528 |
```
|
| 529 |
|
| 530 |
*Returns:* The name of `*this`, if it has one; otherwise, the string
|
| 531 |
`"*"`.
|
| 532 |
|
| 533 |
-
####
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
bool operator==(const locale& other) const;
|
| 537 |
```
|
| 538 |
|
| 539 |
*Returns:* `true` if both arguments are the same locale, or one is a
|
| 540 |
copy of the other, or each has a name and the names are identical;
|
| 541 |
`false` otherwise.
|
| 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;
|
| 553 |
```
|
| 554 |
|
| 555 |
*Effects:* Compares two strings according to the `collate<charT>` facet.
|
| 556 |
|
| 557 |
*Remarks:* This member operator template (and therefore `locale` itself)
|
| 558 |
-
|
| 559 |
-
|
| 560 |
|
| 561 |
*Returns:*
|
| 562 |
|
| 563 |
``` cpp
|
| 564 |
use_facet<collate<charT>>(*this).compare(s1.data(), s1.data() + s1.size(),
|
|
@@ -574,28 +552,29 @@ locale `loc` simply by ([[alg.sort]], [[vector]]):
|
|
| 574 |
std::sort(v.begin(), v.end(), loc);
|
| 575 |
```
|
| 576 |
|
| 577 |
— *end example*]
|
| 578 |
|
| 579 |
-
####
|
| 580 |
|
| 581 |
``` cpp
|
| 582 |
static locale global(const locale& loc);
|
| 583 |
```
|
| 584 |
|
| 585 |
-
Sets the global locale to its argument.
|
| 586 |
-
|
| 587 |
-
|
| 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*.
|
| 596 |
-
|
|
|
|
|
|
|
| 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()`.
|
|
@@ -616,11 +595,11 @@ change with time.
|
|
| 616 |
|
| 617 |
``` cpp
|
| 618 |
template<class Facet> const Facet& use_facet(const locale& loc);
|
| 619 |
```
|
| 620 |
|
| 621 |
-
*
|
| 622 |
public static member `id` as defined in [[locale.facet]].
|
| 623 |
|
| 624 |
*Returns:* A reference to the corresponding facet of `loc`, if present.
|
| 625 |
|
| 626 |
*Throws:* `bad_cast` if `has_facet<Facet>(loc)` is `false`.
|
|
@@ -658,12 +637,12 @@ 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 |
-
|
| 665 |
|
| 666 |
#### Conversions <a id="conversions">[[conversions]]</a>
|
| 667 |
|
| 668 |
##### Character conversions <a id="conversions.character">[[conversions.character]]</a>
|
| 669 |
|
|
@@ -684,17 +663,17 @@ template <class charT> charT tolower(charT c, const locale& loc);
|
|
| 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()`,
|
| 687 |
respectively. Each such member function takes an `ios_base&` argument
|
| 688 |
whose members `flags()`, `precision()`, and `width()`, specify the
|
| 689 |
-
format of the corresponding datum
|
| 690 |
need to use other facets call its member `getloc()` to retrieve the
|
| 691 |
locale imbued there. Formatting facets use the character argument `fill`
|
| 692 |
to fill out the specified width where necessary.
|
| 693 |
|
| 694 |
The `put()` members make no provision for error reporting. (Any failures
|
| 695 |
-
of the OutputIterator argument
|
| 696 |
iterator.) The `get()` members take an `ios_base::iostate&` argument
|
| 697 |
whose value they ignore, but set to `ios_base::failbit` in case of a
|
| 698 |
parse error.
|
| 699 |
|
| 700 |
Within this clause it is unspecified whether one virtual function calls
|
|
@@ -704,11 +683,11 @@ another virtual function.
|
|
| 704 |
|
| 705 |
``` cpp
|
| 706 |
namespace std {
|
| 707 |
class ctype_base {
|
| 708 |
public:
|
| 709 |
-
using mask =
|
| 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;
|
|
@@ -723,11 +702,11 @@ namespace std {
|
|
| 723 |
static const mask graph = alnum | punct;
|
| 724 |
};
|
| 725 |
}
|
| 726 |
```
|
| 727 |
|
| 728 |
-
The type `mask` is a bitmask type
|
| 729 |
|
| 730 |
#### Class template `ctype` <a id="locale.ctype">[[locale.ctype]]</a>
|
| 731 |
|
| 732 |
``` cpp
|
| 733 |
namespace std {
|
|
@@ -775,35 +754,32 @@ namespace std {
|
|
| 775 |
|
| 776 |
Class `ctype` encapsulates the C library `<cctype>` features. `istream`
|
| 777 |
members are required to use `ctype<>` for character classing during
|
| 778 |
input parsing.
|
| 779 |
|
| 780 |
-
The specializations required in
|
| 781 |
-
[[
|
| 782 |
-
|
| 783 |
-
|
| 784 |
|
| 785 |
##### `ctype` members <a id="locale.ctype.members">[[locale.ctype.members]]</a>
|
| 786 |
|
| 787 |
``` cpp
|
| 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
|
|
@@ -827,22 +803,20 @@ const char* widen(const char* low, const char* high, charT* to) const;
|
|
| 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;
|
| 842 |
-
const charT* do_is(const charT* low, const charT* high,
|
| 843 |
-
mask* vec) 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
|
|
@@ -900,18 +874,17 @@ which a corresponding lower-case character exists, with that character.
|
|
| 900 |
if it is known to exist, or its argument if not. The second form returns
|
| 901 |
`high`.
|
| 902 |
|
| 903 |
``` cpp
|
| 904 |
charT do_widen(char c) const;
|
| 905 |
-
const char* do_widen(const char* low, const char* high,
|
| 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
|
| 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 |
|
|
@@ -921,20 +894,19 @@ The second form transforms each character `*p` in the range \[`low`,
|
|
| 921 |
*Returns:* The first form returns the transformed value. The second form
|
| 922 |
returns `high`.
|
| 923 |
|
| 924 |
``` cpp
|
| 925 |
char do_narrow(charT c, char dfault) const;
|
| 926 |
-
const charT* do_narrow(const charT* low, const charT* high,
|
| 927 |
-
char dfault, char* dest) const;
|
| 928 |
```
|
| 929 |
|
| 930 |
*Effects:* Applies the simplest reasonable transformation from a `charT`
|
| 931 |
value or sequence of `charT` values to the corresponding `char` value or
|
| 932 |
values.
|
| 933 |
|
| 934 |
-
For any character `c` in the basic source character
|
| 935 |
-
|
| 936 |
|
| 937 |
``` cpp
|
| 938 |
do_widen(do_narrow(c, 0)) == c
|
| 939 |
```
|
| 940 |
|
|
@@ -963,45 +935,42 @@ namespace std {
|
|
| 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 |
};
|
| 971 |
}
|
| 972 |
```
|
| 973 |
|
| 974 |
-
#### `ctype`
|
| 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 =
|
| 984 |
-
size_t refs = 0);
|
| 985 |
|
| 986 |
bool is(mask m, char c) const;
|
| 987 |
const char* is(const char* low, const char* high, mask* vec) const;
|
| 988 |
-
const char* scan_is (mask m,
|
| 989 |
-
|
| 990 |
-
const char* scan_not(mask m,
|
| 991 |
-
const char* low, const char* high) const;
|
| 992 |
|
| 993 |
char toupper(char c) const;
|
| 994 |
const char* toupper(char* low, const char* high) const;
|
| 995 |
char tolower(char c) const;
|
| 996 |
const char* tolower(char* low, const char* high) const;
|
| 997 |
|
| 998 |
char widen(char c) const;
|
| 999 |
const char* widen(const char* low, const char* high, char* to) const;
|
| 1000 |
char narrow(char c, char dfault) const;
|
| 1001 |
-
const char* narrow(const char* low, const char* high, char dfault,
|
| 1002 |
-
char* to) const;
|
| 1003 |
|
| 1004 |
static locale::id id;
|
| 1005 |
static const size_t table_size = implementation-defined;
|
| 1006 |
|
| 1007 |
const mask* table() const noexcept;
|
|
@@ -1013,66 +982,60 @@ namespace std {
|
|
| 1013 |
virtual const char* do_toupper(char* low, const char* high) const;
|
| 1014 |
virtual char do_tolower(char c) const;
|
| 1015 |
virtual const char* do_tolower(char* low, const char* high) const;
|
| 1016 |
|
| 1017 |
virtual char do_widen(char c) const;
|
| 1018 |
-
virtual const char* do_widen(const char* low,
|
| 1019 |
-
const char* high,
|
| 1020 |
-
char* to) const;
|
| 1021 |
virtual char do_narrow(char c, char dfault) const;
|
| 1022 |
-
virtual const char* do_narrow(const char* low,
|
| 1023 |
-
const char* high,
|
| 1024 |
char dfault, char* to) const;
|
| 1025 |
};
|
| 1026 |
}
|
| 1027 |
```
|
| 1028 |
|
| 1029 |
A specialization `ctype<char>` is provided so that the member functions
|
| 1030 |
-
on type `char` can be implemented
|
| 1031 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 1032 |
|
| 1033 |
-
#####
|
| 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 |
-
#####
|
| 1043 |
|
| 1044 |
In the following member descriptions, for `unsigned char` values `v`
|
| 1045 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
| 1046 |
implementation-specific value (possibly different for each such value
|
| 1047 |
`v`) without performing the array lookup.
|
| 1048 |
|
| 1049 |
``` cpp
|
| 1050 |
-
explicit ctype(const mask* tbl =
|
| 1051 |
-
size_t refs = 0);
|
| 1052 |
```
|
| 1053 |
|
| 1054 |
-
*
|
| 1055 |
-
|
| 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
|
| 1072 |
-
const char* scan_is(mask m,
|
| 1073 |
-
const char* low, const char* high) const;
|
| 1074 |
```
|
| 1075 |
|
| 1076 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 1077 |
|
| 1078 |
``` cpp
|
|
@@ -1080,12 +1043,11 @@ table()[(unsigned char) *p] & m
|
|
| 1080 |
```
|
| 1081 |
|
| 1082 |
is `true`.
|
| 1083 |
|
| 1084 |
``` cpp
|
| 1085 |
-
const char* scan_not(mask m,
|
| 1086 |
-
const char* low, const char* high) const;
|
| 1087 |
```
|
| 1088 |
|
| 1089 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 1090 |
|
| 1091 |
``` cpp
|
|
@@ -1108,20 +1070,18 @@ const char* tolower(char* low, const char* high) const;
|
|
| 1108 |
|
| 1109 |
*Returns:* `do_tolower(c)` or `do_tolower(low, high)`, respectively.
|
| 1110 |
|
| 1111 |
``` cpp
|
| 1112 |
char widen(char c) const;
|
| 1113 |
-
const char* widen(const char* low, const char* high,
|
| 1114 |
-
char* to) const;
|
| 1115 |
```
|
| 1116 |
|
| 1117 |
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`, respectively.
|
| 1118 |
|
| 1119 |
``` cpp
|
| 1120 |
char narrow(char c, char dfault) const;
|
| 1121 |
-
const char* narrow(const char* low, const char* high,
|
| 1122 |
-
char dfault, char* to) const;
|
| 1123 |
```
|
| 1124 |
|
| 1125 |
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`,
|
| 1126 |
respectively.
|
| 1127 |
|
|
@@ -1130,40 +1090,37 @@ const mask* table() const noexcept;
|
|
| 1130 |
```
|
| 1131 |
|
| 1132 |
*Returns:* The first constructor argument, if it was nonzero, otherwise
|
| 1133 |
`classic_table()`.
|
| 1134 |
|
| 1135 |
-
#####
|
| 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 |
-
#####
|
| 1146 |
|
| 1147 |
``` cpp
|
| 1148 |
char do_toupper(char) const;
|
| 1149 |
const char* do_toupper(char* low, const char* high) const;
|
| 1150 |
char do_tolower(char) const;
|
| 1151 |
const char* do_tolower(char* low, const char* high) const;
|
| 1152 |
|
| 1153 |
virtual char do_widen(char c) const;
|
| 1154 |
-
virtual const char* do_widen(const char* low,
|
| 1155 |
-
const char* high,
|
| 1156 |
-
char* to) const;
|
| 1157 |
virtual char do_narrow(char c, char dfault) const;
|
| 1158 |
-
virtual const char* do_narrow(const char* low,
|
| 1159 |
-
const char* high,
|
| 1160 |
char dfault, char* to) const;
|
| 1161 |
```
|
| 1162 |
|
| 1163 |
These functions are described identically as those members of the same
|
| 1164 |
-
name in the `ctype` class template
|
| 1165 |
|
| 1166 |
#### Class template `codecvt` <a id="locale.codecvt">[[locale.codecvt]]</a>
|
| 1167 |
|
| 1168 |
``` cpp
|
| 1169 |
namespace std {
|
|
@@ -1224,33 +1181,32 @@ namespace std {
|
|
| 1224 |
}
|
| 1225 |
```
|
| 1226 |
|
| 1227 |
The class `codecvt<internT, externT, stateT>` is for use when converting
|
| 1228 |
from one character encoding to another, such as from wide characters to
|
| 1229 |
-
multibyte characters or between wide character encodings such as
|
| 1230 |
and EUC.
|
| 1231 |
|
| 1232 |
The `stateT` argument selects the pair of character encodings being
|
| 1233 |
mapped between.
|
| 1234 |
|
| 1235 |
-
The specializations required in
|
| 1236 |
-
[[
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 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,
|
| 1243 |
encoding forms. `codecvt<wchar_t, char, mbstate_t>` converts between the
|
| 1244 |
-
native character sets for
|
| 1245 |
-
`mbstate_t` perform conversion between encodings known to the library
|
| 1246 |
implementer. Other encodings can be converted by specializing on a
|
| 1247 |
-
|
| 1248 |
state that is useful to communicate to or from the specialized `do_in`
|
| 1249 |
or `do_out` members.
|
| 1250 |
|
| 1251 |
-
#####
|
| 1252 |
|
| 1253 |
``` cpp
|
| 1254 |
result out(
|
| 1255 |
stateT& state,
|
| 1256 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
@@ -1298,11 +1254,11 @@ int length(stateT& state, const externT* from, const externT* from_end, size_t m
|
|
| 1298 |
int max_length() const noexcept;
|
| 1299 |
```
|
| 1300 |
|
| 1301 |
*Returns:* `do_max_length()`.
|
| 1302 |
|
| 1303 |
-
#####
|
| 1304 |
|
| 1305 |
``` cpp
|
| 1306 |
result do_out(
|
| 1307 |
stateT& state,
|
| 1308 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
@@ -1312,14 +1268,14 @@ 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 |
-
*
|
| 1318 |
-
`true`; `state` initialized, if at the beginning of a sequence,
|
| 1319 |
-
equal to the result of converting the preceding characters in
|
| 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.
|
|
@@ -1330,12 +1286,12 @@ 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`
|
| 1336 |
-
|
| 1337 |
|
| 1338 |
``` cpp
|
| 1339 |
do_out(state, from, from_end, from_next, to, to_end, to_next)
|
| 1340 |
```
|
| 1341 |
|
|
@@ -1368,13 +1324,13 @@ shall also return `ok`.[^8]
|
|
| 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 |
-
|
| 1374 |
|
| 1375 |
-
**Table: `do_in/do_out` result values** <a id="
|
| 1376 |
|
| 1377 |
| Value | Meaning |
|
| 1378 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 1379 |
| `ok` | completed the conversion |
|
| 1380 |
| `partial` | not all source characters converted |
|
|
@@ -1389,24 +1345,24 @@ 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 |
-
*
|
| 1395 |
-
if at the beginning of a sequence, or else equal to the
|
| 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 |
-
|
| 1406 |
|
| 1407 |
-
**Table: `do_unshift` result values** <a id="
|
| 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` |
|
|
@@ -1431,15 +1387,16 @@ 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 |
-
*
|
| 1437 |
-
initialized, if at the beginning of a sequence, or else
|
| 1438 |
-
result of converting the preceding characters in the
|
|
|
|
| 1439 |
|
| 1440 |
-
*Effects:* The effect on the `state` argument is
|
| 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
|
|
@@ -1464,10 +1421,11 @@ namespace std {
|
|
| 1464 |
template<class internT, class externT, class stateT>
|
| 1465 |
class codecvt_byname : public codecvt<internT, externT, stateT> {
|
| 1466 |
public:
|
| 1467 |
explicit codecvt_byname(const char*, size_t refs = 0);
|
| 1468 |
explicit codecvt_byname(const string&, size_t refs = 0);
|
|
|
|
| 1469 |
protected:
|
| 1470 |
~codecvt_byname();
|
| 1471 |
};
|
| 1472 |
}
|
| 1473 |
```
|
|
@@ -1479,19 +1437,18 @@ 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:
|
| 1485 |
-
|
| 1486 |
-
|
| 1487 |
-
`
|
| 1488 |
-
|
| 1489 |
-
|
| 1490 |
-
|
| 1491 |
-
|
| 1492 |
-
`ctype<>` facet to perform character classification.
|
| 1493 |
|
| 1494 |
Extractor and inserter members of the standard iostreams use `num_get<>`
|
| 1495 |
and `num_put<>` member functions for formatting and parsing numeric
|
| 1496 |
values ([[istream.formatted.reqmts]], [[ostream.formatted.reqmts]]).
|
| 1497 |
|
|
@@ -1561,11 +1518,11 @@ namespace std {
|
|
| 1561 |
```
|
| 1562 |
|
| 1563 |
The facet `num_get` is used to parse numeric values from an input
|
| 1564 |
sequence such as an istream.
|
| 1565 |
|
| 1566 |
-
#####
|
| 1567 |
|
| 1568 |
``` cpp
|
| 1569 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
| 1570 |
ios_base::iostate& err, bool& val) const;
|
| 1571 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
|
@@ -1590,11 +1547,11 @@ iter_type get(iter_type in, iter_type end, ios_base& str,
|
|
| 1590 |
ios_base::iostate& err, void*& val) const;
|
| 1591 |
```
|
| 1592 |
|
| 1593 |
*Returns:* `do_get(in, end, str, err, val)`.
|
| 1594 |
|
| 1595 |
-
#####
|
| 1596 |
|
| 1597 |
``` cpp
|
| 1598 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 1599 |
ios_base::iostate& err, long& val) const;
|
| 1600 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
|
@@ -1641,32 +1598,32 @@ fmtflags basefield = (flags & ios_base::basefield);
|
|
| 1641 |
fmtflags uppercase = (flags & ios_base::uppercase);
|
| 1642 |
fmtflags boolalpha = (flags & ios_base::boolalpha);
|
| 1643 |
```
|
| 1644 |
|
| 1645 |
For conversion to an integral type, the function determines the integral
|
| 1646 |
-
conversion specifier as indicated in
|
| 1647 |
-
|
| 1648 |
-
|
| 1649 |
|
| 1650 |
-
**Table: Integer conversions** <a id="
|
| 1651 |
|
| 1652 |
| State | `stdio` equivalent |
|
| 1653 |
| ------------------------ | ------------------ |
|
| 1654 |
| `basefield == oct` | `%o` |
|
| 1655 |
| `basefield == hex` | `%X` |
|
| 1656 |
| `basefield == 0` | `%i` `signed` integral type | `%d` |
|
| 1657 |
| `unsigned` integral type | `%u` |
|
| 1658 |
|
| 1659 |
|
| 1660 |
-
For conversions to a floating type the specifier is `%g`.
|
| 1661 |
|
| 1662 |
For conversions to `void*` the specifier is `%p`.
|
| 1663 |
|
| 1664 |
A length modifier is added to the conversion specification, if needed,
|
| 1665 |
-
as indicated in
|
| 1666 |
|
| 1667 |
-
**Table: Length modifier** <a id="
|
| 1668 |
|
| 1669 |
| Type | Length modifier |
|
| 1670 |
| -------------------- | --------------- |
|
| 1671 |
| `short` | `h` |
|
| 1672 |
| `unsigned short` | `h` |
|
|
@@ -1834,11 +1791,11 @@ namespace std {
|
|
| 1834 |
```
|
| 1835 |
|
| 1836 |
The facet `num_put` is used to format numeric values to a character
|
| 1837 |
sequence such as an ostream.
|
| 1838 |
|
| 1839 |
-
#####
|
| 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;
|
|
@@ -1849,11 +1806,11 @@ iter_type put(iter_type out, ios_base& str, char_type fill, long double val) con
|
|
| 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 |
-
#####
|
| 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;
|
|
@@ -1862,30 +1819,30 @@ 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
|
| 1868 |
-
|
| 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`
|
| 1878 |
this conversion specifier for
|
| 1879 |
``` cpp
|
| 1880 |
printf(spec, val)
|
| 1881 |
```
|
| 1882 |
|
| 1883 |
assuming that the current locale is the `"C"` locale.
|
| 1884 |
- Stage 2: Adjust the representation by converting each `char`
|
| 1885 |
determined by stage 1 to a `charT` using a conversion and values
|
| 1886 |
-
returned by members of `use_facet<numpunct<charT>>(
|
| 1887 |
- Stage 3: Determine where padding is required.
|
| 1888 |
- Stage 4: Insert the sequence into the `out`.
|
| 1889 |
|
| 1890 |
Detailed descriptions of each stage follow.
|
| 1891 |
|
|
@@ -1911,13 +1868,13 @@ 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.
|
| 1913 |
|
| 1914 |
For conversion from an integral type other than a character type, the
|
| 1915 |
function determines the integral conversion specifier as indicated in
|
| 1916 |
-
|
| 1917 |
|
| 1918 |
-
**Table: Integer conversions** <a id="
|
| 1919 |
|
| 1920 |
| State | `stdio` equivalent |
|
| 1921 |
| -------------------------------------------- | ------------------ |
|
| 1922 |
| `basefield == ios_base::oct` | `%o` |
|
| 1923 |
| `(basefield == ios_base::hex) && !uppercase` | `%x` |
|
|
@@ -1926,13 +1883,13 @@ Table [[tab:localization.integer.conversions.out]].
|
|
| 1926 |
| for an `unsigned` integral type | `%u` |
|
| 1927 |
|
| 1928 |
|
| 1929 |
For conversion from a floating-point type, the function determines the
|
| 1930 |
floating-point conversion specifier as indicated in
|
| 1931 |
-
|
| 1932 |
|
| 1933 |
-
**Table: Floating-point conversions** <a id="
|
| 1934 |
|
| 1935 |
| State | `stdio` equivalent |
|
| 1936 |
| ---------------------------------------------------------------------- | ------------------ |
|
| 1937 |
| `floatfield == ios_base::fixed` | `%f` |
|
| 1938 |
| `floatfield == ios_base::scientific && !uppercase` | `%e` |
|
|
@@ -1943,13 +1900,13 @@ Table [[tab:localization.fp.conversions.out]].
|
|
| 1943 |
| otherwise | `%G` |
|
| 1944 |
|
| 1945 |
|
| 1946 |
For conversions from an integral or floating-point type a length
|
| 1947 |
modifier is added to the conversion specifier as indicated in
|
| 1948 |
-
|
| 1949 |
|
| 1950 |
-
**Table: Length modifier** <a id="
|
| 1951 |
|
| 1952 |
| Type | Length modifier |
|
| 1953 |
| -------------------- | --------------- |
|
| 1954 |
| `long` | `l` |
|
| 1955 |
| `long long` | `ll` |
|
|
@@ -1958,14 +1915,13 @@ Table [[tab:localization.length.modifier.out]].
|
|
| 1958 |
| `long double` | `L` |
|
| 1959 |
| otherwise | none |
|
| 1960 |
|
| 1961 |
|
| 1962 |
The conversion specifier has the following optional additional
|
| 1963 |
-
qualifiers prepended as indicated in
|
| 1964 |
-
Table [[tab:localization.numeric.conversions]].
|
| 1965 |
|
| 1966 |
-
**Table: Numeric conversions** <a id="
|
| 1967 |
|
| 1968 |
| Type(s) | State | `stdio` equivalent |
|
| 1969 |
| --------------------- | ----------- | ------------------ |
|
| 1970 |
| an integral type | `showpos` | `+` |
|
| 1971 |
| | `showbase` | `#` |
|
|
@@ -1985,16 +1941,20 @@ would be printed by a call of `printf(s, val)` where `s` is the
|
|
| 1985 |
conversion specifier determined above.
|
| 1986 |
|
| 1987 |
- **Stage 2:**
|
| 1988 |
|
| 1989 |
Any character `c` other than a decimal point(.) is converted to a
|
| 1990 |
-
`charT` via
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1991 |
|
| 1992 |
A local variable `punct` is initialized via
|
| 1993 |
|
| 1994 |
``` cpp
|
| 1995 |
-
const numpunct<charT>& punct = use_facet<numpunct<charT>>(
|
| 1996 |
```
|
| 1997 |
|
| 1998 |
For arithmetic types, `punct.thousands_sep()` characters are inserted
|
| 1999 |
into the sequence as determined by the value returned by
|
| 2000 |
`punct.do_grouping()` using the method described
|
|
@@ -2009,13 +1969,13 @@ A local variable is initialized as
|
|
| 2009 |
``` cpp
|
| 2010 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 2011 |
```
|
| 2012 |
|
| 2013 |
The location of any padding[^12] is determined according to
|
| 2014 |
-
|
| 2015 |
|
| 2016 |
-
**Table: Fill padding** <a id="
|
| 2017 |
|
| 2018 |
| State | Location |
|
| 2019 |
| ------------------------------------------------------------------------------ | ------------------ |
|
| 2020 |
| `adjustfield == ios_base::left` | pad after |
|
| 2021 |
| `adjustfield == ios_base::right` | pad before |
|
|
@@ -2089,43 +2049,73 @@ namespace std {
|
|
| 2089 |
}
|
| 2090 |
```
|
| 2091 |
|
| 2092 |
`numpunct<>`
|
| 2093 |
|
| 2094 |
-
specifies numeric punctuation. The specializations required in
|
| 2095 |
-
[[
|
| 2096 |
`numpunct<{}wchar_t>` and `numpunct<char>`, provide classic `"C"`
|
| 2097 |
numeric formats, i.e., they contain information equivalent to that
|
| 2098 |
contained in the `"C"` locale or their wide character counterparts as if
|
| 2099 |
obtained by a call to `widen`.
|
| 2100 |
|
| 2101 |
-
The syntax for number formats is as follows, where
|
| 2102 |
-
|
| 2103 |
-
|
| 2104 |
-
|
| 2105 |
-
|
| 2106 |
-
```
|
| 2107 |
-
|
| 2108 |
-
sign
|
| 2109 |
-
|
| 2110 |
-
|
| 2111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2112 |
```
|
| 2113 |
|
| 2114 |
and floating-point values have:
|
| 2115 |
|
| 2116 |
-
```
|
| 2117 |
-
floatval
|
| 2118 |
-
|
| 2119 |
-
|
| 2120 |
```
|
| 2121 |
|
| 2122 |
-
|
| 2123 |
-
|
| 2124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2125 |
|
| 2126 |
-
#####
|
| 2127 |
|
| 2128 |
``` cpp
|
| 2129 |
char_type decimal_point() const;
|
| 2130 |
```
|
| 2131 |
|
|
@@ -2148,11 +2138,11 @@ string_type truename() const;
|
|
| 2148 |
string_type falsename() const;
|
| 2149 |
```
|
| 2150 |
|
| 2151 |
*Returns:* `do_truename()` or `do_falsename()`, respectively.
|
| 2152 |
|
| 2153 |
-
#####
|
| 2154 |
|
| 2155 |
``` cpp
|
| 2156 |
char_type do_decimal_point() const;
|
| 2157 |
```
|
| 2158 |
|
|
@@ -2168,16 +2158,16 @@ required specializations return `’,’` or `L’,’`.
|
|
| 2168 |
|
| 2169 |
``` cpp
|
| 2170 |
string do_grouping() const;
|
| 2171 |
```
|
| 2172 |
|
| 2173 |
-
*Returns:* A
|
| 2174 |
-
|
| 2175 |
-
|
| 2176 |
-
|
| 2177 |
-
|
| 2178 |
-
|
| 2179 |
|
| 2180 |
The required specializations return the empty string, indicating no
|
| 2181 |
grouping.
|
| 2182 |
|
| 2183 |
``` cpp
|
|
@@ -2202,10 +2192,11 @@ namespace std {
|
|
| 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 |
};
|
| 2210 |
}
|
| 2211 |
```
|
|
@@ -2242,20 +2233,20 @@ namespace std {
|
|
| 2242 |
```
|
| 2243 |
|
| 2244 |
The class `collate<charT>` provides features for use in the collation
|
| 2245 |
(comparison) and hashing of strings. A locale member function template,
|
| 2246 |
`operator()`, uses the collate facet to allow a locale to act directly
|
| 2247 |
-
as the predicate argument for standard algorithms
|
| 2248 |
-
|
| 2249 |
-
|
| 2250 |
-
|
| 2251 |
-
|
| 2252 |
|
| 2253 |
Each function compares a string of characters `*p` in the range \[`low`,
|
| 2254 |
`high`).
|
| 2255 |
|
| 2256 |
-
#####
|
| 2257 |
|
| 2258 |
``` cpp
|
| 2259 |
int compare(const charT* low1, const charT* high1,
|
| 2260 |
const charT* low2, const charT* high2) const;
|
| 2261 |
```
|
|
@@ -2272,22 +2263,22 @@ string_type transform(const charT* low, const charT* high) const;
|
|
| 2272 |
long hash(const charT* low, const charT* high) const;
|
| 2273 |
```
|
| 2274 |
|
| 2275 |
*Returns:* `do_hash(low, high)`.
|
| 2276 |
|
| 2277 |
-
#####
|
| 2278 |
|
| 2279 |
``` cpp
|
| 2280 |
int do_compare(const charT* low1, const charT* high1,
|
| 2281 |
const charT* low2, const charT* high2) const;
|
| 2282 |
```
|
| 2283 |
|
| 2284 |
*Returns:* `1` if the first string is greater than the second, `-1` if
|
| 2285 |
less, zero otherwise. The specializations required in
|
| 2286 |
-
|
| 2287 |
-
|
| 2288 |
-
|
| 2289 |
|
| 2290 |
``` cpp
|
| 2291 |
string_type do_transform(const charT* low, const charT* high) const;
|
| 2292 |
```
|
| 2293 |
|
|
@@ -2317,10 +2308,11 @@ namespace std {
|
|
| 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 |
};
|
| 2325 |
}
|
| 2326 |
```
|
|
@@ -2329,14 +2321,13 @@ namespace std {
|
|
| 2329 |
|
| 2330 |
Templates `time_get<charT, InputIterator>` and
|
| 2331 |
`time_put<charT, OutputIterator>` provide date and time formatting and
|
| 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:
|
| 2335 |
-
|
| 2336 |
-
|
| 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 |
|
|
@@ -2404,11 +2395,11 @@ 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 |
-
#####
|
| 2410 |
|
| 2411 |
``` cpp
|
| 2412 |
dateorder date_order() const;
|
| 2413 |
```
|
| 2414 |
|
|
@@ -2455,11 +2446,11 @@ iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
|
| 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 |
-
*
|
| 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:
|
|
@@ -2497,11 +2488,11 @@ 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 |
-
#####
|
| 2503 |
|
| 2504 |
``` cpp
|
| 2505 |
dateorder do_date_order() const;
|
| 2506 |
```
|
| 2507 |
|
|
@@ -2531,14 +2522,13 @@ iter_type do_get_date(iter_type s, iter_type end, ios_base& str,
|
|
| 2531 |
|
| 2532 |
*Effects:* Reads characters starting at `s` until it has extracted those
|
| 2533 |
`struct tm` members and remaining format characters used by
|
| 2534 |
`time_put<>::put` to produce one of the following formats, or until it
|
| 2535 |
encounters an error. The format depends on the value returned by
|
| 2536 |
-
`date_order()` as shown in
|
| 2537 |
-
Table [[tab:lib.locale.time.get.virtuals.dogetdate]].
|
| 2538 |
|
| 2539 |
-
**Table: `do_get_date` effects** <a id="
|
| 2540 |
|
| 2541 |
| `date_order()` | Format |
|
| 2542 |
| -------------- | ---------- |
|
| 2543 |
| `no_order` | `"%m%d%y"` |
|
| 2544 |
| `dmy` | `"%d%m%y"` |
|
|
@@ -2585,11 +2575,11 @@ recognized as part of a valid year identifier.
|
|
| 2585 |
``` cpp
|
| 2586 |
iter_type do_get(iter_type s, iter_type end, ios_base& f,
|
| 2587 |
ios_base::iostate& err, tm* t, char format, char modifier) const;
|
| 2588 |
```
|
| 2589 |
|
| 2590 |
-
*
|
| 2591 |
|
| 2592 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 2593 |
It then reads characters starting at `s` until it encounters an error,
|
| 2594 |
or until it has extracted and assigned those `struct tm` members, and
|
| 2595 |
any remaining format characters, corresponding to a conversion directive
|
|
@@ -2609,11 +2599,11 @@ members from the input sequence \[`s`, `end`), it evaluates
|
|
| 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
|
| 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 |
|
|
@@ -2627,10 +2617,11 @@ namespace std {
|
|
| 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();
|
| 2634 |
};
|
| 2635 |
}
|
| 2636 |
```
|
|
@@ -2661,11 +2652,11 @@ namespace std {
|
|
| 2661 |
char format, char modifier) const;
|
| 2662 |
};
|
| 2663 |
}
|
| 2664 |
```
|
| 2665 |
|
| 2666 |
-
#####
|
| 2667 |
|
| 2668 |
``` cpp
|
| 2669 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
| 2670 |
const charT* pattern, const charT* pat_end) const;
|
| 2671 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
|
@@ -2694,11 +2685,11 @@ 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 |
-
#####
|
| 2700 |
|
| 2701 |
``` cpp
|
| 2702 |
iter_type do_put(iter_type s, ios_base&, char_type fill, const tm* t,
|
| 2703 |
char format, char modifier) const;
|
| 2704 |
```
|
|
@@ -2721,18 +2712,18 @@ reasonable default for this argument. — *end note*]
|
|
| 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 |
-
|
| 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();
|
| 2736 |
};
|
| 2737 |
}
|
| 2738 |
```
|
|
@@ -2742,14 +2733,13 @@ namespace std {
|
|
| 2742 |
These templates handle monetary formats. A template parameter indicates
|
| 2743 |
whether local or international monetary formats are to be used.
|
| 2744 |
|
| 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:
|
| 2748 |
-
|
| 2749 |
-
|
| 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 |
|
|
@@ -2781,31 +2771,28 @@ namespace std {
|
|
| 2781 |
ios_base::iostate& err, string_type& digits) const;
|
| 2782 |
};
|
| 2783 |
}
|
| 2784 |
```
|
| 2785 |
|
| 2786 |
-
#####
|
| 2787 |
|
| 2788 |
``` cpp
|
| 2789 |
-
iter_type get(iter_type s, iter_type end, bool intl,
|
| 2790 |
-
ios_base
|
| 2791 |
-
|
| 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 |
-
#####
|
| 2799 |
|
| 2800 |
``` cpp
|
| 2801 |
-
iter_type do_get(iter_type s, iter_type end, bool intl,
|
| 2802 |
-
ios_base
|
| 2803 |
-
|
| 2804 |
-
|
| 2805 |
-
ios_base& str, ios_base::iostate& err,
|
| 2806 |
-
string_type& digits) const;
|
| 2807 |
```
|
| 2808 |
|
| 2809 |
*Effects:* Reads characters from `s` to parse and construct a monetary
|
| 2810 |
value according to the format specified by a `moneypunct<charT, Intl>`
|
| 2811 |
facet reference `mp` and the character mapping specified by a
|
|
@@ -2815,11 +2802,11 @@ does not change `err`; otherwise, sets `err` to `(err|str.failbit)`, or
|
|
| 2815 |
`(err|str.failbit|str.eofbit)` if no more characters are available, and
|
| 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’`
|
| 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*]
|
|
@@ -2834,13 +2821,13 @@ Where `money_base::space` or `money_base::none` appears as the last
|
|
| 2834 |
element in the format pattern, no white space is consumed. Otherwise,
|
| 2835 |
where `money_base::space` appears in any of the initial elements of the
|
| 2836 |
format pattern, at least one white space character is required. Where
|
| 2837 |
`money_base::none` appears in any of the initial elements of the format
|
| 2838 |
pattern, white space is allowed but not required. If
|
| 2839 |
-
`(str.flags() & str.showbase)` is false, the currency symbol is
|
| 2840 |
-
and is consumed only if other characters are needed to complete
|
| 2841 |
-
format; otherwise, the currency symbol is required.
|
| 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
|
|
@@ -2912,22 +2899,20 @@ namespace std {
|
|
| 2912 |
const string_type& digits) const;
|
| 2913 |
};
|
| 2914 |
}
|
| 2915 |
```
|
| 2916 |
|
| 2917 |
-
#####
|
| 2918 |
|
| 2919 |
``` cpp
|
| 2920 |
-
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
|
| 2921 |
-
|
| 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 |
-
#####
|
| 2929 |
|
| 2930 |
``` cpp
|
| 2931 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
| 2932 |
char_type fill, long double units) const;
|
| 2933 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
@@ -3021,11 +3006,11 @@ namespace std {
|
|
| 3021 |
```
|
| 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`
|
| 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 |
|
|
@@ -3041,44 +3026,57 @@ required. Any remaining characters of the sign sequence are required
|
|
| 3041 |
after all other format components. Where `value` appears, the absolute
|
| 3042 |
numeric monetary value is required.
|
| 3043 |
|
| 3044 |
The format of the numeric monetary value is a decimal number:
|
| 3045 |
|
| 3046 |
-
```
|
| 3047 |
-
value
|
|
|
|
| 3048 |
decimal-point digits
|
| 3049 |
```
|
| 3050 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3051 |
if `frac_digits()` returns a positive value, or
|
| 3052 |
|
| 3053 |
-
```
|
| 3054 |
-
value
|
|
|
|
| 3055 |
```
|
| 3056 |
|
| 3057 |
-
otherwise. The symbol
|
| 3058 |
-
|
| 3059 |
|
| 3060 |
-
```
|
| 3061 |
-
units
|
| 3062 |
-
digits
|
|
|
|
| 3063 |
```
|
| 3064 |
|
| 3065 |
-
|
| 3066 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3067 |
`ct` is a reference of type `const ctype<charT>&` obtained as described
|
| 3068 |
-
in the definitions of `money_get<>` and `money_put<>`. The symbol
|
| 3069 |
-
|
| 3070 |
-
|
| 3071 |
-
|
| 3072 |
-
|
| 3073 |
-
|
| 3074 |
|
| 3075 |
The placement of thousands-separator characters (if any) is determined
|
| 3076 |
by the value returned by `grouping()`, defined identically as the member
|
| 3077 |
`numpunct<>::do_grouping()`.
|
| 3078 |
|
| 3079 |
-
#####
|
| 3080 |
|
| 3081 |
``` cpp
|
| 3082 |
charT decimal_point() const;
|
| 3083 |
charT thousands_sep() const;
|
| 3084 |
string grouping() const;
|
|
@@ -3091,11 +3089,11 @@ 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 |
-
#####
|
| 3097 |
|
| 3098 |
``` cpp
|
| 3099 |
charT do_decimal_point() const;
|
| 3100 |
```
|
| 3101 |
|
|
@@ -3118,39 +3116,47 @@ 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;[^
|
| 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.[^
|
| 3140 |
|
| 3141 |
``` cpp
|
| 3142 |
pattern do_pos_format() const;
|
| 3143 |
pattern do_neg_format() const;
|
| 3144 |
```
|
| 3145 |
|
| 3146 |
*Returns:* The specializations required in
|
| 3147 |
-
|
| 3148 |
-
|
| 3149 |
-
`moneypunct<char
|
| 3150 |
-
|
| 3151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3152 |
|
| 3153 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 3154 |
|
| 3155 |
``` cpp
|
| 3156 |
namespace std {
|
|
@@ -3160,10 +3166,11 @@ namespace std {
|
|
| 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();
|
| 3167 |
};
|
| 3168 |
}
|
| 3169 |
```
|
|
@@ -3188,34 +3195,34 @@ namespace std {
|
|
| 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
|
| 3194 |
string_type get(catalog c, int set, int msgid,
|
| 3195 |
const string_type& dfault) const;
|
| 3196 |
void close(catalog c) const;
|
| 3197 |
|
| 3198 |
static locale::id id;
|
| 3199 |
|
| 3200 |
protected:
|
| 3201 |
~messages();
|
| 3202 |
-
virtual catalog do_open(const
|
| 3203 |
virtual string_type do_get(catalog, int set, int msgid,
|
| 3204 |
const string_type& dfault) const;
|
| 3205 |
virtual void do_close(catalog) const;
|
| 3206 |
};
|
| 3207 |
}
|
| 3208 |
```
|
| 3209 |
|
| 3210 |
Values of type `messages_base::catalog` usable as arguments to members
|
| 3211 |
`get` and `close` can be obtained only by calling member `open`.
|
| 3212 |
|
| 3213 |
-
#####
|
| 3214 |
|
| 3215 |
``` cpp
|
| 3216 |
-
catalog open(const
|
| 3217 |
```
|
| 3218 |
|
| 3219 |
*Returns:* `do_open(name, loc)`.
|
| 3220 |
|
| 3221 |
``` cpp
|
|
@@ -3228,14 +3235,14 @@ string_type get(catalog cat, int set, int msgid, const string_type& dfault) cons
|
|
| 3228 |
void close(catalog cat) const;
|
| 3229 |
```
|
| 3230 |
|
| 3231 |
*Effects:* Calls `do_close(cat)`.
|
| 3232 |
|
| 3233 |
-
#####
|
| 3234 |
|
| 3235 |
``` cpp
|
| 3236 |
-
catalog do_open(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
|
|
@@ -3248,22 +3255,22 @@ 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 |
-
*
|
| 3254 |
closed.
|
| 3255 |
|
| 3256 |
*Returns:* A message identified by arguments `set`, `msgid`, and
|
| 3257 |
`dfault`, according to an *implementation-defined* mapping. If no such
|
| 3258 |
message can be found, returns `dfault`.
|
| 3259 |
|
| 3260 |
``` cpp
|
| 3261 |
void do_close(catalog cat) const;
|
| 3262 |
```
|
| 3263 |
|
| 3264 |
-
*
|
| 3265 |
closed.
|
| 3266 |
|
| 3267 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 3268 |
|
| 3269 |
*Remarks:* The limit on such resources, if any, is
|
|
@@ -3279,208 +3286,17 @@ namespace std {
|
|
| 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();
|
| 3286 |
};
|
| 3287 |
}
|
| 3288 |
```
|
| 3289 |
|
| 3290 |
-
### Program-defined facets <a id="facets.examples">[[facets.examples]]</a>
|
| 3291 |
-
|
| 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>
|
| 3306 |
-
#include <locale>
|
| 3307 |
-
int main(int argc, char** argv) {
|
| 3308 |
-
using namespace std;
|
| 3309 |
-
locale::global(locale("")); // set the global locale
|
| 3310 |
-
// imbue it on all the std streams
|
| 3311 |
-
cin.imbue(locale());
|
| 3312 |
-
cout.imbue(locale());
|
| 3313 |
-
cerr.imbue(locale());
|
| 3314 |
-
wcin.imbue(locale());
|
| 3315 |
-
wcout.imbue(locale());
|
| 3316 |
-
wcerr.imbue(locale());
|
| 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>
|
| 3331 |
-
int main() {
|
| 3332 |
-
using namespace std;
|
| 3333 |
-
cin.imbue(locale("")); // the user's preferred locale
|
| 3334 |
-
cout.imbue(locale::classic());
|
| 3335 |
-
double f;
|
| 3336 |
-
while (cin >> f) cout << f << endl;
|
| 3337 |
-
return (cin.fail() != 0);
|
| 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>
|
| 3355 |
-
#include <string>
|
| 3356 |
-
#include <locale>
|
| 3357 |
-
|
| 3358 |
-
class Date {
|
| 3359 |
-
public:
|
| 3360 |
-
Date(unsigned day, unsigned month, unsigned year);
|
| 3361 |
-
std::string asString(const std::locale& = std::locale());
|
| 3362 |
-
};
|
| 3363 |
-
|
| 3364 |
-
std::istream& operator>>(std::istream& s, Date& d);
|
| 3365 |
-
std::ostream& operator<<(std::ostream& s, Date d);
|
| 3366 |
-
```
|
| 3367 |
-
|
| 3368 |
-
This example illustrates two architectural uses of class `locale`.
|
| 3369 |
-
|
| 3370 |
-
The first is as a default argument in `Date::asString()`, where the
|
| 3371 |
-
default is the global (presumably user-preferred) locale.
|
| 3372 |
-
|
| 3373 |
-
The second is in the operators `<<` and `>>`, where a locale
|
| 3374 |
-
“hitchhikes” on another object, in this case a stream, to the point
|
| 3375 |
-
where it is needed.
|
| 3376 |
-
|
| 3377 |
-
``` cpp
|
| 3378 |
-
// file: Date.C
|
| 3379 |
-
#include "Date" // includes <ctime>
|
| 3380 |
-
#include <sstream>
|
| 3381 |
-
std::string Date::asString(const std::locale& l) {
|
| 3382 |
-
using namespace std;
|
| 3383 |
-
ostringstream s; s.imbue(l);
|
| 3384 |
-
s << *this; return s.str();
|
| 3385 |
-
}
|
| 3386 |
-
|
| 3387 |
-
std::istream& operator>>(std::istream& s, Date& d) {
|
| 3388 |
-
using namespace std;
|
| 3389 |
-
istream::sentry cerberos(s);
|
| 3390 |
-
if (cerberos) {
|
| 3391 |
-
ios_base::iostate err = goodbit;
|
| 3392 |
-
struct tm t;
|
| 3393 |
-
use_facet<time_get<char>>(s.getloc()).get_date(s, 0, s, err, &t);
|
| 3394 |
-
if (!err) d = Date(t.tm_day, t.tm_mon + 1, t.tm_year + 1900);
|
| 3395 |
-
s.setstate(err);
|
| 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>
|
| 3415 |
-
namespace My {
|
| 3416 |
-
using namespace std;
|
| 3417 |
-
class JCtype : public locale::facet {
|
| 3418 |
-
public:
|
| 3419 |
-
static locale::id id; // required for use as a new locale facet
|
| 3420 |
-
bool is_kanji (wchar_t c) const;
|
| 3421 |
-
JCtype() { }
|
| 3422 |
-
protected:
|
| 3423 |
-
~JCtype() { }
|
| 3424 |
-
};
|
| 3425 |
-
}
|
| 3426 |
-
|
| 3427 |
-
// file: filt.C
|
| 3428 |
-
#include <iostream>
|
| 3429 |
-
#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() { }
|
| 3466 |
-
public:
|
| 3467 |
-
BoolNames(const char* name) : cnumpunct(name) { }
|
| 3468 |
-
};
|
| 3469 |
-
}
|
| 3470 |
-
|
| 3471 |
-
int main(int argc, char** argv) {
|
| 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
|
|
@@ -3501,17 +3317,17 @@ namespace std {
|
|
| 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]]
|
| 3508 |
-
the functions listed in
|
| 3509 |
|
| 3510 |
-
ISO C 7.11
|
| 3511 |
|
| 3512 |
-
**Table: Potential `setlocale` data races** <a id="
|
| 3513 |
|
| 3514 |
| | | | | |
|
| 3515 |
| --------- | ---------- | ----------- | ------------ | ---------- |
|
| 3516 |
| `fprintf` | `isprint` | `iswdigit` | `localeconv` | `tolower` |
|
| 3517 |
| `fscanf` | `ispunct` | `iswgraph` | `mblen` | `toupper` |
|
|
@@ -3553,23 +3369,25 @@ ISO C 7.11.
|
|
| 3553 |
[facet.num.put.members]: #facet.num.put.members
|
| 3554 |
[facet.num.put.virtuals]: #facet.num.put.virtuals
|
| 3555 |
[facet.numpunct]: #facet.numpunct
|
| 3556 |
[facet.numpunct.members]: #facet.numpunct.members
|
| 3557 |
[facet.numpunct.virtuals]: #facet.numpunct.virtuals
|
| 3558 |
-
[facets.examples]: #facets.examples
|
| 3559 |
[file.streams]: input.md#file.streams
|
| 3560 |
[ios.base]: input.md#ios.base
|
| 3561 |
[istream.formatted]: input.md#istream.formatted
|
| 3562 |
[istream.formatted.reqmts]: input.md#istream.formatted.reqmts
|
| 3563 |
[iterator.requirements]: iterators.md#iterator.requirements
|
| 3564 |
[lex.charset]: lex.md#lex.charset
|
| 3565 |
[locale]: #locale
|
| 3566 |
[locale.categories]: #locale.categories
|
| 3567 |
[locale.category]: #locale.category
|
|
|
|
| 3568 |
[locale.codecvt]: #locale.codecvt
|
| 3569 |
[locale.codecvt.byname]: #locale.codecvt.byname
|
|
|
|
| 3570 |
[locale.codecvt.members]: #locale.codecvt.members
|
|
|
|
| 3571 |
[locale.codecvt.virtuals]: #locale.codecvt.virtuals
|
| 3572 |
[locale.collate]: #locale.collate
|
| 3573 |
[locale.collate.byname]: #locale.collate.byname
|
| 3574 |
[locale.collate.members]: #locale.collate.members
|
| 3575 |
[locale.collate.virtuals]: #locale.collate.virtuals
|
|
@@ -3600,51 +3418,50 @@ ISO C 7.11.
|
|
| 3600 |
[locale.nm.put]: #locale.nm.put
|
| 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
|
| 3611 |
[locale.time.put]: #locale.time.put
|
| 3612 |
[locale.time.put.byname]: #locale.time.put.byname
|
| 3613 |
[locale.time.put.members]: #locale.time.put.members
|
| 3614 |
[locale.time.put.virtuals]: #locale.time.put.virtuals
|
| 3615 |
[locale.types]: #locale.types
|
| 3616 |
[locales]: #locales
|
| 3617 |
[localization]: #localization
|
| 3618 |
[localization.general]: #localization.general
|
|
|
|
| 3619 |
[ostream.formatted.reqmts]: input.md#ostream.formatted.reqmts
|
| 3620 |
[res.on.data.races]: library.md#res.on.data.races
|
| 3621 |
[sequence.reqmts]: containers.md#sequence.reqmts
|
| 3622 |
-
[
|
| 3623 |
-
[tab:
|
| 3624 |
-
[tab:
|
| 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 |
|
| 3631 |
[^1]: In this subclause, the type name `struct tm` is an incomplete type
|
| 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
|
| 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 |
|
|
@@ -3692,12 +3509,12 @@ ISO C 7.11.
|
|
| 3692 |
vendors do.
|
| 3693 |
|
| 3694 |
[^18]: Interpretation of the `modifier` argument is
|
| 3695 |
implementation-defined, but should follow POSIX conventions.
|
| 3696 |
|
| 3697 |
-
[^19]: Implementations
|
| 3698 |
-
|
| 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.
|
|
@@ -3706,15 +3523,11 @@ ISO C 7.11.
|
|
| 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]:
|
| 3712 |
-
`true`) this is typically four characters long, usually three
|
| 3713 |
-
letters and a space.
|
| 3714 |
|
| 3715 |
-
[^26]:
|
| 3716 |
|
| 3717 |
-
[^27]:
|
| 3718 |
-
|
| 3719 |
-
[^28]: Note that the international symbol returned by `do_curr_sym()`
|
| 3720 |
usually contains a space, itself; for example, `"USD "`.
|
|
|
|
| 1 |
# Localization library <a id="localization">[[localization]]</a>
|
| 2 |
|
| 3 |
## General <a id="localization.general">[[localization.general]]</a>
|
| 4 |
|
| 5 |
+
This Clause describes components that C++ programs may use to
|
| 6 |
+
encapsulate (and therefore be more portable when confronting) cultural
|
| 7 |
+
differences. The locale facility includes internationalization support
|
| 8 |
+
for character classification and string collation, numeric, monetary,
|
| 9 |
+
and date/time formatting and parsing, and message retrieval.
|
| 10 |
|
| 11 |
The following subclauses describe components for locales themselves, the
|
| 12 |
standard facets, and facilities from the ISO C library, as summarized in
|
| 13 |
+
[[localization.summary]].
|
| 14 |
|
| 15 |
+
**Table: Localization library summary** <a id="localization.summary">[localization.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 |
|
|
|
|
| 107 |
|
| 108 |
``` cpp
|
| 109 |
namespace std {
|
| 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,
|
| 121 |
all = collate | ctype | monetary | numeric | time | messages;
|
| 122 |
|
| 123 |
+
// construct/copy/destroy
|
| 124 |
locale() noexcept;
|
| 125 |
locale(const locale& other) noexcept;
|
| 126 |
explicit locale(const char* std_name);
|
| 127 |
explicit locale(const string& std_name);
|
| 128 |
locale(const locale& other, const char* std_name, category);
|
|
|
|
| 131 |
locale(const locale& other, const locale& one, category);
|
| 132 |
~locale(); // not virtual
|
| 133 |
const locale& operator=(const locale& other) noexcept;
|
| 134 |
template<class Facet> locale combine(const locale& other) const;
|
| 135 |
|
| 136 |
+
// locale operations
|
| 137 |
+
string name() const;
|
| 138 |
|
| 139 |
bool operator==(const locale& other) const;
|
|
|
|
| 140 |
|
| 141 |
template<class charT, class traits, class Allocator>
|
| 142 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 143 |
const basic_string<charT, traits, Allocator>& s2) const;
|
| 144 |
|
| 145 |
+
// global locale objects
|
| 146 |
static locale global(const locale&);
|
| 147 |
static const locale& classic();
|
| 148 |
};
|
| 149 |
}
|
| 150 |
```
|
|
|
|
| 165 |
template<class charT, class traits>
|
| 166 |
basic_ostream<charT, traits>&
|
| 167 |
operator<< (basic_ostream<charT, traits>& s, Date d) {
|
| 168 |
typename basic_ostream<charT, traits>::sentry cerberos(s);
|
| 169 |
if (cerberos) {
|
|
|
|
| 170 |
tm tmbuf; d.extract(tmbuf);
|
| 171 |
+
bool failed =
|
| 172 |
use_facet<time_put<charT, ostreambuf_iterator<charT, traits>>>(
|
| 173 |
+
s.getloc()).put(s, s, s.fill(), &tmbuf, 'x').failed();
|
| 174 |
+
if (failed)
|
| 175 |
+
s.setstate(s.badbit); // might throw
|
| 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 C++
|
| 186 |
+
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 |
|
| 190 |
[*Note 1*:
|
| 191 |
|
| 192 |
All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
|
| 193 |
except that:
|
|
|
|
| 197 |
is provided so that a locale may be used as a predicate argument to
|
| 198 |
the standard collections, to collate strings.
|
| 199 |
- Convenient global interfaces are provided for traditional `ctype`
|
| 200 |
functions such as `isdigit()` and `isspace()`, so that given a locale
|
| 201 |
object `loc` a C++ program can call `isspace(c, loc)`. (This eases
|
| 202 |
+
upgrading existing extractors [[istream.formatted]].)
|
| 203 |
|
| 204 |
— *end note*]
|
| 205 |
|
| 206 |
Once a facet reference is obtained from a locale object by calling
|
| 207 |
`use_facet<>`, that reference remains usable, and the results from
|
|
|
|
| 219 |
|
| 220 |
Whether there is one global locale object for the entire program or one
|
| 221 |
global locale object per thread is *implementation-defined*.
|
| 222 |
Implementations should provide one global locale object per thread. If
|
| 223 |
there is a single global locale object for the entire program,
|
| 224 |
+
implementations are not required to avoid data races on it
|
| 225 |
+
[[res.on.data.races]].
|
| 226 |
|
| 227 |
+
#### Types <a id="locale.types">[[locale.types]]</a>
|
| 228 |
|
| 229 |
##### Type `locale::category` <a id="locale.category">[[locale.category]]</a>
|
| 230 |
|
| 231 |
``` cpp
|
| 232 |
using category = int;
|
|
|
|
| 251 |
|
| 252 |
member functions expecting a `category` argument require one of the
|
| 253 |
`category` values defined above, or the union of two or more such
|
| 254 |
values. Such a `category` value identifies a set of locale categories.
|
| 255 |
Each locale category, in turn, identifies a set of locale facets,
|
| 256 |
+
including at least those shown in [[locale.category.facets]].
|
|
|
|
| 257 |
|
| 258 |
+
**Table: Locale category facets** <a id="locale.category.facets">[locale.category.facets]</a>
|
| 259 |
|
| 260 |
| Category | Includes facets |
|
| 261 |
| -------- | ----------------------------------------------------- |
|
| 262 |
| collate | `collate<char>`, `collate<wchar_t>` |
|
| 263 |
| ctype | `ctype<char>`, `ctype<wchar_t>` |
|
| 264 |
| | `codecvt<char, char, mbstate_t>` |
|
| 265 |
+
| | `codecvt<char16_t, char8_t, mbstate_t>` |
|
| 266 |
+
| | `codecvt<char32_t, char8_t, mbstate_t>` |
|
| 267 |
| | `codecvt<wchar_t, char, mbstate_t>` |
|
| 268 |
| monetary | `moneypunct<char>`, `moneypunct<wchar_t>` |
|
| 269 |
| | `moneypunct<char, true>`, `moneypunct<wchar_t, true>` |
|
| 270 |
| | `money_get<char>`, `money_get<wchar_t>` |
|
| 271 |
| | `money_put<char>`, `money_put<wchar_t>` |
|
|
|
|
| 276 |
| | `time_put<char>`, `time_put<wchar_t>` |
|
| 277 |
| messages | `messages<char>`, `messages<wchar_t>` |
|
| 278 |
|
| 279 |
|
| 280 |
For any locale `loc` either constructed, or returned by
|
| 281 |
+
`locale::classic()`, and any facet `Facet` shown in
|
| 282 |
+
[[locale.category.facets]], `has_facet<Facet>(loc)` is `true`. Each
|
| 283 |
+
`locale` member function which takes a `locale::category` argument
|
| 284 |
operates on the corresponding set of facets.
|
| 285 |
|
| 286 |
An implementation is required to provide those specializations for facet
|
| 287 |
templates identified as members of a category, and for those shown in
|
| 288 |
+
[[locale.spec]].
|
| 289 |
|
| 290 |
+
**Table: Required specializations** <a id="locale.spec">[locale.spec]</a>
|
| 291 |
|
| 292 |
| Category | Includes facets |
|
| 293 |
| -------- | --------------------------------------------------------- |
|
| 294 |
| collate | `collate_byname<char>`, `collate_byname<wchar_t>` |
|
| 295 |
| ctype | `ctype_byname<char>`, `ctype_byname<wchar_t>` |
|
| 296 |
| | `codecvt_byname<char, char, mbstate_t>` |
|
| 297 |
+
| | `codecvt_byname<char16_t, char8_t, mbstate_t>` |
|
| 298 |
+
| | `codecvt_byname<char32_t, char8_t, mbstate_t>` |
|
| 299 |
| | `codecvt_byname<wchar_t, char, mbstate_t>` |
|
| 300 |
| monetary | `moneypunct_byname<char, International>` |
|
| 301 |
| | `moneypunct_byname<wchar_t, International>` |
|
| 302 |
| | `money_get<C, InputIterator>` |
|
| 303 |
| | `money_put<C, OutputIterator>` |
|
|
|
|
| 320 |
obtained by calling member `getloc()` on the `ios_base&` argument to
|
| 321 |
these functions.
|
| 322 |
|
| 323 |
In declarations of facets, a template parameter with name
|
| 324 |
`InputIterator` or `OutputIterator` indicates the set of all possible
|
| 325 |
+
specializations on parameters that meet the *Cpp17InputIterator*
|
| 326 |
+
requirements or *Cpp17OutputIterator* requirements, respectively
|
| 327 |
+
[[iterator.requirements]]. A template parameter with name `C` represents
|
| 328 |
+
the set of types containing `char`, `wchar_t`, and any other
|
| 329 |
+
*implementation-defined* character types that meet the requirements for
|
| 330 |
+
a character on which any of the iostream components can be instantiated.
|
| 331 |
+
A template parameter with name `International` represents the set of all
|
| 332 |
+
possible specializations on a bool parameter.
|
| 333 |
|
| 334 |
##### Class `locale::facet` <a id="locale.facet">[[locale.facet]]</a>
|
| 335 |
|
| 336 |
``` cpp
|
| 337 |
namespace std {
|
|
|
|
| 357 |
Template parameters in this Clause which are required to be facets are
|
| 358 |
those named `Facet` in declarations. A program that passes a type that
|
| 359 |
is *not* a facet, or a type that refers to a volatile-qualified facet,
|
| 360 |
as an (explicit or deduced) template parameter to a locale function
|
| 361 |
expecting a facet, is ill-formed. A const-qualified facet is a valid
|
| 362 |
+
template argument to any locale function that expects a `Facet` template
|
| 363 |
parameter.
|
| 364 |
|
| 365 |
The `refs` argument to the constructor is used for lifetime management.
|
| 366 |
For `refs == 0`, the implementation performs
|
| 367 |
`delete static_cast<locale::facet*>(f)` (where `f` is a pointer to the
|
|
|
|
| 405 |
[*Note 1*: Because facets are used by iostreams, potentially while
|
| 406 |
static constructors are running, their initialization cannot depend on
|
| 407 |
programmed static initialization. One initialization strategy is for
|
| 408 |
`locale` to initialize each facet’s `id` member the first time an
|
| 409 |
instance of the facet is installed into a locale. This depends only on
|
| 410 |
+
static storage being zero before constructors run
|
| 411 |
+
[[basic.start.static]]. — *end note*]
|
| 412 |
|
| 413 |
+
#### Constructors and destructor <a id="locale.cons">[[locale.cons]]</a>
|
| 414 |
|
| 415 |
``` cpp
|
| 416 |
locale() noexcept;
|
| 417 |
```
|
| 418 |
|
|
|
|
|
|
|
| 419 |
*Effects:* Constructs a copy of the argument last passed to
|
| 420 |
`locale::global(locale&)`, if it has been called; else, the resulting
|
| 421 |
facets have virtual function semantics identical to those of
|
| 422 |
`locale::classic()`.
|
| 423 |
|
| 424 |
+
[*Note 1*: This constructor yields a copy of the current global locale.
|
| 425 |
+
It is commonly used as a default argument for function parameters of
|
| 426 |
+
type `const locale&`. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
|
| 428 |
``` cpp
|
| 429 |
explicit locale(const char* std_name);
|
| 430 |
```
|
| 431 |
|
|
|
|
| 490 |
|
| 491 |
*Effects:* Creates a copy of `other`, replacing the current value.
|
| 492 |
|
| 493 |
*Returns:* `*this`.
|
| 494 |
|
| 495 |
+
#### Members <a id="locale.members">[[locale.members]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
|
| 497 |
``` cpp
|
| 498 |
template<class Facet> locale combine(const locale& other) const;
|
| 499 |
```
|
| 500 |
|
|
|
|
| 506 |
*Throws:* `runtime_error` if `has_facet<Facet>(other)` is `false`.
|
| 507 |
|
| 508 |
*Remarks:* The resulting locale has no name.
|
| 509 |
|
| 510 |
``` cpp
|
| 511 |
+
string name() const;
|
| 512 |
```
|
| 513 |
|
| 514 |
*Returns:* The name of `*this`, if it has one; otherwise, the string
|
| 515 |
`"*"`.
|
| 516 |
|
| 517 |
+
#### Operators <a id="locale.operators">[[locale.operators]]</a>
|
| 518 |
|
| 519 |
``` cpp
|
| 520 |
bool operator==(const locale& other) const;
|
| 521 |
```
|
| 522 |
|
| 523 |
*Returns:* `true` if both arguments are the same locale, or one is a
|
| 524 |
copy of the other, or each has a name and the names are identical;
|
| 525 |
`false` otherwise.
|
| 526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
``` cpp
|
| 528 |
template<class charT, class traits, class Allocator>
|
| 529 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 530 |
const basic_string<charT, traits, Allocator>& s2) const;
|
| 531 |
```
|
| 532 |
|
| 533 |
*Effects:* Compares two strings according to the `collate<charT>` facet.
|
| 534 |
|
| 535 |
*Remarks:* This member operator template (and therefore `locale` itself)
|
| 536 |
+
meets the requirements for a comparator predicate template
|
| 537 |
+
argument [[algorithms]] applied to strings.
|
| 538 |
|
| 539 |
*Returns:*
|
| 540 |
|
| 541 |
``` cpp
|
| 542 |
use_facet<collate<charT>>(*this).compare(s1.data(), s1.data() + s1.size(),
|
|
|
|
| 552 |
std::sort(v.begin(), v.end(), loc);
|
| 553 |
```
|
| 554 |
|
| 555 |
— *end example*]
|
| 556 |
|
| 557 |
+
#### Static members <a id="locale.statics">[[locale.statics]]</a>
|
| 558 |
|
| 559 |
``` cpp
|
| 560 |
static locale global(const locale& loc);
|
| 561 |
```
|
| 562 |
|
| 563 |
+
*Effects:* Sets the global locale to its argument. Causes future calls
|
| 564 |
+
to the constructor `locale()` to return a copy of the argument. If the
|
| 565 |
+
argument has a name, does
|
|
|
|
| 566 |
|
| 567 |
``` cpp
|
| 568 |
setlocale(LC_ALL, loc.name().c_str());
|
| 569 |
```
|
| 570 |
|
| 571 |
otherwise, the effect on the C locale, if any, is
|
| 572 |
+
*implementation-defined*.
|
| 573 |
+
|
| 574 |
+
*Remarks:* No library function other than `locale::global()` affects the
|
| 575 |
+
value returned by `locale()`.
|
| 576 |
|
| 577 |
[*Note 1*: See [[c.locales]] for data race considerations when
|
| 578 |
`setlocale` is invoked. — *end note*]
|
| 579 |
|
| 580 |
*Returns:* The previous value of `locale()`.
|
|
|
|
| 595 |
|
| 596 |
``` cpp
|
| 597 |
template<class Facet> const Facet& use_facet(const locale& loc);
|
| 598 |
```
|
| 599 |
|
| 600 |
+
*Mandates:* `Facet` is a facet class whose definition contains the
|
| 601 |
public static member `id` as defined in [[locale.facet]].
|
| 602 |
|
| 603 |
*Returns:* A reference to the corresponding facet of `loc`, if present.
|
| 604 |
|
| 605 |
*Throws:* `bad_cast` if `has_facet<Facet>(loc)` is `false`.
|
|
|
|
| 637 |
|
| 638 |
``` cpp
|
| 639 |
use_facet<ctype<charT>>(loc).is(ctype_base::F, c)
|
| 640 |
```
|
| 641 |
|
| 642 |
+
where `F` is the `ctype_base::mask` value corresponding to that function
|
| 643 |
+
[[category.ctype]].[^4]
|
| 644 |
|
| 645 |
#### Conversions <a id="conversions">[[conversions]]</a>
|
| 646 |
|
| 647 |
##### Character conversions <a id="conversions.character">[[conversions.character]]</a>
|
| 648 |
|
|
|
|
| 663 |
Each of the standard categories includes a family of facets. Some of
|
| 664 |
these implement formatting or parsing of a datum, for use by standard or
|
| 665 |
users’ iostream operators `<<` and `>>`, as members `put()` and `get()`,
|
| 666 |
respectively. Each such member function takes an `ios_base&` argument
|
| 667 |
whose members `flags()`, `precision()`, and `width()`, specify the
|
| 668 |
+
format of the corresponding datum [[ios.base]]. Those functions which
|
| 669 |
need to use other facets call its member `getloc()` to retrieve the
|
| 670 |
locale imbued there. Formatting facets use the character argument `fill`
|
| 671 |
to fill out the specified width where necessary.
|
| 672 |
|
| 673 |
The `put()` members make no provision for error reporting. (Any failures
|
| 674 |
+
of the OutputIterator argument can be extracted from the returned
|
| 675 |
iterator.) The `get()` members take an `ios_base::iostate&` argument
|
| 676 |
whose value they ignore, but set to `ios_base::failbit` in case of a
|
| 677 |
parse error.
|
| 678 |
|
| 679 |
Within this clause it is unspecified whether one virtual function calls
|
|
|
|
| 683 |
|
| 684 |
``` cpp
|
| 685 |
namespace std {
|
| 686 |
class ctype_base {
|
| 687 |
public:
|
| 688 |
+
using mask = see below;
|
| 689 |
|
| 690 |
// numeric values are for exposition only.
|
| 691 |
static const mask space = 1 << 0;
|
| 692 |
static const mask print = 1 << 1;
|
| 693 |
static const mask cntrl = 1 << 2;
|
|
|
|
| 702 |
static const mask graph = alnum | punct;
|
| 703 |
};
|
| 704 |
}
|
| 705 |
```
|
| 706 |
|
| 707 |
+
The type `mask` is a bitmask type [[bitmask.types]].
|
| 708 |
|
| 709 |
#### Class template `ctype` <a id="locale.ctype">[[locale.ctype]]</a>
|
| 710 |
|
| 711 |
``` cpp
|
| 712 |
namespace std {
|
|
|
|
| 754 |
|
| 755 |
Class `ctype` encapsulates the C library `<cctype>` features. `istream`
|
| 756 |
members are required to use `ctype<>` for character classing during
|
| 757 |
input parsing.
|
| 758 |
|
| 759 |
+
The specializations required in [[locale.category.facets]]
|
| 760 |
+
[[locale.category]], namely `ctype<char>` and `ctype<wchar_t>`,
|
| 761 |
+
implement character classing appropriate to the implementation’s native
|
| 762 |
+
character set.
|
| 763 |
|
| 764 |
##### `ctype` members <a id="locale.ctype.members">[[locale.ctype.members]]</a>
|
| 765 |
|
| 766 |
``` cpp
|
| 767 |
bool is(mask m, charT c) const;
|
| 768 |
+
const charT* is(const charT* low, const charT* high, mask* vec) const;
|
|
|
|
| 769 |
```
|
| 770 |
|
| 771 |
*Returns:* `do_is(m, c)` or `do_is(low, high, vec)`.
|
| 772 |
|
| 773 |
``` cpp
|
| 774 |
+
const charT* scan_is(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 775 |
```
|
| 776 |
|
| 777 |
*Returns:* `do_scan_is(m, low, high)`.
|
| 778 |
|
| 779 |
``` cpp
|
| 780 |
+
const charT* scan_not(mask m, const charT* low, const charT* high) const;
|
|
|
|
| 781 |
```
|
| 782 |
|
| 783 |
*Returns:* `do_scan_not(m, low, high)`.
|
| 784 |
|
| 785 |
``` cpp
|
|
|
|
| 803 |
|
| 804 |
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`.
|
| 805 |
|
| 806 |
``` cpp
|
| 807 |
char narrow(charT c, char dfault) const;
|
| 808 |
+
const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
|
|
|
|
| 809 |
```
|
| 810 |
|
| 811 |
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`.
|
| 812 |
|
| 813 |
##### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
|
| 814 |
|
| 815 |
``` cpp
|
| 816 |
bool do_is(mask m, charT c) const;
|
| 817 |
+
const charT* do_is(const charT* low, const charT* high, mask* vec) const;
|
|
|
|
| 818 |
```
|
| 819 |
|
| 820 |
*Effects:* Classifies a character or sequence of characters. For each
|
| 821 |
argument character, identifies a value `M` of type `ctype_base::mask`.
|
| 822 |
The second form identifies a value `M` of type `ctype_base::mask` for
|
|
|
|
| 874 |
if it is known to exist, or its argument if not. The second form returns
|
| 875 |
`high`.
|
| 876 |
|
| 877 |
``` cpp
|
| 878 |
charT do_widen(char c) const;
|
| 879 |
+
const char* do_widen(const char* low, const char* high, charT* dest) const;
|
|
|
|
| 880 |
```
|
| 881 |
|
| 882 |
*Effects:* Applies the simplest reasonable transformation from a `char`
|
| 883 |
value or sequence of `char` values to the corresponding `charT` value or
|
| 884 |
values.[^5] The only characters for which unique transformations are
|
| 885 |
+
required are those in the basic source character set [[lex.charset]].
|
| 886 |
|
| 887 |
For any named `ctype` category with a `ctype <charT>` facet `ctc` and
|
| 888 |
valid `ctype_base::mask` value `M`,
|
| 889 |
`(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^6]
|
| 890 |
|
|
|
|
| 894 |
*Returns:* The first form returns the transformed value. The second form
|
| 895 |
returns `high`.
|
| 896 |
|
| 897 |
``` cpp
|
| 898 |
char do_narrow(charT c, char dfault) const;
|
| 899 |
+
const charT* do_narrow(const charT* low, const charT* high, char dfault, char* dest) const;
|
|
|
|
| 900 |
```
|
| 901 |
|
| 902 |
*Effects:* Applies the simplest reasonable transformation from a `charT`
|
| 903 |
value or sequence of `charT` values to the corresponding `char` value or
|
| 904 |
values.
|
| 905 |
|
| 906 |
+
For any character `c` in the basic source character set [[lex.charset]]
|
| 907 |
+
the transformation is such that
|
| 908 |
|
| 909 |
``` cpp
|
| 910 |
do_widen(do_narrow(c, 0)) == c
|
| 911 |
```
|
| 912 |
|
|
|
|
| 935 |
class ctype_byname : public ctype<charT> {
|
| 936 |
public:
|
| 937 |
using mask = typename ctype<charT>::mask;
|
| 938 |
explicit ctype_byname(const char*, size_t refs = 0);
|
| 939 |
explicit ctype_byname(const string&, size_t refs = 0);
|
| 940 |
+
|
| 941 |
protected:
|
| 942 |
~ctype_byname();
|
| 943 |
};
|
| 944 |
}
|
| 945 |
```
|
| 946 |
|
| 947 |
+
#### `ctype<char>` specialization <a id="facet.ctype.special">[[facet.ctype.special]]</a>
|
| 948 |
|
| 949 |
``` cpp
|
| 950 |
namespace std {
|
| 951 |
template<>
|
| 952 |
class ctype<char> : public locale::facet, public ctype_base {
|
| 953 |
public:
|
| 954 |
using char_type = char;
|
| 955 |
|
| 956 |
+
explicit ctype(const mask* tab = nullptr, bool del = false, size_t refs = 0);
|
|
|
|
| 957 |
|
| 958 |
bool is(mask m, char c) const;
|
| 959 |
const char* is(const char* low, const char* high, mask* vec) const;
|
| 960 |
+
const char* scan_is (mask m, const char* low, const char* high) const;
|
| 961 |
+
const char* scan_not(mask m, const char* low, const char* high) const;
|
|
|
|
|
|
|
| 962 |
|
| 963 |
char toupper(char c) const;
|
| 964 |
const char* toupper(char* low, const char* high) const;
|
| 965 |
char tolower(char c) const;
|
| 966 |
const char* tolower(char* low, const char* high) const;
|
| 967 |
|
| 968 |
char widen(char c) const;
|
| 969 |
const char* widen(const char* low, const char* high, char* to) const;
|
| 970 |
char narrow(char c, char dfault) const;
|
| 971 |
+
const char* narrow(const char* low, const char* high, char dfault, char* to) const;
|
|
|
|
| 972 |
|
| 973 |
static locale::id id;
|
| 974 |
static const size_t table_size = implementation-defined;
|
| 975 |
|
| 976 |
const mask* table() const noexcept;
|
|
|
|
| 982 |
virtual const char* do_toupper(char* low, const char* high) const;
|
| 983 |
virtual char do_tolower(char c) const;
|
| 984 |
virtual const char* do_tolower(char* low, const char* high) const;
|
| 985 |
|
| 986 |
virtual char do_widen(char c) const;
|
| 987 |
+
virtual const char* do_widen(const char* low, const char* high, char* to) const;
|
|
|
|
|
|
|
| 988 |
virtual char do_narrow(char c, char dfault) const;
|
| 989 |
+
virtual const char* do_narrow(const char* low, const char* high,
|
|
|
|
| 990 |
char dfault, char* to) const;
|
| 991 |
};
|
| 992 |
}
|
| 993 |
```
|
| 994 |
|
| 995 |
A specialization `ctype<char>` is provided so that the member functions
|
| 996 |
+
on type `char` can be implemented inline.[^7] The
|
| 997 |
*implementation-defined* value of member `table_size` is at least 256.
|
| 998 |
|
| 999 |
+
##### Destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
|
| 1000 |
|
| 1001 |
``` cpp
|
| 1002 |
~ctype();
|
| 1003 |
```
|
| 1004 |
|
| 1005 |
*Effects:* If the constructor’s first argument was nonzero, and its
|
| 1006 |
second argument was `true`, does `delete [] table()`.
|
| 1007 |
|
| 1008 |
+
##### Members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
|
| 1009 |
|
| 1010 |
In the following member descriptions, for `unsigned char` values `v`
|
| 1011 |
where `v >= table_size`, `table()[v]` is assumed to have an
|
| 1012 |
implementation-specific value (possibly different for each such value
|
| 1013 |
`v`) without performing the array lookup.
|
| 1014 |
|
| 1015 |
``` cpp
|
| 1016 |
+
explicit ctype(const mask* tbl = nullptr, bool del = false, size_t refs = 0);
|
|
|
|
| 1017 |
```
|
| 1018 |
|
| 1019 |
+
*Preconditions:* Either `tbl == nullptr` is `true` or \[`tbl`,
|
| 1020 |
+
`tbl+table_size`) is a valid range.
|
| 1021 |
|
| 1022 |
*Effects:* Passes its `refs` argument to its base class constructor.
|
| 1023 |
|
| 1024 |
``` cpp
|
| 1025 |
bool is(mask m, char c) const;
|
| 1026 |
+
const char* is(const char* low, const char* high, mask* vec) const;
|
|
|
|
| 1027 |
```
|
| 1028 |
|
| 1029 |
*Effects:* The second form, for all `*p` in the range \[`low`, `high`),
|
| 1030 |
assigns into `vec[p - low]` the value `table()[(unsigned char)*p]`.
|
| 1031 |
|
| 1032 |
*Returns:* The first form returns `table()[(unsigned char)c] & m`; the
|
| 1033 |
second form returns `high`.
|
| 1034 |
|
| 1035 |
``` cpp
|
| 1036 |
+
const char* scan_is(mask m, const char* low, const char* high) const;
|
|
|
|
| 1037 |
```
|
| 1038 |
|
| 1039 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 1040 |
|
| 1041 |
``` cpp
|
|
|
|
| 1043 |
```
|
| 1044 |
|
| 1045 |
is `true`.
|
| 1046 |
|
| 1047 |
``` cpp
|
| 1048 |
+
const char* scan_not(mask m, const char* low, const char* high) const;
|
|
|
|
| 1049 |
```
|
| 1050 |
|
| 1051 |
*Returns:* The smallest `p` in the range \[`low`, `high`) such that
|
| 1052 |
|
| 1053 |
``` cpp
|
|
|
|
| 1070 |
|
| 1071 |
*Returns:* `do_tolower(c)` or `do_tolower(low, high)`, respectively.
|
| 1072 |
|
| 1073 |
``` cpp
|
| 1074 |
char widen(char c) const;
|
| 1075 |
+
const char* widen(const char* low, const char* high, char* to) const;
|
|
|
|
| 1076 |
```
|
| 1077 |
|
| 1078 |
*Returns:* `do_widen(c)` or `do_widen(low, high, to)`, respectively.
|
| 1079 |
|
| 1080 |
``` cpp
|
| 1081 |
char narrow(char c, char dfault) const;
|
| 1082 |
+
const char* narrow(const char* low, const char* high, char dfault, char* to) const;
|
|
|
|
| 1083 |
```
|
| 1084 |
|
| 1085 |
*Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`,
|
| 1086 |
respectively.
|
| 1087 |
|
|
|
|
| 1090 |
```
|
| 1091 |
|
| 1092 |
*Returns:* The first constructor argument, if it was nonzero, otherwise
|
| 1093 |
`classic_table()`.
|
| 1094 |
|
| 1095 |
+
##### Static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
|
| 1096 |
|
| 1097 |
``` cpp
|
| 1098 |
static const mask* classic_table() noexcept;
|
| 1099 |
```
|
| 1100 |
|
| 1101 |
*Returns:* A pointer to the initial element of an array of size
|
| 1102 |
`table_size` which represents the classifications of characters in the
|
| 1103 |
`"C"` locale.
|
| 1104 |
|
| 1105 |
+
##### Virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
|
| 1106 |
|
| 1107 |
``` cpp
|
| 1108 |
char do_toupper(char) const;
|
| 1109 |
const char* do_toupper(char* low, const char* high) const;
|
| 1110 |
char do_tolower(char) const;
|
| 1111 |
const char* do_tolower(char* low, const char* high) const;
|
| 1112 |
|
| 1113 |
virtual char do_widen(char c) const;
|
| 1114 |
+
virtual const char* do_widen(const char* low, const char* high, char* to) const;
|
|
|
|
|
|
|
| 1115 |
virtual char do_narrow(char c, char dfault) const;
|
| 1116 |
+
virtual const char* do_narrow(const char* low, const char* high,
|
|
|
|
| 1117 |
char dfault, char* to) const;
|
| 1118 |
```
|
| 1119 |
|
| 1120 |
These functions are described identically as those members of the same
|
| 1121 |
+
name in the `ctype` class template [[locale.ctype.members]].
|
| 1122 |
|
| 1123 |
#### Class template `codecvt` <a id="locale.codecvt">[[locale.codecvt]]</a>
|
| 1124 |
|
| 1125 |
``` cpp
|
| 1126 |
namespace std {
|
|
|
|
| 1181 |
}
|
| 1182 |
```
|
| 1183 |
|
| 1184 |
The class `codecvt<internT, externT, stateT>` is for use when converting
|
| 1185 |
from one character encoding to another, such as from wide characters to
|
| 1186 |
+
multibyte characters or between wide character encodings such as UTF-32
|
| 1187 |
and EUC.
|
| 1188 |
|
| 1189 |
The `stateT` argument selects the pair of character encodings being
|
| 1190 |
mapped between.
|
| 1191 |
|
| 1192 |
+
The specializations required in [[locale.category.facets]]
|
| 1193 |
+
[[locale.category]] convert the implementation-defined native character
|
| 1194 |
+
set. `codecvt<char, char, mbstate_t>` implements a degenerate
|
| 1195 |
+
conversion; it does not convert at all. The specialization
|
| 1196 |
+
`codecvt<char16_t, char8_t, mbstate_t>` converts between the UTF-16 and
|
|
|
|
| 1197 |
UTF-8 encoding forms, and the specialization `codecvt`
|
| 1198 |
+
`<char32_t, char8_t, mbstate_t>` converts between the UTF-32 and UTF-8
|
| 1199 |
encoding forms. `codecvt<wchar_t, char, mbstate_t>` converts between the
|
| 1200 |
+
native character sets for ordinary and wide characters. Specializations
|
| 1201 |
+
on `mbstate_t` perform conversion between encodings known to the library
|
| 1202 |
implementer. Other encodings can be converted by specializing on a
|
| 1203 |
+
program-defined `stateT` type. Objects of type `stateT` can contain any
|
| 1204 |
state that is useful to communicate to or from the specialized `do_in`
|
| 1205 |
or `do_out` members.
|
| 1206 |
|
| 1207 |
+
##### Members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
|
| 1208 |
|
| 1209 |
``` cpp
|
| 1210 |
result out(
|
| 1211 |
stateT& state,
|
| 1212 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
|
|
| 1254 |
int max_length() const noexcept;
|
| 1255 |
```
|
| 1256 |
|
| 1257 |
*Returns:* `do_max_length()`.
|
| 1258 |
|
| 1259 |
+
##### Virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
|
| 1260 |
|
| 1261 |
``` cpp
|
| 1262 |
result do_out(
|
| 1263 |
stateT& state,
|
| 1264 |
const internT* from, const internT* from_end, const internT*& from_next,
|
|
|
|
| 1268 |
stateT& state,
|
| 1269 |
const externT* from, const externT* from_end, const externT*& from_next,
|
| 1270 |
internT* to, internT* to_end, internT*& to_next) const;
|
| 1271 |
```
|
| 1272 |
|
| 1273 |
+
*Preconditions:* `(from <= from_end && to <= to_end)` is well-defined
|
| 1274 |
+
and `true`; `state` is initialized, if at the beginning of a sequence,
|
| 1275 |
+
or else is equal to the result of converting the preceding characters in
|
| 1276 |
+
the sequence.
|
| 1277 |
|
| 1278 |
*Effects:* Translates characters in the source range \[`from`,
|
| 1279 |
`from_end`), placing the results in sequential positions starting at
|
| 1280 |
destination `to`. Converts no more than `(from_end - from)` source
|
| 1281 |
elements, and stores no more than `(to_end - to)` destination elements.
|
|
|
|
| 1286 |
`externT` are the same type and the converted sequence is identical to
|
| 1287 |
the input sequence \[`from`, `from``next`). `to_next` is set equal to
|
| 1288 |
`to`, the value of `state` is unchanged, and there are no changes to the
|
| 1289 |
values in \[`to`, `to_end`).
|
| 1290 |
|
| 1291 |
+
A `codecvt` facet that is used by `basic_filebuf` [[file.streams]] shall
|
| 1292 |
+
have the property that if
|
| 1293 |
|
| 1294 |
``` cpp
|
| 1295 |
do_out(state, from, from_end, from_next, to, to_end, to_next)
|
| 1296 |
```
|
| 1297 |
|
|
|
|
| 1324 |
[*Note 2*: This argument can be used, for example, to maintain shift
|
| 1325 |
state, to specify conversion options (such as count only), or to
|
| 1326 |
identify a cache of seek offsets. — *end note*]
|
| 1327 |
|
| 1328 |
*Returns:* An enumeration value, as summarized in
|
| 1329 |
+
[[locale.codecvt.inout]].
|
| 1330 |
|
| 1331 |
+
**Table: `do_in/do_out` result values** <a id="locale.codecvt.inout">[locale.codecvt.inout]</a>
|
| 1332 |
|
| 1333 |
| Value | Meaning |
|
| 1334 |
| --------- | ------------------------------------------------------------------------------------------------ |
|
| 1335 |
| `ok` | completed the conversion |
|
| 1336 |
| `partial` | not all source characters converted |
|
|
|
|
| 1345 |
|
| 1346 |
``` cpp
|
| 1347 |
result do_unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
|
| 1348 |
```
|
| 1349 |
|
| 1350 |
+
*Preconditions:* `(to <= to_end)` is well-defined and `true`; `state` is
|
| 1351 |
+
initialized, if at the beginning of a sequence, or else is equal to the
|
| 1352 |
+
result of converting the preceding characters in the sequence.
|
| 1353 |
|
| 1354 |
*Effects:* Places characters starting at `to` that should be appended to
|
| 1355 |
terminate a sequence when the current `stateT` is given by `state`.[^9]
|
| 1356 |
Stores no more than `(to_end - to)` destination elements, and leaves the
|
| 1357 |
`to_next` pointer pointing one beyond the last element successfully
|
| 1358 |
stored.
|
| 1359 |
|
| 1360 |
*Returns:* An enumeration value, as summarized in
|
| 1361 |
+
[[locale.codecvt.unshift]].
|
| 1362 |
|
| 1363 |
+
**Table: `do_unshift` result values** <a id="locale.codecvt.unshift">[locale.codecvt.unshift]</a>
|
| 1364 |
|
| 1365 |
| Value | Meaning |
|
| 1366 |
| --------- | -------------------------------------------------------------------------------------------------------------------- |
|
| 1367 |
| `ok` | completed the sequence |
|
| 1368 |
| `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
|
|
|
|
| 1387 |
|
| 1388 |
``` cpp
|
| 1389 |
int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
|
| 1390 |
```
|
| 1391 |
|
| 1392 |
+
*Preconditions:* `(from <= from_end)` is well-defined and `true`;
|
| 1393 |
+
`state` is initialized, if at the beginning of a sequence, or else is
|
| 1394 |
+
equal to the result of converting the preceding characters in the
|
| 1395 |
+
sequence.
|
| 1396 |
|
| 1397 |
+
*Effects:* The effect on the `state` argument is as if it called
|
| 1398 |
`do_in(state, from, from_end, from, to, to+max, to)` for `to` pointing
|
| 1399 |
to a buffer of at least `max` elements.
|
| 1400 |
|
| 1401 |
*Returns:* `(from_next-from)` where `from_next` is the largest value in
|
| 1402 |
the range \[`from`, `from_end`\] such that the sequence of values in the
|
|
|
|
| 1421 |
template<class internT, class externT, class stateT>
|
| 1422 |
class codecvt_byname : public codecvt<internT, externT, stateT> {
|
| 1423 |
public:
|
| 1424 |
explicit codecvt_byname(const char*, size_t refs = 0);
|
| 1425 |
explicit codecvt_byname(const string&, size_t refs = 0);
|
| 1426 |
+
|
| 1427 |
protected:
|
| 1428 |
~codecvt_byname();
|
| 1429 |
};
|
| 1430 |
}
|
| 1431 |
```
|
|
|
|
| 1437 |
Implementations may (but are not required to) delegate extraction of
|
| 1438 |
smaller types to extractors for larger types.[^11]
|
| 1439 |
|
| 1440 |
All specifications of member functions for `num_put` and `num_get` in
|
| 1441 |
the subclauses of [[category.numeric]] only apply to the
|
| 1442 |
+
specializations required in Tables [[tab:locale.category.facets]] and
|
| 1443 |
+
[[tab:locale.spec]] [[locale.category]], namely `num_get<char>`,
|
| 1444 |
+
`num_get<wchar_t>`, `num_get<C, InputIterator>`, `num_put<char>`,
|
| 1445 |
+
`num_put<wchar_t>`, and `num_put<C, OutputIterator>`. These
|
| 1446 |
+
specializations refer to the `ios_base&` argument for formatting
|
| 1447 |
+
specifications [[locale.categories]], and to its imbued locale for the
|
| 1448 |
+
`numpunct<>` facet to identify all numeric punctuation preferences, and
|
| 1449 |
+
also for the `ctype<>` facet to perform character classification.
|
|
|
|
| 1450 |
|
| 1451 |
Extractor and inserter members of the standard iostreams use `num_get<>`
|
| 1452 |
and `num_put<>` member functions for formatting and parsing numeric
|
| 1453 |
values ([[istream.formatted.reqmts]], [[ostream.formatted.reqmts]]).
|
| 1454 |
|
|
|
|
| 1518 |
```
|
| 1519 |
|
| 1520 |
The facet `num_get` is used to parse numeric values from an input
|
| 1521 |
sequence such as an istream.
|
| 1522 |
|
| 1523 |
+
##### Members <a id="facet.num.get.members">[[facet.num.get.members]]</a>
|
| 1524 |
|
| 1525 |
``` cpp
|
| 1526 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
| 1527 |
ios_base::iostate& err, bool& val) const;
|
| 1528 |
iter_type get(iter_type in, iter_type end, ios_base& str,
|
|
|
|
| 1547 |
ios_base::iostate& err, void*& val) const;
|
| 1548 |
```
|
| 1549 |
|
| 1550 |
*Returns:* `do_get(in, end, str, err, val)`.
|
| 1551 |
|
| 1552 |
+
##### Virtual functions <a id="facet.num.get.virtuals">[[facet.num.get.virtuals]]</a>
|
| 1553 |
|
| 1554 |
``` cpp
|
| 1555 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
| 1556 |
ios_base::iostate& err, long& val) const;
|
| 1557 |
iter_type do_get(iter_type in, iter_type end, ios_base& str,
|
|
|
|
| 1598 |
fmtflags uppercase = (flags & ios_base::uppercase);
|
| 1599 |
fmtflags boolalpha = (flags & ios_base::boolalpha);
|
| 1600 |
```
|
| 1601 |
|
| 1602 |
For conversion to an integral type, the function determines the integral
|
| 1603 |
+
conversion specifier as indicated in [[facet.num.get.int]]. The
|
| 1604 |
+
table is ordered. That is, the first line whose condition is true
|
| 1605 |
+
applies.
|
| 1606 |
|
| 1607 |
+
**Table: Integer conversions** <a id="facet.num.get.int">[facet.num.get.int]</a>
|
| 1608 |
|
| 1609 |
| State | `stdio` equivalent |
|
| 1610 |
| ------------------------ | ------------------ |
|
| 1611 |
| `basefield == oct` | `%o` |
|
| 1612 |
| `basefield == hex` | `%X` |
|
| 1613 |
| `basefield == 0` | `%i` `signed` integral type | `%d` |
|
| 1614 |
| `unsigned` integral type | `%u` |
|
| 1615 |
|
| 1616 |
|
| 1617 |
+
For conversions to a floating-point type the specifier is `%g`.
|
| 1618 |
|
| 1619 |
For conversions to `void*` the specifier is `%p`.
|
| 1620 |
|
| 1621 |
A length modifier is added to the conversion specification, if needed,
|
| 1622 |
+
as indicated in [[facet.num.get.length]].
|
| 1623 |
|
| 1624 |
+
**Table: Length modifier** <a id="facet.num.get.length">[facet.num.get.length]</a>
|
| 1625 |
|
| 1626 |
| Type | Length modifier |
|
| 1627 |
| -------------------- | --------------- |
|
| 1628 |
| `short` | `h` |
|
| 1629 |
| `unsigned short` | `h` |
|
|
|
|
| 1791 |
```
|
| 1792 |
|
| 1793 |
The facet `num_put` is used to format numeric values to a character
|
| 1794 |
sequence such as an ostream.
|
| 1795 |
|
| 1796 |
+
##### Members <a id="facet.num.put.members">[[facet.num.put.members]]</a>
|
| 1797 |
|
| 1798 |
``` cpp
|
| 1799 |
iter_type put(iter_type out, ios_base& str, char_type fill, bool val) const;
|
| 1800 |
iter_type put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1801 |
iter_type put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
|
|
|
| 1806 |
iter_type put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
| 1807 |
```
|
| 1808 |
|
| 1809 |
*Returns:* `do_put(out, str, fill, val)`.
|
| 1810 |
|
| 1811 |
+
##### Virtual functions <a id="facet.num.put.virtuals">[[facet.num.put.virtuals]]</a>
|
| 1812 |
|
| 1813 |
``` cpp
|
| 1814 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long val) const;
|
| 1815 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long long val) const;
|
| 1816 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
|
|
|
|
| 1819 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, long double val) const;
|
| 1820 |
iter_type do_put(iter_type out, ios_base& str, char_type fill, const void* val) const;
|
| 1821 |
```
|
| 1822 |
|
| 1823 |
*Effects:* Writes characters to the sequence `out`, formatting `val` as
|
| 1824 |
+
desired. In the following description, `loc` names a local variable
|
| 1825 |
+
initialized as
|
| 1826 |
|
| 1827 |
``` cpp
|
| 1828 |
locale loc = str.getloc();
|
| 1829 |
```
|
| 1830 |
|
| 1831 |
The details of this operation occur in several stages:
|
| 1832 |
|
| 1833 |
- Stage 1: Determine a printf conversion specifier `spec` and determine
|
| 1834 |
+
the characters that would be printed by `printf` [[c.files]] given
|
| 1835 |
this conversion specifier for
|
| 1836 |
``` cpp
|
| 1837 |
printf(spec, val)
|
| 1838 |
```
|
| 1839 |
|
| 1840 |
assuming that the current locale is the `"C"` locale.
|
| 1841 |
- Stage 2: Adjust the representation by converting each `char`
|
| 1842 |
determined by stage 1 to a `charT` using a conversion and values
|
| 1843 |
+
returned by members of `use_facet<numpunct<charT>>(loc)`.
|
| 1844 |
- Stage 3: Determine where padding is required.
|
| 1845 |
- Stage 4: Insert the sequence into the `out`.
|
| 1846 |
|
| 1847 |
Detailed descriptions of each stage follow.
|
| 1848 |
|
|
|
|
| 1868 |
line whose condition is true applies. A line without a condition is the
|
| 1869 |
default behavior when none of the earlier lines apply.
|
| 1870 |
|
| 1871 |
For conversion from an integral type other than a character type, the
|
| 1872 |
function determines the integral conversion specifier as indicated in
|
| 1873 |
+
[[facet.num.put.int]].
|
| 1874 |
|
| 1875 |
+
**Table: Integer conversions** <a id="facet.num.put.int">[facet.num.put.int]</a>
|
| 1876 |
|
| 1877 |
| State | `stdio` equivalent |
|
| 1878 |
| -------------------------------------------- | ------------------ |
|
| 1879 |
| `basefield == ios_base::oct` | `%o` |
|
| 1880 |
| `(basefield == ios_base::hex) && !uppercase` | `%x` |
|
|
|
|
| 1883 |
| for an `unsigned` integral type | `%u` |
|
| 1884 |
|
| 1885 |
|
| 1886 |
For conversion from a floating-point type, the function determines the
|
| 1887 |
floating-point conversion specifier as indicated in
|
| 1888 |
+
[[facet.num.put.fp]].
|
| 1889 |
|
| 1890 |
+
**Table: Floating-point conversions** <a id="facet.num.put.fp">[facet.num.put.fp]</a>
|
| 1891 |
|
| 1892 |
| State | `stdio` equivalent |
|
| 1893 |
| ---------------------------------------------------------------------- | ------------------ |
|
| 1894 |
| `floatfield == ios_base::fixed` | `%f` |
|
| 1895 |
| `floatfield == ios_base::scientific && !uppercase` | `%e` |
|
|
|
|
| 1900 |
| otherwise | `%G` |
|
| 1901 |
|
| 1902 |
|
| 1903 |
For conversions from an integral or floating-point type a length
|
| 1904 |
modifier is added to the conversion specifier as indicated in
|
| 1905 |
+
[[facet.num.put.length]].
|
| 1906 |
|
| 1907 |
+
**Table: Length modifier** <a id="facet.num.put.length">[facet.num.put.length]</a>
|
| 1908 |
|
| 1909 |
| Type | Length modifier |
|
| 1910 |
| -------------------- | --------------- |
|
| 1911 |
| `long` | `l` |
|
| 1912 |
| `long long` | `ll` |
|
|
|
|
| 1915 |
| `long double` | `L` |
|
| 1916 |
| otherwise | none |
|
| 1917 |
|
| 1918 |
|
| 1919 |
The conversion specifier has the following optional additional
|
| 1920 |
+
qualifiers prepended as indicated in [[facet.num.put.conv]].
|
|
|
|
| 1921 |
|
| 1922 |
+
**Table: Numeric conversions** <a id="facet.num.put.conv">[facet.num.put.conv]</a>
|
| 1923 |
|
| 1924 |
| Type(s) | State | `stdio` equivalent |
|
| 1925 |
| --------------------- | ----------- | ------------------ |
|
| 1926 |
| an integral type | `showpos` | `+` |
|
| 1927 |
| | `showbase` | `#` |
|
|
|
|
| 1941 |
conversion specifier determined above.
|
| 1942 |
|
| 1943 |
- **Stage 2:**
|
| 1944 |
|
| 1945 |
Any character `c` other than a decimal point(.) is converted to a
|
| 1946 |
+
`charT` via
|
| 1947 |
+
|
| 1948 |
+
``` cpp
|
| 1949 |
+
use_facet<ctype<charT>>(loc).widen(c)
|
| 1950 |
+
```
|
| 1951 |
|
| 1952 |
A local variable `punct` is initialized via
|
| 1953 |
|
| 1954 |
``` cpp
|
| 1955 |
+
const numpunct<charT>& punct = use_facet<numpunct<charT>>(loc);
|
| 1956 |
```
|
| 1957 |
|
| 1958 |
For arithmetic types, `punct.thousands_sep()` characters are inserted
|
| 1959 |
into the sequence as determined by the value returned by
|
| 1960 |
`punct.do_grouping()` using the method described
|
|
|
|
| 1969 |
``` cpp
|
| 1970 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 1971 |
```
|
| 1972 |
|
| 1973 |
The location of any padding[^12] is determined according to
|
| 1974 |
+
[[facet.num.put.fill]].
|
| 1975 |
|
| 1976 |
+
**Table: Fill padding** <a id="facet.num.put.fill">[facet.num.put.fill]</a>
|
| 1977 |
|
| 1978 |
| State | Location |
|
| 1979 |
| ------------------------------------------------------------------------------ | ------------------ |
|
| 1980 |
| `adjustfield == ios_base::left` | pad after |
|
| 1981 |
| `adjustfield == ios_base::right` | pad before |
|
|
|
|
| 2049 |
}
|
| 2050 |
```
|
| 2051 |
|
| 2052 |
`numpunct<>`
|
| 2053 |
|
| 2054 |
+
specifies numeric punctuation. The specializations required in
|
| 2055 |
+
[[locale.category.facets]] [[locale.category]], namely
|
| 2056 |
`numpunct<{}wchar_t>` and `numpunct<char>`, provide classic `"C"`
|
| 2057 |
numeric formats, i.e., they contain information equivalent to that
|
| 2058 |
contained in the `"C"` locale or their wide character counterparts as if
|
| 2059 |
obtained by a call to `widen`.
|
| 2060 |
|
| 2061 |
+
The syntax for number formats is as follows, where represents the radix
|
| 2062 |
+
set specified by the `fmtflags` argument value, and and are the results
|
| 2063 |
+
of corresponding `numpunct<charT>` members. Integer values have the
|
| 2064 |
+
format:
|
| 2065 |
+
|
| 2066 |
+
``` bnf
|
| 2067 |
+
intval:
|
| 2068 |
+
signₒₚₜ units
|
| 2069 |
+
```
|
| 2070 |
+
|
| 2071 |
+
``` bnf
|
| 2072 |
+
sign:
|
| 2073 |
+
'+'
|
| 2074 |
+
'-'
|
| 2075 |
+
```
|
| 2076 |
+
|
| 2077 |
+
``` bnf
|
| 2078 |
+
units:
|
| 2079 |
+
digits
|
| 2080 |
+
digits thousands-sep units
|
| 2081 |
+
```
|
| 2082 |
+
|
| 2083 |
+
``` bnf
|
| 2084 |
+
digits:
|
| 2085 |
+
digit digitsₒₚₜ
|
| 2086 |
```
|
| 2087 |
|
| 2088 |
and floating-point values have:
|
| 2089 |
|
| 2090 |
+
``` bnf
|
| 2091 |
+
floatval:
|
| 2092 |
+
signₒₚₜ units fractionalₒₚₜ exponentₒₚₜ
|
| 2093 |
+
signₒₚₜ decimal-point digits exponentₒₚₜ
|
| 2094 |
```
|
| 2095 |
|
| 2096 |
+
``` bnf
|
| 2097 |
+
fractional:
|
| 2098 |
+
decimal-point digitsₒₚₜ
|
| 2099 |
+
```
|
| 2100 |
+
|
| 2101 |
+
``` bnf
|
| 2102 |
+
exponent:
|
| 2103 |
+
e signₒₚₜ digits
|
| 2104 |
+
```
|
| 2105 |
+
|
| 2106 |
+
``` bnf
|
| 2107 |
+
e:
|
| 2108 |
+
'e'
|
| 2109 |
+
'E'
|
| 2110 |
+
```
|
| 2111 |
+
|
| 2112 |
+
where the number of digits between is as specified by `do_grouping()`.
|
| 2113 |
+
For parsing, if the portion contains no thousands-separators, no
|
| 2114 |
+
grouping constraint is applied.
|
| 2115 |
|
| 2116 |
+
##### Members <a id="facet.numpunct.members">[[facet.numpunct.members]]</a>
|
| 2117 |
|
| 2118 |
``` cpp
|
| 2119 |
char_type decimal_point() const;
|
| 2120 |
```
|
| 2121 |
|
|
|
|
| 2138 |
string_type falsename() const;
|
| 2139 |
```
|
| 2140 |
|
| 2141 |
*Returns:* `do_truename()` or `do_falsename()`, respectively.
|
| 2142 |
|
| 2143 |
+
##### Virtual functions <a id="facet.numpunct.virtuals">[[facet.numpunct.virtuals]]</a>
|
| 2144 |
|
| 2145 |
``` cpp
|
| 2146 |
char_type do_decimal_point() const;
|
| 2147 |
```
|
| 2148 |
|
|
|
|
| 2158 |
|
| 2159 |
``` cpp
|
| 2160 |
string do_grouping() const;
|
| 2161 |
```
|
| 2162 |
|
| 2163 |
+
*Returns:* A `string` `vec` used as a vector of integer values, in which
|
| 2164 |
+
each element `vec[i]` represents the number of digits[^13] in the group
|
| 2165 |
+
at position `i`, starting with position 0 as the rightmost group. If
|
| 2166 |
+
`vec.size() <= i`, the number is the same as group `(i - 1)`; if
|
| 2167 |
+
`(i < 0 || vec[i] <= 0 || vec[i] == CHAR_MAX)`, the size of the digit
|
| 2168 |
+
group is unlimited.
|
| 2169 |
|
| 2170 |
The required specializations return the empty string, indicating no
|
| 2171 |
grouping.
|
| 2172 |
|
| 2173 |
``` cpp
|
|
|
|
| 2192 |
using char_type = charT;
|
| 2193 |
using string_type = basic_string<charT>;
|
| 2194 |
|
| 2195 |
explicit numpunct_byname(const char*, size_t refs = 0);
|
| 2196 |
explicit numpunct_byname(const string&, size_t refs = 0);
|
| 2197 |
+
|
| 2198 |
protected:
|
| 2199 |
~numpunct_byname();
|
| 2200 |
};
|
| 2201 |
}
|
| 2202 |
```
|
|
|
|
| 2233 |
```
|
| 2234 |
|
| 2235 |
The class `collate<charT>` provides features for use in the collation
|
| 2236 |
(comparison) and hashing of strings. A locale member function template,
|
| 2237 |
`operator()`, uses the collate facet to allow a locale to act directly
|
| 2238 |
+
as the predicate argument for standard algorithms [[algorithms]] and
|
| 2239 |
+
containers operating on strings. The specializations required in
|
| 2240 |
+
[[locale.category.facets]] [[locale.category]], namely `collate<char>`
|
| 2241 |
+
and `collate<wchar_t>`, apply lexicographic ordering
|
| 2242 |
+
[[alg.lex.comparison]].
|
| 2243 |
|
| 2244 |
Each function compares a string of characters `*p` in the range \[`low`,
|
| 2245 |
`high`).
|
| 2246 |
|
| 2247 |
+
##### Members <a id="locale.collate.members">[[locale.collate.members]]</a>
|
| 2248 |
|
| 2249 |
``` cpp
|
| 2250 |
int compare(const charT* low1, const charT* high1,
|
| 2251 |
const charT* low2, const charT* high2) const;
|
| 2252 |
```
|
|
|
|
| 2263 |
long hash(const charT* low, const charT* high) const;
|
| 2264 |
```
|
| 2265 |
|
| 2266 |
*Returns:* `do_hash(low, high)`.
|
| 2267 |
|
| 2268 |
+
##### Virtual functions <a id="locale.collate.virtuals">[[locale.collate.virtuals]]</a>
|
| 2269 |
|
| 2270 |
``` cpp
|
| 2271 |
int do_compare(const charT* low1, const charT* high1,
|
| 2272 |
const charT* low2, const charT* high2) const;
|
| 2273 |
```
|
| 2274 |
|
| 2275 |
*Returns:* `1` if the first string is greater than the second, `-1` if
|
| 2276 |
less, zero otherwise. The specializations required in
|
| 2277 |
+
[[locale.category.facets]][[locale.category]], namely `collate<char>`
|
| 2278 |
+
and `collate<wchar_t>`, implement a lexicographical
|
| 2279 |
+
comparison [[alg.lex.comparison]].
|
| 2280 |
|
| 2281 |
``` cpp
|
| 2282 |
string_type do_transform(const charT* low, const charT* high) const;
|
| 2283 |
```
|
| 2284 |
|
|
|
|
| 2308 |
public:
|
| 2309 |
using string_type = basic_string<charT>;
|
| 2310 |
|
| 2311 |
explicit collate_byname(const char*, size_t refs = 0);
|
| 2312 |
explicit collate_byname(const string&, size_t refs = 0);
|
| 2313 |
+
|
| 2314 |
protected:
|
| 2315 |
~collate_byname();
|
| 2316 |
};
|
| 2317 |
}
|
| 2318 |
```
|
|
|
|
| 2321 |
|
| 2322 |
Templates `time_get<charT, InputIterator>` and
|
| 2323 |
`time_put<charT, OutputIterator>` provide date and time formatting and
|
| 2324 |
parsing. All specifications of member functions for `time_put` and
|
| 2325 |
`time_get` in the subclauses of [[category.time]] only apply to the
|
| 2326 |
+
specializations required in Tables [[tab:locale.category.facets]] and
|
| 2327 |
+
[[tab:locale.spec]] [[locale.category]]. Their members use their
|
| 2328 |
+
`ios_base&`, `ios_base::iostate&`, and `fill` arguments as described in
|
|
|
|
| 2329 |
[[locale.categories]], and the `ctype<>` facet, to determine formatting
|
| 2330 |
details.
|
| 2331 |
|
| 2332 |
#### Class template `time_get` <a id="locale.time.get">[[locale.time.get]]</a>
|
| 2333 |
|
|
|
|
| 2395 |
unspecified values are assigned.[^15]
|
| 2396 |
|
| 2397 |
If the end iterator is reached during parsing by any of the `get()`
|
| 2398 |
member functions, the member sets `ios_base::eofbit` in `err`.
|
| 2399 |
|
| 2400 |
+
##### Members <a id="locale.time.get.members">[[locale.time.get.members]]</a>
|
| 2401 |
|
| 2402 |
``` cpp
|
| 2403 |
dateorder date_order() const;
|
| 2404 |
```
|
| 2405 |
|
|
|
|
| 2446 |
``` cpp
|
| 2447 |
iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
|
| 2448 |
tm* t, const char_type* fmt, const char_type* fmtend) const;
|
| 2449 |
```
|
| 2450 |
|
| 2451 |
+
*Preconditions:* \[`fmt`, `fmtend`) is a valid range.
|
| 2452 |
|
| 2453 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 2454 |
It then enters a loop, reading zero or more characters from `s` at each
|
| 2455 |
iteration. Unless otherwise specified below, the loop terminates when
|
| 2456 |
the first of the following conditions holds:
|
|
|
|
| 2488 |
whether multi-character sequences are considered while doing
|
| 2489 |
so. — *end note*]
|
| 2490 |
|
| 2491 |
*Returns:* `s`.
|
| 2492 |
|
| 2493 |
+
##### Virtual functions <a id="locale.time.get.virtuals">[[locale.time.get.virtuals]]</a>
|
| 2494 |
|
| 2495 |
``` cpp
|
| 2496 |
dateorder do_date_order() const;
|
| 2497 |
```
|
| 2498 |
|
|
|
|
| 2522 |
|
| 2523 |
*Effects:* Reads characters starting at `s` until it has extracted those
|
| 2524 |
`struct tm` members and remaining format characters used by
|
| 2525 |
`time_put<>::put` to produce one of the following formats, or until it
|
| 2526 |
encounters an error. The format depends on the value returned by
|
| 2527 |
+
`date_order()` as shown in [[locale.time.get.dogetdate]].
|
|
|
|
| 2528 |
|
| 2529 |
+
**Table: `do_get_date` effects** <a id="locale.time.get.dogetdate">[locale.time.get.dogetdate]</a>
|
| 2530 |
|
| 2531 |
| `date_order()` | Format |
|
| 2532 |
| -------------- | ---------- |
|
| 2533 |
| `no_order` | `"%m%d%y"` |
|
| 2534 |
| `dmy` | `"%d%m%y"` |
|
|
|
|
| 2575 |
``` cpp
|
| 2576 |
iter_type do_get(iter_type s, iter_type end, ios_base& f,
|
| 2577 |
ios_base::iostate& err, tm* t, char format, char modifier) const;
|
| 2578 |
```
|
| 2579 |
|
| 2580 |
+
*Preconditions:* `t` points to an object.
|
| 2581 |
|
| 2582 |
*Effects:* The function starts by evaluating `err = ios_base::goodbit`.
|
| 2583 |
It then reads characters starting at `s` until it encounters an error,
|
| 2584 |
or until it has extracted and assigned those `struct tm` members, and
|
| 2585 |
any remaining format characters, corresponding to a conversion directive
|
|
|
|
| 2599 |
members are unspecified and may be outside their valid range.
|
| 2600 |
|
| 2601 |
*Remarks:* It is unspecified whether multiple calls to `do_get()` with
|
| 2602 |
the address of the same `struct tm` object will update the current
|
| 2603 |
contents of the object or simply overwrite its members. Portable
|
| 2604 |
+
programs should zero out the object before invoking the function.
|
| 2605 |
|
| 2606 |
*Returns:* An iterator pointing immediately beyond the last character
|
| 2607 |
recognized as possibly part of a valid input sequence for the given
|
| 2608 |
`format` and `modifier`.
|
| 2609 |
|
|
|
|
| 2617 |
using dateorder = time_base::dateorder;
|
| 2618 |
using iter_type = InputIterator;
|
| 2619 |
|
| 2620 |
explicit time_get_byname(const char*, size_t refs = 0);
|
| 2621 |
explicit time_get_byname(const string&, size_t refs = 0);
|
| 2622 |
+
|
| 2623 |
protected:
|
| 2624 |
~time_get_byname();
|
| 2625 |
};
|
| 2626 |
}
|
| 2627 |
```
|
|
|
|
| 2652 |
char format, char modifier) const;
|
| 2653 |
};
|
| 2654 |
}
|
| 2655 |
```
|
| 2656 |
|
| 2657 |
+
##### Members <a id="locale.time.put.members">[[locale.time.put.members]]</a>
|
| 2658 |
|
| 2659 |
``` cpp
|
| 2660 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
| 2661 |
const charT* pattern, const charT* pat_end) const;
|
| 2662 |
iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
|
|
|
|
| 2685 |
reasonable default for this argument. — *end note*]
|
| 2686 |
|
| 2687 |
*Returns:* An iterator pointing immediately after the last character
|
| 2688 |
produced.
|
| 2689 |
|
| 2690 |
+
##### Virtual functions <a id="locale.time.put.virtuals">[[locale.time.put.virtuals]]</a>
|
| 2691 |
|
| 2692 |
``` cpp
|
| 2693 |
iter_type do_put(iter_type s, ios_base&, char_type fill, const tm* t,
|
| 2694 |
char format, char modifier) const;
|
| 2695 |
```
|
|
|
|
| 2712 |
#### Class template `time_put_byname` <a id="locale.time.put.byname">[[locale.time.put.byname]]</a>
|
| 2713 |
|
| 2714 |
``` cpp
|
| 2715 |
namespace std {
|
| 2716 |
template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 2717 |
+
class time_put_byname : public time_put<charT, OutputIterator> {
|
|
|
|
| 2718 |
public:
|
| 2719 |
using char_type = charT;
|
| 2720 |
using iter_type = OutputIterator;
|
| 2721 |
|
| 2722 |
explicit time_put_byname(const char*, size_t refs = 0);
|
| 2723 |
explicit time_put_byname(const string&, size_t refs = 0);
|
| 2724 |
+
|
| 2725 |
protected:
|
| 2726 |
~time_put_byname();
|
| 2727 |
};
|
| 2728 |
}
|
| 2729 |
```
|
|
|
|
| 2733 |
These templates handle monetary formats. A template parameter indicates
|
| 2734 |
whether local or international monetary formats are to be used.
|
| 2735 |
|
| 2736 |
All specifications of member functions for `money_put` and `money_get`
|
| 2737 |
in the subclauses of [[category.monetary]] only apply to the
|
| 2738 |
+
specializations required in Tables [[tab:locale.category.facets]] and
|
| 2739 |
+
[[tab:locale.spec]] [[locale.category]]. Their members use their
|
| 2740 |
+
`ios_base&`, `ios_base::iostate&`, and `fill` arguments as described in
|
|
|
|
| 2741 |
[[locale.categories]], and the `moneypunct<>` and `ctype<>` facets, to
|
| 2742 |
determine formatting details.
|
| 2743 |
|
| 2744 |
#### Class template `money_get` <a id="locale.money.get">[[locale.money.get]]</a>
|
| 2745 |
|
|
|
|
| 2771 |
ios_base::iostate& err, string_type& digits) const;
|
| 2772 |
};
|
| 2773 |
}
|
| 2774 |
```
|
| 2775 |
|
| 2776 |
+
##### Members <a id="locale.money.get.members">[[locale.money.get.members]]</a>
|
| 2777 |
|
| 2778 |
``` cpp
|
| 2779 |
+
iter_type get(iter_type s, iter_type end, bool intl, ios_base& f,
|
| 2780 |
+
ios_base::iostate& err, long double& quant) const;
|
| 2781 |
+
iter_type get(iter_type s, iter_type end, bool intl, ios_base& f,
|
|
|
|
| 2782 |
ios_base::iostate& err, string_type& quant) const;
|
| 2783 |
```
|
| 2784 |
|
| 2785 |
*Returns:* `do_get(s, end, intl, f, err, quant)`.
|
| 2786 |
|
| 2787 |
+
##### Virtual functions <a id="locale.money.get.virtuals">[[locale.money.get.virtuals]]</a>
|
| 2788 |
|
| 2789 |
``` cpp
|
| 2790 |
+
iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
|
| 2791 |
+
ios_base::iostate& err, long double& units) const;
|
| 2792 |
+
iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
|
| 2793 |
+
ios_base::iostate& err, string_type& digits) const;
|
|
|
|
|
|
|
| 2794 |
```
|
| 2795 |
|
| 2796 |
*Effects:* Reads characters from `s` to parse and construct a monetary
|
| 2797 |
value according to the format specified by a `moneypunct<charT, Intl>`
|
| 2798 |
facet reference `mp` and the character mapping specified by a
|
|
|
|
| 2802 |
`(err|str.failbit|str.eofbit)` if no more characters are available, and
|
| 2803 |
does not change `units` or `digits`. Uses the pattern returned by
|
| 2804 |
`mp.neg_format()` to parse all values. The result is returned as an
|
| 2805 |
integral value stored in `units` or as a sequence of digits possibly
|
| 2806 |
preceded by a minus sign (as produced by `ct.widen(c)` where `c` is
|
| 2807 |
+
`’-’` or in the range from `’0’` through `’9’` (inclusive)) stored in
|
| 2808 |
`digits`.
|
| 2809 |
|
| 2810 |
[*Example 1*: The sequence `$1,056.23` in a common United States locale
|
| 2811 |
would yield, for `units`, `105623`, or, for `digits`,
|
| 2812 |
`"105623"`. — *end example*]
|
|
|
|
| 2821 |
element in the format pattern, no white space is consumed. Otherwise,
|
| 2822 |
where `money_base::space` appears in any of the initial elements of the
|
| 2823 |
format pattern, at least one white space character is required. Where
|
| 2824 |
`money_base::none` appears in any of the initial elements of the format
|
| 2825 |
pattern, white space is allowed but not required. If
|
| 2826 |
+
`(str.flags() & str.showbase)` is `false`, the currency symbol is
|
| 2827 |
+
optional and is consumed only if other characters are needed to complete
|
| 2828 |
+
the format; otherwise, the currency symbol is required.
|
| 2829 |
|
| 2830 |
If the first character (if any) in the string `pos` returned by
|
| 2831 |
`mp.positive_sign()` or the string `neg` returned by
|
| 2832 |
`mp.negative_sign()` is recognized in the position indicated by `sign`
|
| 2833 |
in the format pattern, it is consumed and any remaining characters in
|
|
|
|
| 2899 |
const string_type& digits) const;
|
| 2900 |
};
|
| 2901 |
}
|
| 2902 |
```
|
| 2903 |
|
| 2904 |
+
##### Members <a id="locale.money.put.members">[[locale.money.put.members]]</a>
|
| 2905 |
|
| 2906 |
``` cpp
|
| 2907 |
+
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, long double quant) const;
|
| 2908 |
+
iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, const string_type& quant) const;
|
|
|
|
|
|
|
| 2909 |
```
|
| 2910 |
|
| 2911 |
*Returns:* `do_put(s, intl, f, loc, quant)`.
|
| 2912 |
|
| 2913 |
+
##### Virtual functions <a id="locale.money.put.virtuals">[[locale.money.put.virtuals]]</a>
|
| 2914 |
|
| 2915 |
``` cpp
|
| 2916 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
| 2917 |
char_type fill, long double units) const;
|
| 2918 |
iter_type do_put(iter_type s, bool intl, ios_base& str,
|
|
|
|
| 3006 |
```
|
| 3007 |
|
| 3008 |
The `moneypunct<>` facet defines monetary formatting parameters used by
|
| 3009 |
`money_get<>` and `money_put<>`. A monetary format is a sequence of four
|
| 3010 |
components, specified by a `pattern` value `p`, such that the `part`
|
| 3011 |
+
value `static_cast<part>(p.field[i])` determines the `i`ᵗʰ component of
|
| 3012 |
the format[^21] In the `field` member of a `pattern` object, each value
|
| 3013 |
`symbol`, `sign`, `value`, and either `space` or `none` appears exactly
|
| 3014 |
once. The value `none`, if present, is not first; the value `space`, if
|
| 3015 |
present, is neither first nor last.
|
| 3016 |
|
|
|
|
| 3026 |
after all other format components. Where `value` appears, the absolute
|
| 3027 |
numeric monetary value is required.
|
| 3028 |
|
| 3029 |
The format of the numeric monetary value is a decimal number:
|
| 3030 |
|
| 3031 |
+
``` bnf
|
| 3032 |
+
value:
|
| 3033 |
+
units fractionalₒₚₜ
|
| 3034 |
decimal-point digits
|
| 3035 |
```
|
| 3036 |
|
| 3037 |
+
``` bnf
|
| 3038 |
+
fractional:
|
| 3039 |
+
decimal-point digitsₒₚₜ
|
| 3040 |
+
```
|
| 3041 |
+
|
| 3042 |
if `frac_digits()` returns a positive value, or
|
| 3043 |
|
| 3044 |
+
``` bnf
|
| 3045 |
+
value:
|
| 3046 |
+
units
|
| 3047 |
```
|
| 3048 |
|
| 3049 |
+
otherwise. The symbol indicates the character returned by
|
| 3050 |
+
`decimal_point()`. The other symbols are defined as follows:
|
| 3051 |
|
| 3052 |
+
``` bnf
|
| 3053 |
+
units:
|
| 3054 |
+
digits
|
| 3055 |
+
digits thousands-sep units
|
| 3056 |
```
|
| 3057 |
|
| 3058 |
+
``` bnf
|
| 3059 |
+
digits:
|
| 3060 |
+
adigit digitsₒₚₜ
|
| 3061 |
+
```
|
| 3062 |
+
|
| 3063 |
+
In the syntax specification, the symbol is any of the values
|
| 3064 |
+
`ct.widen(c)` for `c` in the range `'0'` through `'9'` (inclusive) and
|
| 3065 |
`ct` is a reference of type `const ctype<charT>&` obtained as described
|
| 3066 |
+
in the definitions of `money_get<>` and `money_put<>`. The symbol is the
|
| 3067 |
+
character returned by `thousands_sep()`. The space character used is the
|
| 3068 |
+
value `ct.widen(' ')`. White space characters are those characters `c`
|
| 3069 |
+
for which `ci.is(space, c)` returns `true`. The number of digits
|
| 3070 |
+
required after the decimal point (if any) is exactly the value returned
|
| 3071 |
+
by `frac_digits()`.
|
| 3072 |
|
| 3073 |
The placement of thousands-separator characters (if any) is determined
|
| 3074 |
by the value returned by `grouping()`, defined identically as the member
|
| 3075 |
`numpunct<>::do_grouping()`.
|
| 3076 |
|
| 3077 |
+
##### Members <a id="locale.moneypunct.members">[[locale.moneypunct.members]]</a>
|
| 3078 |
|
| 3079 |
``` cpp
|
| 3080 |
charT decimal_point() const;
|
| 3081 |
charT thousands_sep() const;
|
| 3082 |
string grouping() const;
|
|
|
|
| 3089 |
```
|
| 3090 |
|
| 3091 |
Each of these functions `F` returns the result of calling the
|
| 3092 |
corresponding virtual member function `do_F()`.
|
| 3093 |
|
| 3094 |
+
##### Virtual functions <a id="locale.moneypunct.virtuals">[[locale.moneypunct.virtuals]]</a>
|
| 3095 |
|
| 3096 |
``` cpp
|
| 3097 |
charT do_decimal_point() const;
|
| 3098 |
```
|
| 3099 |
|
|
|
|
| 3116 |
|
| 3117 |
``` cpp
|
| 3118 |
string_type do_curr_symbol() const;
|
| 3119 |
```
|
| 3120 |
|
| 3121 |
+
*Returns:* A string to use as the currency identifier symbol.
|
| 3122 |
+
|
| 3123 |
+
[*Note 1*: For specializations where the second template parameter is
|
| 3124 |
+
`true`, this is typically four characters long: a three-letter code as
|
| 3125 |
+
specified by ISO 4217 followed by a space. — *end note*]
|
| 3126 |
|
| 3127 |
``` cpp
|
| 3128 |
string_type do_positive_sign() const;
|
| 3129 |
string_type do_negative_sign() const;
|
| 3130 |
```
|
| 3131 |
|
| 3132 |
*Returns:* `do_positive_sign()` returns the string to use to indicate a
|
| 3133 |
+
positive monetary value;[^25] `do_negative_sign()` returns the string to
|
| 3134 |
use to indicate a negative value.
|
| 3135 |
|
| 3136 |
``` cpp
|
| 3137 |
int do_frac_digits() const;
|
| 3138 |
```
|
| 3139 |
|
| 3140 |
*Returns:* The number of digits after the decimal radix separator, if
|
| 3141 |
+
any.[^26]
|
| 3142 |
|
| 3143 |
``` cpp
|
| 3144 |
pattern do_pos_format() const;
|
| 3145 |
pattern do_neg_format() const;
|
| 3146 |
```
|
| 3147 |
|
| 3148 |
*Returns:* The specializations required in
|
| 3149 |
+
[[locale.spec]][[locale.category]], namely
|
| 3150 |
+
|
| 3151 |
+
- `moneypunct<char>`,
|
| 3152 |
+
- `moneypunct<wchar_t>`,
|
| 3153 |
+
- `moneypunct<char, true>`, and
|
| 3154 |
+
- `moneypunct<wchar_t, true>`,
|
| 3155 |
+
|
| 3156 |
+
return an object of type `pattern` initialized to
|
| 3157 |
+
`{ symbol, sign, none, value }`.[^27]
|
| 3158 |
|
| 3159 |
#### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
|
| 3160 |
|
| 3161 |
``` cpp
|
| 3162 |
namespace std {
|
|
|
|
| 3166 |
using pattern = money_base::pattern;
|
| 3167 |
using string_type = basic_string<charT>;
|
| 3168 |
|
| 3169 |
explicit moneypunct_byname(const char*, size_t refs = 0);
|
| 3170 |
explicit moneypunct_byname(const string&, size_t refs = 0);
|
| 3171 |
+
|
| 3172 |
protected:
|
| 3173 |
~moneypunct_byname();
|
| 3174 |
};
|
| 3175 |
}
|
| 3176 |
```
|
|
|
|
| 3195 |
using char_type = charT;
|
| 3196 |
using string_type = basic_string<charT>;
|
| 3197 |
|
| 3198 |
explicit messages(size_t refs = 0);
|
| 3199 |
|
| 3200 |
+
catalog open(const string& fn, const locale&) const;
|
| 3201 |
string_type get(catalog c, int set, int msgid,
|
| 3202 |
const string_type& dfault) const;
|
| 3203 |
void close(catalog c) const;
|
| 3204 |
|
| 3205 |
static locale::id id;
|
| 3206 |
|
| 3207 |
protected:
|
| 3208 |
~messages();
|
| 3209 |
+
virtual catalog do_open(const string&, const locale&) const;
|
| 3210 |
virtual string_type do_get(catalog, int set, int msgid,
|
| 3211 |
const string_type& dfault) const;
|
| 3212 |
virtual void do_close(catalog) const;
|
| 3213 |
};
|
| 3214 |
}
|
| 3215 |
```
|
| 3216 |
|
| 3217 |
Values of type `messages_base::catalog` usable as arguments to members
|
| 3218 |
`get` and `close` can be obtained only by calling member `open`.
|
| 3219 |
|
| 3220 |
+
##### Members <a id="locale.messages.members">[[locale.messages.members]]</a>
|
| 3221 |
|
| 3222 |
``` cpp
|
| 3223 |
+
catalog open(const string& name, const locale& loc) const;
|
| 3224 |
```
|
| 3225 |
|
| 3226 |
*Returns:* `do_open(name, loc)`.
|
| 3227 |
|
| 3228 |
``` cpp
|
|
|
|
| 3235 |
void close(catalog cat) const;
|
| 3236 |
```
|
| 3237 |
|
| 3238 |
*Effects:* Calls `do_close(cat)`.
|
| 3239 |
|
| 3240 |
+
##### Virtual functions <a id="locale.messages.virtuals">[[locale.messages.virtuals]]</a>
|
| 3241 |
|
| 3242 |
``` cpp
|
| 3243 |
+
catalog do_open(const string& name, const locale& loc) const;
|
| 3244 |
```
|
| 3245 |
|
| 3246 |
*Returns:* A value that may be passed to `get()` to retrieve a message
|
| 3247 |
from the message catalog identified by the string `name` according to an
|
| 3248 |
*implementation-defined* mapping. The result can be used until it is
|
|
|
|
| 3255 |
|
| 3256 |
``` cpp
|
| 3257 |
string_type do_get(catalog cat, int set, int msgid, const string_type& dfault) const;
|
| 3258 |
```
|
| 3259 |
|
| 3260 |
+
*Preconditions:* `cat` is a catalog obtained from `open()` and not yet
|
| 3261 |
closed.
|
| 3262 |
|
| 3263 |
*Returns:* A message identified by arguments `set`, `msgid`, and
|
| 3264 |
`dfault`, according to an *implementation-defined* mapping. If no such
|
| 3265 |
message can be found, returns `dfault`.
|
| 3266 |
|
| 3267 |
``` cpp
|
| 3268 |
void do_close(catalog cat) const;
|
| 3269 |
```
|
| 3270 |
|
| 3271 |
+
*Preconditions:* `cat` is a catalog obtained from `open()` and not yet
|
| 3272 |
closed.
|
| 3273 |
|
| 3274 |
*Effects:* Releases unspecified resources associated with `cat`.
|
| 3275 |
|
| 3276 |
*Remarks:* The limit on such resources, if any, is
|
|
|
|
| 3286 |
using catalog = messages_base::catalog;
|
| 3287 |
using string_type = basic_string<charT>;
|
| 3288 |
|
| 3289 |
explicit messages_byname(const char*, size_t refs = 0);
|
| 3290 |
explicit messages_byname(const string&, size_t refs = 0);
|
| 3291 |
+
|
| 3292 |
protected:
|
| 3293 |
~messages_byname();
|
| 3294 |
};
|
| 3295 |
}
|
| 3296 |
```
|
| 3297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3298 |
## C library locales <a id="c.locales">[[c.locales]]</a>
|
| 3299 |
|
| 3300 |
### Header `<clocale>` synopsis <a id="clocale.syn">[[clocale.syn]]</a>
|
| 3301 |
|
| 3302 |
``` cpp
|
|
|
|
| 3317 |
```
|
| 3318 |
|
| 3319 |
The contents and meaning of the header `<clocale>` are the same as the C
|
| 3320 |
standard library header `<locale.h>`.
|
| 3321 |
|
| 3322 |
+
Calls to the function `setlocale` may introduce a data race
|
| 3323 |
+
[[res.on.data.races]] with other calls to `setlocale` or with calls to
|
| 3324 |
+
the functions listed in [[setlocale.data.races]].
|
| 3325 |
|
| 3326 |
+
See also: ISO C 7.11
|
| 3327 |
|
| 3328 |
+
**Table: Potential `setlocale` data races** <a id="setlocale.data.races">[setlocale.data.races]</a>
|
| 3329 |
|
| 3330 |
| | | | | |
|
| 3331 |
| --------- | ---------- | ----------- | ------------ | ---------- |
|
| 3332 |
| `fprintf` | `isprint` | `iswdigit` | `localeconv` | `tolower` |
|
| 3333 |
| `fscanf` | `ispunct` | `iswgraph` | `mblen` | `toupper` |
|
|
|
|
| 3369 |
[facet.num.put.members]: #facet.num.put.members
|
| 3370 |
[facet.num.put.virtuals]: #facet.num.put.virtuals
|
| 3371 |
[facet.numpunct]: #facet.numpunct
|
| 3372 |
[facet.numpunct.members]: #facet.numpunct.members
|
| 3373 |
[facet.numpunct.virtuals]: #facet.numpunct.virtuals
|
|
|
|
| 3374 |
[file.streams]: input.md#file.streams
|
| 3375 |
[ios.base]: input.md#ios.base
|
| 3376 |
[istream.formatted]: input.md#istream.formatted
|
| 3377 |
[istream.formatted.reqmts]: input.md#istream.formatted.reqmts
|
| 3378 |
[iterator.requirements]: iterators.md#iterator.requirements
|
| 3379 |
[lex.charset]: lex.md#lex.charset
|
| 3380 |
[locale]: #locale
|
| 3381 |
[locale.categories]: #locale.categories
|
| 3382 |
[locale.category]: #locale.category
|
| 3383 |
+
[locale.category.facets]: #locale.category.facets
|
| 3384 |
[locale.codecvt]: #locale.codecvt
|
| 3385 |
[locale.codecvt.byname]: #locale.codecvt.byname
|
| 3386 |
+
[locale.codecvt.inout]: #locale.codecvt.inout
|
| 3387 |
[locale.codecvt.members]: #locale.codecvt.members
|
| 3388 |
+
[locale.codecvt.unshift]: #locale.codecvt.unshift
|
| 3389 |
[locale.codecvt.virtuals]: #locale.codecvt.virtuals
|
| 3390 |
[locale.collate]: #locale.collate
|
| 3391 |
[locale.collate.byname]: #locale.collate.byname
|
| 3392 |
[locale.collate.members]: #locale.collate.members
|
| 3393 |
[locale.collate.virtuals]: #locale.collate.virtuals
|
|
|
|
| 3418 |
[locale.nm.put]: #locale.nm.put
|
| 3419 |
[locale.num.get]: #locale.num.get
|
| 3420 |
[locale.numpunct]: #locale.numpunct
|
| 3421 |
[locale.numpunct.byname]: #locale.numpunct.byname
|
| 3422 |
[locale.operators]: #locale.operators
|
| 3423 |
+
[locale.spec]: #locale.spec
|
| 3424 |
[locale.statics]: #locale.statics
|
| 3425 |
[locale.syn]: #locale.syn
|
| 3426 |
[locale.time.get]: #locale.time.get
|
| 3427 |
[locale.time.get.byname]: #locale.time.get.byname
|
| 3428 |
+
[locale.time.get.dogetdate]: #locale.time.get.dogetdate
|
| 3429 |
[locale.time.get.members]: #locale.time.get.members
|
| 3430 |
[locale.time.get.virtuals]: #locale.time.get.virtuals
|
| 3431 |
[locale.time.put]: #locale.time.put
|
| 3432 |
[locale.time.put.byname]: #locale.time.put.byname
|
| 3433 |
[locale.time.put.members]: #locale.time.put.members
|
| 3434 |
[locale.time.put.virtuals]: #locale.time.put.virtuals
|
| 3435 |
[locale.types]: #locale.types
|
| 3436 |
[locales]: #locales
|
| 3437 |
[localization]: #localization
|
| 3438 |
[localization.general]: #localization.general
|
| 3439 |
+
[localization.summary]: #localization.summary
|
| 3440 |
[ostream.formatted.reqmts]: input.md#ostream.formatted.reqmts
|
| 3441 |
[res.on.data.races]: library.md#res.on.data.races
|
| 3442 |
[sequence.reqmts]: containers.md#sequence.reqmts
|
| 3443 |
+
[setlocale.data.races]: #setlocale.data.races
|
| 3444 |
+
[tab:locale.category.facets]: #tab:locale.category.facets
|
| 3445 |
+
[tab:locale.spec]: #tab:locale.spec
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3446 |
[vector]: containers.md#vector
|
| 3447 |
|
| 3448 |
[^1]: In this subclause, the type name `struct tm` is an incomplete type
|
| 3449 |
that is defined in `<ctime>`.
|
| 3450 |
|
| 3451 |
+
[^2]: Note that in the call to `put`, the stream is implicitly converted
|
| 3452 |
to an `ostreambuf_iterator<charT, traits>`.
|
| 3453 |
|
| 3454 |
[^3]: This is a complete list of requirements; there are no other
|
| 3455 |
requirements. Thus, a facet class need not have a public copy
|
| 3456 |
constructor, assignment, default constructor, destructor, etc.
|
| 3457 |
|
| 3458 |
[^4]: When used in a loop, it is faster to cache the `ctype<>` facet and
|
| 3459 |
use it directly, or use the vector form of `ctype<>::is`.
|
| 3460 |
|
| 3461 |
[^5]: The char argument of `do_widen` is intended to accept values
|
| 3462 |
+
derived from *character-literal*s for conversion to the locale’s
|
| 3463 |
encoding.
|
| 3464 |
|
| 3465 |
[^6]: In other words, the transformed character is not a member of any
|
| 3466 |
character classification that `c` is not also a member of.
|
| 3467 |
|
|
|
|
| 3509 |
vendors do.
|
| 3510 |
|
| 3511 |
[^18]: Interpretation of the `modifier` argument is
|
| 3512 |
implementation-defined, but should follow POSIX conventions.
|
| 3513 |
|
| 3514 |
+
[^19]: Implementations should refer to other standards such as POSIX for
|
| 3515 |
+
these definitions.
|
| 3516 |
|
| 3517 |
[^20]: The semantics here are different from `ct.narrow`.
|
| 3518 |
|
| 3519 |
[^21]: An array of `char`, rather than an array of `part`, is specified
|
| 3520 |
for `pattern::field` purely for efficiency.
|
|
|
|
| 3523 |
|
| 3524 |
[^23]: In common U.S. locales this is `’,’`.
|
| 3525 |
|
| 3526 |
[^24]: To specify grouping by 3s, the value is `"\003"` *not* `"3"`.
|
| 3527 |
|
| 3528 |
+
[^25]: This is usually the empty string.
|
|
|
|
|
|
|
| 3529 |
|
| 3530 |
+
[^26]: In common U.S. locales, this is 2.
|
| 3531 |
|
| 3532 |
+
[^27]: Note that the international symbol returned by `do_curr_symbol()`
|
|
|
|
|
|
|
| 3533 |
usually contains a space, itself; for example, `"USD "`.
|