SourcePro® 2023.1 |
SourcePro® API Reference Guide |
Implements the RWLocale interface, and encapsulates the C++ Standard Library locale. More...
#include <rw/tools/ansilocale.h>
Public Types | |
typedef std::money_base::pattern | money_pattern |
enum | part { none, space, symbol, sign, value } |
Public Types inherited from RWLocale | |
enum | CurrSymbol { NONE, LOCAL, INTL } |
Public Member Functions | |
RWAnsiLocale (const RWAnsiLocale &) | |
RWAnsiLocale () | |
RWAnsiLocale (const char *localeName) | |
RWAnsiLocale (const std::locale &) | |
RWAnsiLocale (RWAnsiLocale &&locale) | |
virtual | ~RWAnsiLocale () |
virtual RWCString | asString (long val) const |
virtual RWCString | asString (unsigned long val) const |
virtual RWCString | asString (double val, int precision=6, bool showpoint=0) const |
virtual RWCString | asString (long double val, int precision=10, bool showpoint=0) const |
virtual RWCString | asString (const struct tm *ptm, char format, const RWZone &zone=RWZone::local()) const |
RWCString | asString (const struct tm *ptm, const char *format, const RWZone &zone=RWZone::local()) const |
virtual const RWCString & | currency_symbol () const |
virtual const RWCString & | decimal_point () const |
virtual char | frac_digits () const |
virtual const RWCString & | grouping () const |
virtual const RWCString & | int_curr_symbol () const |
virtual char | int_frac_digits () const |
virtual money_pattern | int_neg_format () const |
virtual money_pattern | int_pos_format () const |
virtual const RWCString & | locale_name () const |
virtual const RWCString & | mon_decimal_point () const |
virtual const RWCString & | mon_grouping () const |
virtual const RWCString & | mon_thousands_sep () const |
virtual RWCString | moneyAsString (double value, RWAnsiLocale::CurrSymbol=LOCAL) const |
virtual int | monthIndex (const RWCString &month) const |
virtual char | n_cs_precedes () const |
virtual char | n_sep_by_space () const |
virtual char | n_sign_posn () const |
virtual money_pattern | neg_format () const |
virtual const RWCString & | negative_sign () const |
RWAnsiLocale & | operator= (const RWAnsiLocale &) |
RWAnsiLocale & | operator= (RWAnsiLocale &&locale) |
virtual char | p_cs_precedes () const |
virtual char | p_sep_by_space () const |
virtual char | p_sign_posn () const |
virtual money_pattern | pos_format () const |
virtual const RWCString & | positive_sign () const |
virtual std::locale * | std () |
virtual bool | stringToDate (const RWCString &date, struct tm *) const |
virtual bool | stringToMoney (const RWCString &, double *, RWAnsiLocale::CurrSymbol=LOCAL) const |
virtual bool | stringToNum (const RWCString &value, double *) const |
virtual bool | stringToNum (const RWCString &value, long *) const |
virtual bool | stringToNum (const RWCString &value, unsigned long *) const |
virtual bool | stringToTime (const RWCString &time, struct tm *) const |
void | swap (RWAnsiLocale &rhs) |
virtual const RWCString & | thousands_sep () const |
virtual int | weekdayIndex (const RWCString &day) const |
Public Member Functions inherited from RWLocale | |
RWCString | asString (const struct tm *tmbuf, const char *format, const RWZone &zone=RWZone::local()) const |
const RWLocale * | imbue (std::ios &stream) const |
Additional Inherited Members | |
Static Public Member Functions inherited from RWLocale | |
static const RWLocale * | defaultLocale () |
static const RWLocale & | global () |
static const RWLocale * | global (const RWLocale *loc) |
static const RWLocale & | of (std::ios &stream) |
static const RWLocale * | unimbue (std::ios &stream) |
RWAnsiLocale implements the RWLocale interface. It encapsulates the C++ Standard Library locale, std::locale and adds functionality for date and time conversions. The C++ Standard Library std::locale provides localized representations of dates, numbers, and currencies. RWAnsiLocale offers a simple interface to std::locale so you can avoid working directly with std::locale facets. Additionally, RWAnsiLocale provides flexible conversions of strings to dates and times. While the C++ Standard Library std::locale accepts dates and times only in formats defined by the C++ Standard Library function std::strftime(), RWAnsiLocale accepts multiple date and time formats.
There are three ways to use an RWAnsiLocale object:
For a description of the static members of the RWLocale interface that operate on objects of type RWAnsiLocale, see the RWLocale class description.
<locale.h>
.Program output:
Actual output will depend on the time the example is run, and on the platform.
typedef std::money_base::pattern RWAnsiLocale::money_pattern |
Typedef for a locale-specific rule for formatting monetary outputs.
enum RWAnsiLocale::part |
RWAnsiLocale::RWAnsiLocale | ( | const RWAnsiLocale & | ) |
Copy constructor.
RWAnsiLocale::RWAnsiLocale | ( | ) |
Constructs an RWAnsiLocale object with locale information extracted from the current C++ Standard Library global locale.
RWAnsiLocale::RWAnsiLocale | ( | const char * | localeName | ) |
Constructs an RWAnsiLocale object using the locale name localeName.
Valid values for localeName are NULL
, ""
, "C"
, and any value that is accepted by std::locale.
If the value for localeName is NULL
, the required locale information is extracted from the current C++ Standard Library global locale. Otherwise, localeName is used to construct a C++ Standard Library std::locale object to be queried for the necessary locale information.
std::runtime_error | If the locale name localeName is not recognized by std::locale. |
RWAnsiLocale::RWAnsiLocale | ( | const std::locale & | ) |
Constructs an RWAnsiLocale object from a C++ Standard Library std::locale.
|
virtual |
Virtual destructor.
RWAnsiLocale::RWAnsiLocale | ( | RWAnsiLocale && | locale | ) |
Move constructor. The constructed instance takes ownership of the data owned by locale.
|
virtual |
Converts the number val to a string (for example, "3,456"
).
Implements RWLocale.
|
virtual |
Converts the number val to a string (for example, "3,456"
).
Implements RWLocale.
|
virtual |
Converts the double
val to a string. The parameter precision is the number of digits to place after the decimal separator. If showpoint is true
, the decimal separator appears regardless of the precision.
Implements RWLocale.
|
virtual |
Converts the value of val to a string. The parameter precision is the number of digits to place after the decimal separator. If showpoint is true
, the decimal separator appears regardless of the precision.
Implements RWLocale.
|
virtual |
Converts components of the ptm object to a string, according to the format character. The meanings assigned to the format character are identical to those used in the C++ Standard Library function std::strftime(). The members of ptm are assumed to be set consistently.
See http://en.cppreference.com/w/cpp/chrono/c/strftime for a summary of std::strftime() formatting characters.
Implements RWLocale.
RWCString RWAnsiLocale::asString | ( | const struct tm * | ptm, |
const char * | format, | ||
const RWZone & | zone = RWZone::local() |
||
) | const |
Converts components of the tm struct
object ptm to a string, according to the format string. Each format character in the format string must be preceded by %
. Any characters not preceded by %
are treated as ordinary characters which are returned unchanged. You may represent the special character %
with %%
. The meanings assigned to the format character are identical to those used in the C++ Standard Library function std::strftime(). The members of ptm are assumed to be set consistently.
See http://en.cppreference.com/w/cpp/chrono/c/strftime for a summary of std::strftime() formatting characters.
|
virtual |
Returns a string to use as the local currency symbol.
Implements RWLocale.
|
virtual |
Returns a string to use as the numerical decimal separator.
Implements RWLocale.
|
virtual |
Returns the number of digits in the fractional part of the monetary representation.
Implements RWLocale.
|
virtual |
Returns a string identifying the number of digits to be included in a numerical group. A group is simply the digits between adjacent thousand's separators.
Each character of the string is an integer that specifies the number of digits in a group, starting with the right most group.
0
, the previous element is used repeatedly.CHAR_MAX
, no further grouping is performed.Example
Implements RWLocale.
|
virtual |
|
virtual |
Returns the number of digits in the fractional part of a particular national monetary representation.
Implements RWLocale.
|
virtual |
Returns a money_pattern object specifying the location of the various syntactic elements in an international monetary representation. The restrictions listed for pos_format() and neg_format() apply.
|
virtual |
Returns a money_pattern object specifying the location of the various syntactic elements in an international monetary representation. The restrictions listed for pos_format() and neg_format() apply.
|
virtual |
Returns the name of the encapsulated std::locale.
Implements RWLocale.
|
virtual |
Returns a string to use as the monetary decimal separator.
Implements RWLocale.
|
virtual |
Returns a string identifying the number of digits to be included in a numerical group. A group is simply the digits between adjacent thousand's separators.
Each character of the string is an integer that specifies the number of digits in a group, starting with the right most group.
0
, the previous element is used repeatedly.CHAR_MAX
, no further grouping is performed.See the example in the grouping() description.
Implements RWLocale.
|
virtual |
Returns a string to use as the monetary thousands separator.
Implements RWLocale.
|
virtual |
Returns a string containing the value parameter formatted according to monetary conventions for the locale. The value parameter is assumed to contain an integer representing the number of units of currency (for example, moneyAsString(1000., RWAnsiLocale::cs_local)
in a US locale would yield "$10.00"
). The CurrSymbol
parameter determines which currency symbol should be applied if any – the local (for example, "$"
) or international (for example, "USD"
), or none.
Implements RWLocale.
|
virtual |
Interprets month as a full or abbreviated month name, returning values 1 through 12 to represent (respectively) January through December, or 0 for an error. Ignores leading white space.
Implements RWLocale.
|
virtual |
Gets the negative currency symbol location.
Implements RWLocale.
|
virtual |
Gets the space separating the negative sign from its number, if any.
Implements RWLocale.
|
virtual |
Gets the negative sign position.
Implements RWLocale.
|
virtual |
Returns a money_pattern object specifying the location of the various syntactic elements in a monetary representation. The enumeration values symbol, sign, and value appear exactly once in this pattern, with the remaining location taken by either none or space. none never occupies the first position in the money_pattern and space never occupies the first or last position. Beyond these restrictions, elements may appear in any order.
|
virtual |
Returns a string to use as the negative sign for a monetary quantity.
Implements RWLocale.
RWAnsiLocale& RWAnsiLocale::operator= | ( | const RWAnsiLocale & | ) |
Assignment operator.
RWAnsiLocale& RWAnsiLocale::operator= | ( | RWAnsiLocale && | locale | ) |
Move assignment. Self takes ownership of the data owned by locale.
|
virtual |
Gets the positive currency symbol location.
Implements RWLocale.
|
virtual |
Gets the space separating the positive sign from its number, if any.
Implements RWLocale.
|
virtual |
Gets the positive sign position.
Implements RWLocale.
|
virtual |
Returns a money_pattern object specifying the location of the various syntactic elements in a monetary representation. The enumeration values symbol, sign, and value appear exactly once in this pattern, with the remaining location taken by either none or space. none never occupies the first position in the money_pattern and space never occupies the first or last position. Beyond these restrictions, elements may appear in any order.
|
virtual |
Returns a string to use as the positive sign for a monetary quantity.
Implements RWLocale.
|
virtual |
Returns a pointer to the encapsulated std::locale.
|
virtual |
Interprets date as a date, and extracts the month, day, and year components to the tm
parameter. Returns true
for a valid date, false
otherwise. If it returns false
, the struct
tm
object is untouched; otherwise it sets the tm_mday
, tm_mon
, and tm_year
members. The expected format for the date string is the one specified by the std::strftime() character x
in the current locale.
An example of a valid string in en_US
locale is 09/12/1990
.
Implements RWLocale.
|
virtual |
Interprets the RWCString parameter value as a monetary value. The currency symbol, if any, is ignored. Negative values may be specified by the negation symbol or by enclosing parentheses. Digit group separators are optional; if present they are checked. Returns true
for a valid monetary value, false
for an error. If it returns false
, the double*
parameter value is untouched; otherwise it is set to the integral number of monetary units entered (for example, cents in a U.S. locale).
Implements RWLocale.
|
virtual |
Interprets value as a floating point number, by reading to the first non-numeric or non-punctuation character, then converting. Spaces are allowed before and after the (optional) sign, and at the end. Digit group separators are allowed in the integer portion. Returns true
for a valid number, false
for an error. If it returns false
, the double*
parameter is untouched. All valid numeric strings are accepted; all others are rejected. The following are examples of valid numeric strings in an English-speaking locale:
Implements RWLocale.
|
virtual |
Interprets value as an integer, by reading to the first non-numeric or non-punctuation character, then converting. Spaces are allowed before and after the (optional) sign, and at the end. Digit group separators are allowed. Returns true
for a valid integer, false
for an error. If it returns false
, the long*
parameter is untouched. All valid numeric strings are accepted; all others are rejected. The following are examples of valid integral strings in an English-speaking locale:
Implements RWLocale.
|
virtual |
Interprets value as an integer, by reading to the first non-numeric or non-punctuation character, then converting. Spaces are allowed before and after the (optional) sign, and at the end. Digit group separators are allowed. Returns true
for a valid integer, false
for an error. If it returns false
, the long*
parameter is untouched. All valid numeric strings are accepted; all others are rejected.
Implements RWLocale.
|
virtual |
Interprets time as a time, with hours, minutes, and optional seconds. If the hour is in the range [1...12], the local equivalent of "AM" or "PM" is allowed. Returns true
for a valid time string, false
for an error. If it returns false
, the tm
object is untouched; otherwise it sets the tm_hour
, tm_min
, and tm_sec
members. The expected format for the date string is the one specified by std::strftime() character X
(capital X) in the current locale.
An example of a valid string in en_US
locale is 10
:30:05.
Implements RWLocale.
void RWAnsiLocale::swap | ( | RWAnsiLocale & | rhs | ) |
Swaps the data owned by self with the data owned by rhs.
|
virtual |
Returns a char
to use as the numerical thousands separator.
Implements RWLocale.
Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |