rwsf::LocaleSnapshotrwsf::Locale
#include rwsf/core/LocaleSnapshot.h
The class rwsf::LocaleSnapshot implements the rwsf::Locale interface using Standard C Library facilities. To use it, the program creates an rwsf::LocaleSnapshot instance. The constructor of the instance queries the program's environment (using Standard C Library functions such as localeconv(), strftime(), and, if available, vendor specific library functions) to determine the formatting conventions in effect at the moment of instantiation. When done, the locale can then be switched and another instance of rwsf::LocaleSnapshot created.
By creating multiple instances of rwsf::LocaleSnapshot, your program can have more than one locale active at the same time, something that is difficult to do with the Standard C Library facilities.
Class rwsf::LocaleSnapshot contains a set of public data members initialized by its constructor with information extracted from its execution environment.
Note
rwsf::LocaleSnapshot does not encapsulate character set, collation, or message information.
For a description of the static members of the rwsf::Locale interface that operate on objects of type rwsf::LocaleSnapshot, see the rwsf::Locale class description.
LocaleSnapshot(const char * localeName = 0);
Constructs an rwsf::Locale object by extracting formats from the global locale environment. It uses the Standard C Library function setlocale() to set the named locale, and then restores the previous global locale after formats have been extracted. If localeName is 0, it simply uses the current locale. The most useful locale name is the empty string, "", which is a synonym for the user's chosen locale (usually specified by the environment variable LANG).
std::string asString(const struct tm * tmbuf, const char * format, const rwsf::TimeZone & r = rwsf::TimeZone::local()) const;
Reimplements method in rwsf::Locale
Base class documentation:
Converts components of the structtm object 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 pre-1999 Standard C Library function strftime(). The members of structtm should be set consistently. See Table 3 for a summary of strftime() formatting characters.
Note
This function is not virtual in order to maintain link-compatibility with the previous version of the library.
std::string asString(long) const;
Implements method in rwsf::Locale
Base class documentation:
Converts the number to a string (For example, "\c 3,456").
std::string asString(unsigned long) const;
Implements method in rwsf::Locale
Base class documentation:
Converts the number to a string (For example, "\c 3,456").
std::string asString(double f, int precision = 6, bool showpoint = 0) const;
Implements method in rwsf::Locale
Base class documentation:
Converts the double to a string. digits is the number of digits to place after the decimal separator. If sep is true, the decimal separator appears regardless of the setting of digits. The default is false.
std::string asString(const struct tm * tmbuf, char format, const rwsf::TimeZone & = rwsf::TimeZone::local()) const;
Implements method in rwsf::Locale
Base class documentation:
Converts components of the structtm object to a string, according to the format character. The meanings assigned to the format character are identical to those used in the pre-1999 Standard C Library function strftime(). The members of structtm should be set consistently. See Table 3 for a summary of strftime() formatting characters.
const std::string & currency_symbol() const;
Returns a string to use as the currency symbol for this locale.
const std::string & decimal_point() const;
Returns a string to use as the numerical decimal separator.
const std::string & grouping() const;
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.
const std::string & int_curr_symbol() const;
Returns a string to use as the international currency symbol.
const std::string & locale_name() const;
Returns the name of the encapsulated std::locale.
const std::string & mon_decimal_point() const;
Returns a string to use as the monetary decimal separator.
const std::string & mon_grouping() const;
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.
If the value is equal to CHAR_MAX, no further grouping is to be performed.
See Example under grouping().
const std::string & mon_thousands_sep() const;
Returns a string to use as the monetary thousands separator.
std::string moneyAsString(double, Locale::CurrSymbol = LOCAL) const;
Implements method in rwsf::Locale
Base class documentation:
Returns a string containing the double argument formatted according to monetary conventions for the locale. The double argument should contain an integer representing the number of units of currency (for example, moneyAsString(1000., rwsf::Locale::LOCAL) in a US locale would yield "\c $10.00"). The CurrSymbol argument determines whether to apply the local currency symbol.
int monthIndex(const std::string &) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets its argument 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.
const std::string & negative_sign() const;
Returns a string to use as the negative sign.
const std::string & positive_sign() const;
Returns a string to use as the positive sign.
bool stringToDate(const std::string &, struct tm *) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets the std::string as a date, and extracts the month, day, and year components to the tm argument. It returns true for a valid date, false otherwise. If it returns false, the structtm argument is untouched; otherwise it sets the tm_mday, tm_mon, and tm_year members. If the date is entered as three numbers, the order expected is the same as that produced by pre-1999 strftime(). Note that this function cannot reject all invalid date strings.
The following are examples of valid date strings in an English-speaking locale:
"Jan 9, 62" "1/9/62" "January 9 1962" "09Jan62" "010962"
bool stringToMoney(const std::string &, double *, Locale::CurrSymbol = LOCAL) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets the std::string argument 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* argument is untouched; otherwise it is set to the integral number of monetary units entered (For example, cents, in a U.S. locale).
bool stringToNum(const std::string &, double *) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets the std::string argument as a floating point number. 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* argument 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:
"1" " -02. " ".3" "1234.56" "1e10" "+ 19,876.2E+20"
bool stringToNum(const std::string &, long *) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets the std::string argument as an integer. 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* argument 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:
"1" " -02. " "+ 1,234" "1234545" "1,234,567"
bool stringToNum(const std::string &, unsigned long *) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets the std::string argument as an integer. Allows spaces before and after the (optional) sign, and at the end. Allows digit group separators. Returns true for a valid integer, false for an error. If it returns false, the long* argument is untouched. All valid numeric strings are accepted; all others are rejected.
bool stringToTime(const std::string &, struct tm *) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets the std::string argument as a time, with hour, minute, and optional second. 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 argument is untouched; otherwise it sets the tm_hour, tm_min, and tm_sec members. Note that this function cannot reject all invalid time strings. The following are examples of valid time strings in an English-speaking locale:
"1:10 AM" "13:45:30" "12.30.45pm" "PM 3:15" "1430"
const std::string & thousands_sep() const;
Returns a string to use as the numerical thousands separator.
int weekdayIndex(const std::string &) const;
Implements method in rwsf::Locale
Base class documentation:
Interprets its argument as a full or abbreviated weekday name, returning values 1 through 7 to represent (respectively) Monday through Sunday, or 0 for an error.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.