rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWLocaleSnapshot Class Reference
[Internationalization]

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

List of all members.

Public Member Functions

virtual const RWCStringlocale_name () const
virtual const RWCStringdecimal_point () const
virtual const RWCStringthousands_sep () const
virtual const RWCStringgrouping () const
virtual const RWCStringint_curr_symbol () const
virtual const RWCStringcurrency_symbol () const
virtual const RWCStringmon_decimal_point () const
virtual const RWCStringmon_thousands_sep () const
virtual const RWCStringmon_grouping () const
virtual const RWCStringpositive_sign () const
virtual const RWCStringnegative_sign () const
 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 RWCString moneyAsString (double, RWLocaleSnapshot::CurrSymbol=LOCAL) const
virtual bool stringToDate (const RWCString &, struct tm *) const
virtual bool stringToTime (const RWCString &, struct tm *) 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 stringToMoney (const RWCString &, double *, RWLocaleSnapshot::CurrSymbol=LOCAL) const
virtual int monthIndex (const RWCString &) const
virtual int weekdayIndex (const RWCString &) const

Public Attributes

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

Detailed Description

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>
 RWLocaleSnapshot ourLocale("");  // encapsulate user's formats

Persistence

None

Examples

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 us("C");
 
     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;
  
     RWDateTime bad = RWDateTime(frenchDate, RWDateTime::setDate);
     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 ( const char *  localeName = 0  ) 

Constructs an RWLocale 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 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

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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) encapsulated in self.

Implements RWLocale.

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 struct lconv values (see <locale.h>) encapsulated in self.

Implements RWLocale.

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 struct lconv values (see <locale.h>) encapsulated in self.

Reimplemented from RWLocale.

virtual const RWCString& RWLocaleSnapshot::currency_symbol (  )  const [inline, virtual]

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

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::decimal_point (  )  const [inline, virtual]

Returns a string to use as the numerical decimal separator.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::grouping (  )  const [inline, 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.

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

Examples

 "\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 [inline, virtual]

Returns a string to use as the international currency symbol.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::locale_name (  )  const [inline, virtual]

Returns the name of the encapsulated std::locale.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::mon_decimal_point (  )  const [inline, virtual]

Returns a string to use as the monetary decimal separator.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::mon_grouping (  )  const [inline, 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.

  • 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 [inline, virtual]

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 struct lconv values (see <locale.h>) 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 [inline, virtual]

Returns a string to use as the negative sign.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::positive_sign (  )  const [inline, virtual]

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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) 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 struct lconv values (see <locale.h>) encapsulated in self.

Implements RWLocale.

virtual const RWCString& RWLocaleSnapshot::thousands_sep (  )  const [inline, virtual]

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

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

Defined identically as the correspondingly-named member of the Standard C Library type lconv, from <locale.h>.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.