Creates an snapshot of a locale by querying the program's environment to determine the formatting conventions in effect at the moment of instantiation.
More...
|
| RWLocaleSnapshot (const char *localeName=0) |
|
RWCString | asString (const struct tm *t, const char *fmt, const RWZone &z=RWZone::local()) const |
|
virtual RWCString | asString (const struct tm *, char, const RWZone &=RWZone::local()) const |
|
virtual RWCString | asString (long) const |
|
virtual RWCString | asString (unsigned long) const |
|
virtual RWCString | asString (double, int=6, bool=0) const |
|
virtual RWCString | asString (long double, int=10, bool=0) const |
|
virtual const RWCString & | currency_symbol () const |
|
virtual const RWCString & | decimal_point () const |
|
virtual const RWCString & | grouping () const |
|
virtual const RWCString & | int_curr_symbol () 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, RWLocaleSnapshot::CurrSymbol=LOCAL) const |
|
virtual int | monthIndex (const RWCString &) const |
|
virtual const RWCString & | negative_sign () const |
|
virtual const RWCString & | positive_sign () const |
|
virtual bool | stringToDate (const RWCString &, struct tm *) const |
|
virtual bool | stringToMoney (const RWCString &, double *, RWLocaleSnapshot::CurrSymbol=LOCAL) const |
|
virtual bool | stringToNum (const RWCString &, double *) const |
|
virtual bool | stringToNum (const RWCString &, long *) const |
|
virtual bool | stringToNum (const RWCString &, unsigned long *) const |
|
virtual bool | stringToTime (const RWCString &, struct tm *) const |
|
virtual const RWCString & | thousands_sep () const |
|
virtual int | weekdayIndex (const RWCString &) const |
|
RWCString | asString (const struct tm *tmbuf, const char *format, const RWZone &zone=RWZone::local()) const |
|
const RWLocale * | imbue (std::ios &stream) const |
|
The class RWLocaleSnapshot implements the RWLocale interface using Standard C Library facilities. To use it, the program creates an RWLocaleSnapshot 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 RWLocaleSnapshot created.
By creating multiple instances of RWLocaleSnapshot, 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.
- Note
- RWLocaleSnapshot does not encapsulate character set, collation, or message information.
Class RWLocaleSnapshot contains a set of public data members initialized by its constructor with information extracted from its execution environment.
For a description of the static members of the RWLocale interface that operate on objects of type RWLocaleSnapshot, see the RWLocale class description.
- Synopsis
#include <locale.h>
#include <rw/locale.h>
- Persistence
- None
- Example
-
- Note
- To ensure that the asString() methods in this example correctly format the output, you must first install on your system any locale you request before invoking RWLocaleSnapshot().
-
#include <rw/tools/datetime.h>
#include <rw/locale.h>
#include <rw/cstring.h>
#if defined(_WIN32)
#define FRENCH_LOCALE_NAME "french"
#elif defined(__HP_aCC)
#define FRENCH_LOCALE_NAME "fr_FR.utf8"
#else
#define FRENCH_LOCALE_NAME "fr_FR"
#endif
int main()
{
std::cout << frenchDate << ((d.isValid()) ? " IS " : " IS NOT ")
<< "a valid date (french locale)." << std::endl << std::endl;
std::cout << frenchDate;
std::cout << ((bad.
isValid() && bad == d) ?
" IS " :
" IS NOT ")
<< "a valid date (default locale)." << std::endl << std::endl;
std::cout << americanDate;
std::cout << ((bad.
isValid() && bad == d) ?
" IS " :
" IS NOT ")
<< "a valid date (french locale)." << std::endl << std::endl;
std::cout << d << std::endl;
std::cout << d.asString('x') << std::endl;
std::cout << d.asString('x', french) << std::endl;
return 0;
}
Program output:
10 Juin 2025 IS a valid date (french locale).
10 Juin 2025 IS NOT a valid date (default locale).
10 June 2025 IS a valid date (french locale).
Tue Jun 10 00:00:00 2025
06/10/25
10.06.2025
virtual const RWCString& RWLocaleSnapshot::mon_grouping |
( |
| ) |
const |
|
inlinevirtual |
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 0, the previous element is used repeatedly for the remainder of the digits.
If the value is equal to CHAR_MAX
, no further grouping is to be performed.
See Example under grouping().
Implements RWLocale.