142 lines
5.5 KiB
Markdown
142 lines
5.5 KiB
Markdown
[locale.money.get.virtuals]
|
||
|
||
# 28 Text processing library [[text]](./#text)
|
||
|
||
## 28.3 Localization library [[localization]](localization#locale.money.get.virtuals)
|
||
|
||
### 28.3.4 Standard locale categories [[locale.categories]](locale.categories#locale.money.get.virtuals)
|
||
|
||
#### 28.3.4.7 The monetary category [[category.monetary]](category.monetary#locale.money.get.virtuals)
|
||
|
||
#### 28.3.4.7.2 Class template money_get [[locale.money.get]](locale.money.get#virtuals)
|
||
|
||
#### 28.3.4.7.2.3 Virtual functions [locale.money.get.virtuals]
|
||
|
||
[ð](#lib:money_get,do_get)
|
||
|
||
`iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
|
||
ios_base::iostate& err, long double& units) const;
|
||
iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
|
||
ios_base::iostate& err, string_type& digits) const;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L4191)
|
||
|
||
*Effects*: Reads characters from s to parse and construct a monetary value
|
||
according to the format specified by
|
||
a moneypunct<charT, Intl> facet reference mp and the character mapping specified by
|
||
a ctype<charT> facet reference ct obtained from the locale returned by str.getloc(), andstr.flags()[.](#1.sentence-1)
|
||
|
||
If a valid sequence is recognized, does not change err;
|
||
otherwise, sets err to (err | str.failbit), or(err | str.failbit | str.eofbit) if no more characters are available,
|
||
and does not change units or digits[.](#1.sentence-2)
|
||
|
||
Uses the pattern returned by mp.neg_format() to parse all values[.](#1.sentence-3)
|
||
|
||
The result is returned as an integral value stored in units or as a sequence of digits possibly preceded by a minus sign
|
||
(as produced by ct.widen(c) where c is '-' or
|
||
in the range from '0' through '9' (inclusive))
|
||
stored in digits[.](#1.sentence-4)
|
||
|
||
[*Example [1](#example-1)*:
|
||
|
||
The sequence $1,056.23 in a common United States locale would yield,
|
||
for units, 105623, or,
|
||
for digits, "105623"[.](#1.sentence-5)
|
||
|
||
â *end example*]
|
||
|
||
If mp.grouping() indicates that no thousands separators are permitted,
|
||
any such characters are not read, and
|
||
parsing is terminated at the point where they first appear[.](#1.sentence-6)
|
||
|
||
Otherwise, thousands separators are optional;
|
||
if present, they are checked for correct placement only after
|
||
all format components have been read[.](#1.sentence-7)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L4223)
|
||
|
||
Where money_base::space or money_base::none appears as the last element in the format pattern,
|
||
no whitespace is consumed[.](#2.sentence-1)
|
||
|
||
Otherwise, where money_base::space appears in any of
|
||
the initial elements of the format pattern,
|
||
at least one whitespace character is required[.](#2.sentence-2)
|
||
|
||
Where money_base::none appears
|
||
in any of the initial elements of the format pattern,
|
||
whitespace is allowed but not required[.](#2.sentence-3)
|
||
|
||
If (str.flags() & str.showbase) is false,
|
||
the currency symbol is optional and
|
||
is consumed only if other characters are needed to complete the format;
|
||
otherwise, the currency symbol is required[.](#2.sentence-4)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L4238)
|
||
|
||
If the first character (if any) in
|
||
the string pos returned by mp.positive_sign() or
|
||
the string neg returned by mp.negative_sign() is recognized in the position indicated by sign in the format pattern,
|
||
it is consumed and
|
||
any remaining characters in the string are required
|
||
after all the other format components[.](#3.sentence-1)
|
||
|
||
[*Example [2](#example-2)*:
|
||
|
||
If showbase is off,
|
||
then for a neg value of "()" and
|
||
a currency symbol of "L",
|
||
in "(100 L)" the "L" is consumed;
|
||
but if neg is "-",
|
||
the "L" in "-100 L" is not consumed[.](#3.sentence-2)
|
||
|
||
â *end example*]
|
||
|
||
If pos or neg is empty,
|
||
the sign component is optional, and
|
||
if no sign is detected,
|
||
the result is given the sign that corresponds to the source of the empty string[.](#3.sentence-3)
|
||
|
||
Otherwise,
|
||
the character in the indicated position must match
|
||
the first character of pos or neg,
|
||
and the result is given the corresponding sign[.](#3.sentence-4)
|
||
|
||
If the first character of pos is equal to
|
||
the first character of neg,
|
||
or if both strings are empty,
|
||
the result is given a positive sign[.](#3.sentence-5)
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L4267)
|
||
|
||
Digits in the numeric monetary component are extracted and
|
||
placed in digits, or into a character buffer buf1 for conversion to produce a value for units,
|
||
in the order in which they appear,
|
||
preceded by a minus sign if and only if the result is negative[.](#4.sentence-1)
|
||
|
||
The value units is produced as if by[229](#footnote-229 "The semantics here are different from ct.narrow.")for (int i = 0; i < n; ++i) buf2[i] = src[find(atoms, atoms + sizeof(src), buf1[i]) - atoms];
|
||
buf2[n] = 0;
|
||
sscanf(buf2, "%Lf", &units); where n is the number of characters placed in buf1,buf2 is a character buffer, and
|
||
the values src and atoms are defined as if bystatic const char src[] = "0123456789-";
|
||
charT atoms[sizeof(src)];
|
||
ct.widen(src, src + sizeof(src) - 1, atoms);
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L4292)
|
||
|
||
*Returns*: An iterator pointing immediately beyond
|
||
the last character recognized as part of a valid monetary quantity[.](#5.sentence-1)
|
||
|
||
[229)](#footnote-229)[229)](#footnoteref-229)
|
||
|
||
The semantics here are different from ct.narrow[.](#footnote-229.sentence-1)
|