SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Public Attributes
RWLocaleSnapshot Class Reference

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...

#include <rw/tools/localesnapshot.h>

Inheritance diagram for RWLocaleSnapshot:
RWLocale

Public Member Functions

 RWLocaleSnapshot ()
 
 RWLocaleSnapshot (const char *localeName)
 
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 RWCStringcurrency_symbol () const
 
virtual const RWCStringdecimal_point () const
 
virtual const RWCStringgrouping () const
 
virtual const RWCStringint_curr_symbol () const
 
virtual const RWCStringlocale_name () const
 
virtual const RWCStringmon_decimal_point () const
 
virtual const RWCStringmon_grouping () const
 
virtual const RWCStringmon_thousands_sep () const
 
virtual RWCString moneyAsString (double, RWLocaleSnapshot::CurrSymbol=LOCAL) const
 
virtual int monthIndex (const RWCString &) const
 
virtual const RWCStringnegative_sign () const
 
virtual const RWCStringpositive_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 RWCStringthousands_sep () const
 
virtual int weekdayIndex (const RWCString &) const
 
- Public Member Functions inherited from RWLocale
RWCString asString (const struct tm *tmbuf, const char *format, const RWZone &zone=RWZone::local()) const
 
const RWLocaleimbue (std::ios &stream) const
 

Public Attributes

RWCString currency_symbol_
 
RWCString decimal_point_
 
char frac_digits_
 
RWCString grouping_
 
RWCString int_curr_symbol_
 
char int_frac_digits_
 
RWCString mon_decimal_point_
 
RWCString mon_grouping_
 
RWCString mon_thousands_sep_
 
char n_cs_precedes_
 
char n_sep_by_space_
 
char n_sign_posn_
 
RWCString negative_sign_
 
char p_cs_precedes_
 
char p_sep_by_space_
 
char p_sign_posn_
 
RWCString positive_sign_
 
RWCString thousands_sep_
 

Additional Inherited Members

- Public Types inherited from RWLocale
enum  CurrSymbol { NONE, LOCAL, INTL }
 
- Static Public Member Functions inherited from RWLocale
static const RWLocaledefaultLocale ()
 
static const RWLocaleglobal ()
 
static const RWLocaleglobal (const RWLocale *loc)
 
static const RWLocaleof (std::ios &stream)
 
static const RWLocaleunimbue (std::ios &stream)
 

Detailed Description

The class RWLocaleSnapshot implements the RWLocale interface using C Standard Library facilities. To use it, the program creates an RWLocaleSnapshot instance. The constructor of the instance queries the program's environment (using C Standard 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 C Standard 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>
RWLocaleSnapshot ourLocale(""); // encapsulate user's formats
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)
// french should be a valid French locale name on Windows
#define FRENCH_LOCALE_NAME "french"
#elif defined(__HP_aCC)
#define FRENCH_LOCALE_NAME "fr_FR.utf8"
#else
// fr_FR should be a valid French locale name on most Unices
#define FRENCH_LOCALE_NAME "fr_FR"
#endif
int main()
{
RWLocaleSnapshot french(FRENCH_LOCALE_NAME); // or vendor-specific
RWCString americanDate ("10 June 2025");
RWCString frenchDate ("10 Juin 2025");
RWDateTime d(frenchDate, RWDateTime::setDate, french); // OK
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;
bad = RWDateTime(americanDate, RWDateTime::setDate, french);
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

Constructor & Destructor Documentation

RWLocaleSnapshot::RWLocaleSnapshot ( )

Constructs an RWLocale object by extracting formats from the current locale environment.

RWLocaleSnapshot::RWLocaleSnapshot ( const char *  localeName)

Constructs an RWLocale object by extracting formats from the global locale environment. It uses the C++ Standard Library function std::setlocale() to set the named locale, and then restores the previous global locale after formats have been extracted. If localeName is 0, it 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).

Member Function Documentation

RWCString RWLocaleSnapshot::asString ( const struct tm *  t,
const char *  fmt,
const RWZone z = RWZone::local() 
) const

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.
virtual RWCString RWLocaleSnapshot::asString ( const struct tm *  ,
char  ,
const RWZone = RWZone::local() 
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual RWCString RWLocaleSnapshot::asString ( long  ) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual RWCString RWLocaleSnapshot::asString ( unsigned  long) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual RWCString RWLocaleSnapshot::asString ( double  ,
int  = 6,
bool  = 0 
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual RWCString RWLocaleSnapshot::asString ( long  double,
int  = 10,
bool  = 0 
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::currency_symbol ( ) const
inlinevirtual

Returns a string to use as the currency symbol for this locale.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::decimal_point ( ) const
inlinevirtual

Returns a string to use as the numerical decimal separator.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::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.
Example
"\3" // Specifies the United States grouping system.
// For example, "1,000,000"
"\3\2" // Specifies the Nepalese grouping system.
// For example, "1,00,00,000"

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::int_curr_symbol ( ) const
inlinevirtual

Returns a string to use as the international currency symbol.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::locale_name ( ) const
inlinevirtual

Returns the name of the encapsulated std::locale.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::mon_decimal_point ( ) const
inlinevirtual

Returns a string to use as the monetary decimal separator.

Implements RWLocale.

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.

virtual const RWCString& RWLocaleSnapshot::mon_thousands_sep ( ) const
inlinevirtual

Returns a string to use as the monetary thousands separator.

Implements RWLocale.

virtual RWCString RWLocaleSnapshot::moneyAsString ( double  ,
RWLocaleSnapshot::CurrSymbol  = LOCAL 
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual int RWLocaleSnapshot::monthIndex ( const RWCString str) const
virtual

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.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::negative_sign ( ) const
inlinevirtual

Returns a string to use as the negative sign.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::positive_sign ( ) const
inlinevirtual

Returns a string to use as the positive sign.

Implements RWLocale.

virtual bool RWLocaleSnapshot::stringToDate ( const RWCString ,
struct tm *   
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual bool RWLocaleSnapshot::stringToMoney ( const RWCString ,
double *  ,
RWLocaleSnapshot::CurrSymbol  = LOCAL 
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual bool RWLocaleSnapshot::stringToNum ( const RWCString ,
double *   
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual bool RWLocaleSnapshot::stringToNum ( const RWCString ,
long *   
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual bool RWLocaleSnapshot::stringToNum ( const RWCString ,
unsigned long *   
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual bool RWLocaleSnapshot::stringToTime ( const RWCString ,
struct tm *   
) const
virtual

Redefined from RWLocale

Note
These virtual functions follow the interface described under class RWLocale. They generally work by converting values to and from strings using the rules specified by the std::lconv values (see http://en.cppreference.com/w/cpp/locale/lconv) encapsulated in self.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::thousands_sep ( ) const
inlinevirtual

Returns a string to use as the numerical thousands separator.

Implements RWLocale.

virtual int RWLocaleSnapshot::weekdayIndex ( const RWCString str) const
virtual

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.

Implements RWLocale.

Member Data Documentation

RWCString RWLocaleSnapshot::currency_symbol_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::decimal_point_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::frac_digits_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::grouping_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::int_curr_symbol_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::int_frac_digits_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::mon_decimal_point_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::mon_grouping_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::mon_thousands_sep_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::n_cs_precedes_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::n_sep_by_space_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::n_sign_posn_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::negative_sign_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::p_cs_precedes_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::p_sep_by_space_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

char RWLocaleSnapshot::p_sign_posn_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::positive_sign_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

RWCString RWLocaleSnapshot::thousands_sep_

Defined identically as the correspondingly-named member of the C++ Standard Library type std::lconv.

Copyright © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.