This chapter describes components that C + + library that may use for porting to different cultures.
The locale facility includes internationalization support for
The header <locale> defines classes used to contain and manipulate information for
a locale.
namespace std {
class locale;
template <class Facet> const Facet& use_facet(const locale&);
template <class Facet> bool has_facet(const locale&) throw();
template <class charT> bool isspace (charT c, const locale& loc);
template <class charT> bool isprint (charT c, const locale& loc);
template <class charT> bool iscntrl (charT c, const locale& loc);
template <class charT> bool isupper (charT c, const locale& loc);
template <class charT> bool islower (charT c, const locale& loc);
template <class charT> bool isalpha (charT c, const locale& loc);
template <class charT> bool isdigit (charT c, const locale& loc);
template <class charT> bool ispunct (charT c, const locale& loc);
template <class charT> bool isxdigit(charT c, const locale& loc);
template <class charT> bool isalnum (charT c, const locale& loc);
template <class charT> bool isgraph (charT c, const locale& loc);
template <class charT> charT toupper(charT c, const locale& loc);
template <class charT> charT tolower(charT c, const locale& loc);
22- 2 Localization library DRAFT: 25 November 1997 22.1 Locales
class ctype_base;
template <class charT> class ctype;
template <> class ctype<char>; // specialization
template <class charT> class ctype_byname;
template <> class ctype_byname<char>; // specialization
class codecvt_base;
template <class internT, class externT, class stateT>
class codecvt;
template <class internT, class externT, class stateT>
class codecvt_byname;
template <class charT, class InputIterator> class num_get;
template <class charT, class OutputIterator> class num_put;
template <class charT> class numpunct;
template <class charT> class numpunct_byname;
template <class charT> class collate;
template <class charT> class collate_byname;
class time_base;
template <class charT, class InputIterator> class time_get;
template <class charT, class InputIterator> class time_get_byname;
template <class charT, class OutputIterator> class time_put;
template <class charT, class OutputIterator> class time_put_byname;
class money_base;
template <class charT, class InputIterator> class money_get;
template <class charT, class OutputIterator> class money_put;
template <class charT, bool Intl> class moneypunct;
template <class charT, bool Intl> class moneypunct_byname;
class messages_base;
template <class charT> class messages;
template <class charT> class messages_byname;
}
The class locale contains a set of facets for locale implementation. These facets are as if they were and index and an interface at the same time.
namespace std {
class locale {
public:
class facet;
class id;
typedef int category;
static const category
none = 0,
collate = 0x010, ctype = 0x020,
monetary = 0x040, numeric = 0x080,
time = 0x100, messages = 0x200,
all = collate | ctype | monetary | numeric | time | messages;
locale() throw()
locale(const locale& other) throw()
explicit locale(const char* std_name);
locale(const locale& other, const char* std_name, category);
template <class Facet> locale(const locale& other, Facet* f);
locale(const locale& other, const locale& one, category);
~locale() throw();
const locale& operator=(const locale& other) throw();
template <class Facet> locale combine(const locale& other);
basic_string<char> name() const;
bool operator==(const locale& other) const;
bool operator!=(const locale& other) const;
template <class charT, class Traits, class Allocator>
bool operator()(const basic_string<charT,Traits,Allocator>& s1,
const basic_string<charT,Traits,Allocator>& s2) const;
static locale global(const locale&);
static const locale& classic();
};
}
This library contains various types specific for locale implementation.
An integral type used as a mask for all types.
Prototype:
typedef int category;
Each locale member function takes a locale::category argument based on a corresponding facet.
| Category |
Includes Facets |
|---|---|
An implementation is included for each facet template member of a category.
| Category |
Includes Facets |
|---|---|
The class facet is the base class for locale feature sets.
class locale:: facet synopsis:
namespace std {
class locale::facet {
protected:
explicit facet(size_t refs = 0);
virtual ~facet();
private:
facet(const facet&); // not defined void operator=(const facet&); // not defined };
}
The class locale::id is used for an index for locale facet identification.
namespace std {
class locale::id {
public:
id();
private:
void operator=(const id&); // not defined id(const id&); // not defined };
}
Constructs an object of locale.
Prototype:
locale() throw();
locale(const locale& other) throw();
explicit locale(const char* std_name);
locale(const locale& other,
const char* std_name, category); template <class Facet> locale
(const locale& other, Facet* f); locale(const locale& other,
const locale& one, category cats); If a locale object is created with an empty string the LANG environmental variable is used to determine the Language.
Prototype:
Member functions of the class locale.
Creates a copy of the locale except for the type Facet of the argument.
Prototype:
template <class Facet> locale combine(const locale& other);Return:
The newly created locale is returned.
Returns the name of the locale.
Prototype:
basic_string<char> name() const;Return:
Returns the name of the locale or "*" if there is none.
The class locale has overloaded operators.
Prototype:
bool operator==(const locale& other) const;Return:
The equality operator returns true if both arguments are the same locale.
The locale non-equality operator
Prototype:
bool operator!=(const locale& other) const;Return:
The non-equality operator returns true if the locales are not the same.
Compares two strings using use_facet<collate<> >.
Prototype:
template <class charT,
class Traits, class Allocator> bool operator()(
const basic_string<charT,Traits,Allocator>& s1, const basic_string<charT,Traits,Allocator>& s2) const; Returns true if the first argument is less than the second argument for ordering.
global Prototype:
static locale global(const locale& loc);Return:
Global returns the previous locale.
Sets the locale to "C" locale equivalent to locale("C").
Prototype:
static const locale& classic();
Return:
This function returns the "C" locale.
Locale has two global functions.
Retrieves a reference to a facet of a locale.
Prototype:
template <class Facet> const Facet& use_facet
(const locale& loc); Throws a bad_cast exception if has_facet is false.
Return:
The function returns a facet reference to corresponding to its argument.
Tests a locale to see if a facet is present
Prototype:
template <class Facet> bool has_facet
(const locale& loc) throw(); If a facet requested is present has_facet returns true.
Character classification functionality is provided for in the locale class.
template <class charT> bool isspace (charT c, const locale& loc); template <class charT> bool isprint (charT c, const locale& loc); template <class charT> bool iscntrl (charT c, const locale& loc); template <class charT> bool isupper (charT c, const locale& loc); template <class charT> bool islower (charT c, const locale& loc); template <class charT> bool isalpha (charT c, const locale& loc); template <class charT> bool isdigit (charT c, const locale& loc); template <class charT> bool ispunct (charT c, const locale& loc); template <class charT> bool isxdigit(charT c, const locale& loc); template <class charT> bool isalnum (charT c, const locale& loc); template <class charT> bool isgraph (charT c, const locale& loc);
In the character classification functions true is returned if the function evaluates to true.
Character conversion functionality is provided for in the locale class.
Converts to upper case character using the locale specified.
Prototype:
template <class charT> charT toupper
(charT c, const locale& loc) const; Returns the upper case character.
Converts to a lower case character using the locale specified.
Prototype:
template <class charT> charT tolower
(charT c, const locale& loc) const; Returns the lower case character.
The standard provides for various locale categories for providing formatting and manipulation of data and streams.
The type ctype_base provides for const enumerations.
namespace std {
class ctype_base {
public:
enum mask {
space=1<<0, print=1<<1, cntrl=1<<2, upper=1<<3, lower=1<<4,
alpha=1<<5, digit=1<<6, punct=1<<7, xdigit=1<<8,
alnum=alpha|digit, graph=alnum|punct
};
};
}
The class ctype provides for character classifications.
template <class charT>
class ctype : public locale::facet, public ctype_base {
public:
typedef charT char_type;
explicit ctype(size_t refs = 0);
bool is(mask m, charT c) const;
const charT* is
(const charT* low, const charT* high, mask* vec) const;
const charT* scan_is
(mask m,const charT* low, const charT* high) const;
const charT* scan_not
(mask m,const charT* low, const charT* high) const;
charT toupper(charT c) const;
const charT* toupper(charT* low, const charT* high) const;
charT tolower(charT c) const;
const charT* tolower(charT* low, const charT* high) const;
charT widen(char c) const;
const char* widen
(const char* low, const char* high, charT* to) const;
char narrow(charT c, char dfault) const;
const charT* narrow
(const charT* low, const charT*, char dfault, char* to) const;
static locale::id id;
protected:
~ctype(); //virtual
virtual bool do_is(mask m, charT c) const;
virtual const charT* do_is
(const charT* low, const charT* high, mask* vec) const;
virtual const charT* do_scan_is
(mask m, const charT* low, const charT* high) const;
virtual const charT* do_scan_not
(mask m, const charT* low, const charT* high) const;
virtual charT do_toupper(charT) const;
virtual const charT* do_toupper
(charT* low, const charT* high) const;
virtual charT do_tolower(charT) const;
virtual const charT* do_tolower
(charT* low, const charT* high) const;
virtual charT do_widen(char) const;
virtual const char* do_widen
(const char* low, const char* high, charT* dest) const;
virtual char do_narrow(charT, char dfault) const;
virtual const charT* do_narrow
(const charT* low, const charT* high,
char dfault, char* dest) const;
};
An overloaded function that tests for or places a mask.
Prototype:
bool is(mask m, charT c) const;
Return:
Returns true if the char c matches mask.
Prototype:
const charT* is
(const charT* low, const charT* high, mask* vec) const; Fills between the low and high with the mask argument.
Return:
Scans the range for a mask value.
Prototype:
const charT* scan_is
(mask m, const charT* low, const charT* high) const; Returns a pointer to the first character in the range that matches
the mask, or the high argument if there is no match.
Scans the range for exclusion of the mask value.
Prototype:
const charT* scan_not(mask m,
const charT* low, const charT* high) const; Returns a pointer to the first character in the range that does
not match the mask, or the high argument if all characters match
Converts to a character or a range of characters to uppercase.
Prototype:
charT toupper(charT) const;
const charT* toupper
(charT* low, const charT* high) const; Returns the converted char if it exists.
Converts to a character or a range of characters to lowercase.
Prototype:
charT tolower(charT c) const;
const charT* tolower(charT* low, const charT* high) const;Return:
Returns the converted char if it exists.
Converts a char or range of char type to the charT type.
Prototype:
charT widen(char c) const;
const char* widen(const char* low, const char* high, charT* to) const;Return:
The converted charT is returned.
Converts a charT or range of charT type to the char type.
Prototype:
char narrow(charT c, char dfault) const;
const charT* narrow(const charT* low, const charT*, char dfault,
char* to) const;Return:
The converted char is returned.
Virtual functions must be overloaded in the locale.
Prototype:
bool do_is
(mask m, charT c) const; const charT* do_is
(const charT* low, const charT* high, mask* vec) const; Prototype:
const charT* do_scan_is(mask m,
const charT* low, const charT* high) const;
Prototype:
const charT* do_scan_not(mask m,
const charT* low, const charT* high) const;
Prototype:
charT do_toupper(charT c) const;
const charT* do_toupper(charT* low, const charT* high) const;
Prototype:
charT do_tolower(charT c) const;
const charT* do_tolower(charT* low, const charT* high) const;
Prototype:
charT do_widen(char c) const;
const char* do_widen(const char* low, const char* high,
charT* dest) const;
Prototype:
char do_narrow(charT c, char dfault) const;
const charT* do_narrow(const charT* low, const charT* high,
char dfault, char* dest) const;
Template class ctype_byname
namespace std { template <class charT>
class ctype_byname : public ctype<charT> {
public:
typedef ctype<charT>::mask mask;
explicit ctype_byname(const char*, size_t refs = 0);
protected:
~ctype_byname();
// virtual
virtual bool do_is(mask m, charT c) const;
virtual const charT* do_is
(const charT* low, const charT* high,mask* vec) const;
virtual const char* do_scan_is
(mask m, const charT* low, const charT* high) const;
virtual const char* do_scan_not
(mask m, const charT* low, const charT* high) const;
virtual charT do_toupper(charT) const;
virtual const charT* do_toupper
(charT* low, const charT* high) const;
virtual charT do_tolower(charT) const;
virtual const charT* do_tolower
(charT* low, const charT* high) const;
virtual charT do_widen(char) const;
virtual const char* do_widen
(const char* low, const char* high, charT* dest) const;
virtual char do_narrow(charT, char dfault) const;
virtual const charT* do_narrow
(const charT* low, const charT* high,
char dfault, char* dest) const;
};
}
namespace std {
template <> class ctype<char>
: public locale::facet, public ctype_base {
public:
typedef char char_type;
explicit
ctype(const mask* tab = 0, bool del = false,
size_t refs = 0);
bool is(mask m, char c) const;
const char* is(const char* low, const char* high, mask* vec) const;
const char* scan_is (mask m,
const char* low, const char* high) const;
const char* scan_not(mask m,
const char* low, const char* high) const;
char toupper(char c) const;
const char* toupper(char* low, const char* high) const;
char tolower(char c) const;
const char* tolower(char* low, const char* high) const;
char widen(char c) const;
const char* widen
(const char* low, const char* high, char* to) const;
char narrow(char c, char dfault) const;
const char* narrow
(const char* low, const char* high,
char dfault, char* to) const;
static locale::id id;
static const size_t table_size;
protected:
const mask* table() const throw();
static const mask* classic_table() throw();
~ctype(); //virtual
virtual char do_toupper(char c) const;
virtual const char* do_toupper
(char* low, const char* high) const;
virtual char do_tolower(char c) const;
virtual const char* do_tolower
(char* low, const char* high) const;
virtual char do_widen(char c) const;
virtual const char* do_widen
(const char* low, const char* high, char* to) const;
virtual char do_narrow(char c, char dfault) const;
virtual const char* do_narrow
(const char* low, const char* high,
char dfault, char* to) const; };
}
Specialized ctype<char> constructors and destructor.
Prototype:
explicit ctype
(const mask* tbl = 0, bool del = false, size_t refs = 0); Prototype:
Specialize ctype<char> member functions are identical functionality to "22.2.1.1.1 Ctype Members."
Prototype:
bool is(mask m, char c) const;
const char* is(const char* low, const char* high,
mask* vec) const;Prototype:
const char* scan_is(mask m,
const char* low, const char* high) const; const char* scan_not(mask m,
const char* low, const char* high) const;Prototype:
char toupper(char c) const;
const char* toupper(char* low, const char* high) const;Prototype:
char tolower(char c) const;
const char* tolower(char* low, const char* high) const;Prototype:
char widen(char c) const;
const char* widen(const char* low, const char* high,
char* to) const;Prototype:
char narrow(char c, char /*dfault*/) const;
const char* narrow(const char* low, const char* high,
char /*dfault*/, char* to) const;Prototype:
const mask* table() const throw();
Specialized ctype<char> static members. are provided.
Determines the classification of characters in the "C" locale.
Prototype:
static const mask* classic_table() throw();
Return:
Returns to a table that represents the classification in a "C" locale.
Specialize ctype<char> virtual member functions are identical functionality to "22.2.1.1.2 Ctype Virtual Functions."
Prototype:
char do_toupper(char) const;
const char* do_toupper
(char* low, const char* high) const; char do_tolower(char) const;
const char* do_tolower
(char* low, const char* high) const; virtual char do_widen(char c) const;
virtual const char* do_widen
(const char* low,const char* high, char* to) const; virtual char do_narrow(char c, char dfault) const;
virtual const char* do_narrow
(const char* low,const char* high, char dfault, char* to) const; A specialization of ctype_byname of type char.
namespace std {
template <> class ctype_byname<char> : public ctype<char> {
public:
explicit ctype_byname(const char*, size_t refs = 0);
protected:
~ctype_byname(); // virtual
virtual char do_toupper(char c) const;
virtual const char* do_toupper
(char* low, const char* high) const;
virtual char do_tolower(char c) const;
virtual const char* do_tolower
(char* low, const char* high) const;
virtual char do_widen(char c) const;
virtual const char* do_widen
(char* low,const char* high, char* to) const;
virtual char do_widen(char c) const;
virtual const char* do_widen(char* low, const char* high) const;
};
}
A class used for converting one character encoded types to another. For example, from wide character to multibyte character sets.
Template Class Codevect Synopsis:
namespace std {
class codecvt_base {
public:
enum result
{ ok, partial, error, noconv };
};
template <class internT, class externT, class stateT>
class codecvt : public locale::facet, public codecvt_base {
public:
typedef internT intern_type;
typedef externT extern_type;
typedef stateT state_type;
explicit codecvt(size_t refs = 0)
result out
(stateT& state, const internT* from, const internT* from_end,
const internT*& from_next, externT* to, externT* to_limit,
externT*& to_next) const;
result unshift
(stateT& state, externT* to, externT* to_limit,
externT*& to_next) const;
result in
(stateT& state, const externT* from, const externT* from_end,
const externT*& from_next, internT* to, internT* to_limit,
internT*& to_next) const;
int encoding() const throw();
bool always_noconv() const throw();
int length
(const stateT&, const externT* from, const externT* end,
size_t max) const;
int max_length() const throw();
static locale::id id;
protected:
~codecvt(); //virtual
virtual result do_out
(stateT& state, const internT* from, const internT* from_end,
const internT*& from_next, externT* to, externT* to_limit,
externT*& to_next) const;
virtual result do_in
(stateT& state, const externT* from, const externT* from_end,
const externT*& from_next, internT* to, internT* to_limit,
internT*& to_next) const;
virtual result do_unshift
(stateT& state, externT* to, externT* to_limit,
externT*& to_next) const;
virtual int do_encoding() const throw();
virtual bool do_always_noconv() const throw();
virtual int do_length
(const stateT&, const externT* from, const externT* end,
size_t max) const;
virtual int do_max_length() const throw();
};
}
Member functions of the codecvt class.
Convert internal representation to external.
Prototype:
result out(
stateT& state,const internT* from, const internT* from_end, const internT*& from_next, externT* to, externT* to_limit, externT*& to_next) const; Prototype:
result unshift(stateT& state,
externT* to, externT* to_limit, externT*& to_next) const;
Converts external representation to internal.
Prototype:
result in(stateT& state, const externT* from,
const externT* from_end, const externT*& from_next, internT* to, internT* to_limit, internT*& to_next) const; Determines if no conversion is ever done.
Prototype:
bool always_noconv() const throw();Return:
Returns true if no conversion will be done.
Determines the length between two points.
Prototype:
int length(stateT& state, const externT* from,
const externT* from_end, size_t max) const; The distance between two points is returned.
Determines the length necessary for conversion.
Prototype:
int max_length() const throw();Return:
The number of elements to convert from externT to internT is returned.
Virtual functions for codecvt implementation.
Prototype:
result do_out(stateT& state, const internT* from,
const internT* from_end, const internT*& from_next, externT* to, externT* to_limit, externT*& to_next) const;
Return:
The result is returned as a value as in "Convert Result Values."
Prototype:
result do_in(stateT& state, const externT* from,
const externT* from_end, const externT*& from_next, internT* to, internT* to_limit, internT*& to_next) const;
Return:
The result is returned as a value as in "Convert Result Values."
Prototype:
result do_unshift(stateT& state,
externT* to, externT* to_limit, externT*& to_next) const;
Return:
The result is returned as a value as in "Convert Result Values."
Prototype:
int do_encoding() const throw();
Prototype:
bool do_always_noconv() const throw();
Prototype:
int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
Prototype:
int do_max_length() const throw();
| Value |
Meaning |
|---|---|
A class for code conversion by name.
Template Class Codecvt_byname Synopsis:
namespace std {
template <class internT, class externT, class stateT>
class codecvt_byname : public codecvt<internT, externT, stateT> {
public:
explicit codecvt_byname(const char*, size_t refs = 0);
protected:
~codecvt_byname(); // virtual
virtual result do_out
(stateT& state, const internT* from, const internT* from_end,
const internT*& from_next, externT* to, externT* to_limit,
externT*& to_next) const;
virtual result do_in
(stateT& state, const externT* from, const externT* from_end,
const externT*& from_next, internT* to, internT* to_limit,
internT*& to_next) const;
virtual result do_unshift
(stateT& state, externT* to, externT* to_limit,
externT*& to_next) const;
virtual int do_encoding() const throw();
virtual bool do_always_noconv() const throw();
virtual int do_length
(const stateT&, const externT* from, const externT* end,
size_t max) const;
virtual result do_unshift
(stateT& state, externT* to, externT* to_limit,
externT*& to_next) const;
virtual int do_max_length() const throw();
};
}
A class for numeric formatting and manipulation for locales.
A class for formatted numeric input.
Template Class num_get Synopsis:
namespace std {
template <class charT, class InputIterator = istreambuf_iterator<charT> >
class num_get : public locale::facet {
public:
typedef charT char_type;
typedef InputIterator iter_type;
explicit num_get(size_t refs = 0);
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, bool& v) const;
iter_type get(iter_type in, iter_type end, ios_base& ,
ios_base::iostate& err, long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned short& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned int& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, float& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, double& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, long double& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, void*& v) const;
static locale::id id;
protected:
~num_get(); //virtual
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, bool& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned short& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned int& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned long& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, float& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, double& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long double& v) const;
virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, void*& v) const;
};
}
The class num_get includes specific functions for parsing and formatting of numbers.
The function get is overloaded for un-formatted input.
Prototype:
iter_type get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, long& val) const; iter_type get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, unsigned short& val) const; iter_type get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, unsigned int& val) const; iter_type get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, unsigned long& val) const; iter_type get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, short& val) const; iter_type get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, double& val) const; iter_type get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, long double& val) const; iter_type get(iter_type in, iter_type end,
ios_base& str, ios_base::iostate& err, void*& val) const; Prototype:
iter_type do_get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, long& val) const; iter_type do_get(iter_type in, iter_type end,
ios_base& str, ios_base::iostate& err, unsigned short& val) const; iter_type do_get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, nsigned int& val) const; iter_type do_get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, unsigned long& val) const; iter_type do_get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, float& val) const; iter_type do_get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, double& val) const; iter_type do_get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, long double& val) const; iter_type do_get(iter_type in, iter_type end,
ios_base& str,ios_base::iostate& err, void*& val) const; iiter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, bool& val) const;
Implements the relative versions of get.
A class for formatted numeric output.
Template Class num_put Synopsis:
namespace std {
template <class charT, class OutputIterator = ostreambuf_iterator<charT> >
class num_put : public locale::facet {
public:
typedef charT char_type;
typedef OutputIterator iter_type;
explicit num_put(size_t refs = 0);
iter_type put(iter_type s, ios_base& f,
char_type fill, bool v) const;
iter_type put(iter_type s, ios_base& f,
char_type fill, long v) const;
iter_type put(iter_type s, ios_base& f,
char_type fill, unsigned long v) const;
iter_type put(iter_type s, ios_base& f, char_type fill,
double v) const;
iter_type put(iter_type s, ios_base& f, char_type fill,
long double v) const;
iter_type put(iter_type s, ios_base& f, char_type fill,
const void* v) const;
static locale::id id;
protected:
~num_put(); //virtual
virtual iter_type do_put(iter_type, ios_base&, char_type fill,
bool v) const;
virtual iter_type do_put
(iter_type, ios_base&, char_type fill, long v) const;
virtual iter_type do_put
(iter_type, ios_base&, char_type fill, unsigned long) const;
virtual iter_type do_put
(iter_type, ios_base&, char_type fill, double v) const;
virtual iter_type do_put
(iter_type, ios_base&, char_type fill,long double v) const;
virtual iter_type do_put
(iter_type, ios_base&, char_type fill, const void* v) const;
};
}
The class num_put includes specific functions for parsing and formatting of numbers.
The function put is overloaded for un-formatted output.
Prototype:
iter_type put(iter_type out, ios_base& str,
char_type fill, bool val) const; iter_type put(iter_type out, ios_base& str,
char_type fill, long val) const; iter_type put(iter_type out, ios_base& str,
char_type fill,unsigned long val) const; iter_type put(iter_type out, ios_base& str,
char_type fill, double val) const; iter_type put(iter_type out, ios_base& str,
char_type fill,long double val) const; iter_type put(iter_type out, ios_base& str,
char_type fill const void* val) const; Implementation functions for put.
Prototype:
iter_type do_put(iter_type out, ios_base& str,
char_type fill, bool val) const; iter_type do_put(iter_type out, ios_base& str,
char_type fill, long val) const; iter_type do_put(iter_type out, ios_base& str,
char_type fill, unsigned long val) const; iter_type do_put(iter_type out, ios_base& str,
char_type fill, double val) const; iter_type do_put(iter_type out, ios_base& str,
char_type fill,long double val) const; iter_type do_put(iter_type out, ios_base& str,
char_type fill, const void* val) const; A facet for numeric punctuation in formatting and parsing.
A class for numeric punctuation conversion.
Template Class numpunct Synopsis:
namespace std {
template <class charT>
class numpunct : public locale::facet {
public:
typedef charT char_type;
typedef basic_string<charT> string_type;
explicit numpunct(size_t refs = 0);
char_type decimal_point() const;
char_type thousands_sep() const;
string grouping() const;
string_type truename() const;
string_type falsename() const;
static locale::id id;
protected:
~numpunct(); //virtual
virtual char_type do_decimal_point() const;
virtual char_type do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_truename() const;
virtual string_type do_falsename() const;
};
}
The template class numpunct provides various functions for punctuation localizations.
Determines the character used for a decimal point.
Prototype:
char_type decimal_point() const;Return:
Returns the character used for a decimal point.
Determines the character used for a thousand separator.
Prototype:
char_type thousands_sep() const;Return:
Returns the character used for the thousand separator.
Describes the thousand separators.
Prototype:
string grouping() const;Return:
Returns a string describing the thousand separators.
Determines the localization for "true".
Prototype:
string_type truename() const;Return:
Returns a string describing the localization of the word "true".
Determines the localization for "false".
Prototype:
string_type falsename() const;Return:
Returns a string describing the localization of the word "false".
Implementation of the public functions.
Prototype:
char_type do_decimal_point() const;
Prototype:
string_type do_thousands_sep() const;
Prototype:
string do_grouping() const;
Prototype:
string_type do_truename() const;
Prototype:
string_type do_falsename() const;
Provides for specializations of class numpunct.
Class Numpunct_byname Synopsis:
namespace std {
template <class charT>
class numpunct_byname : public numpunct<charT> {
// this class is specialized for char and wchar_t.
public:
typedef charT char_type;
typedef basic_string<charT> string_type;
explicit numpunct_byname(const char*, size_t refs = 0);
protected:
~numpunct_byname(); // virtual
virtual char_type do_decimal_point() const;
virtual char_type do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_truename() const; // for bool
virtual string_type do_falsename() const; // for bool
};
}
A class used for the comparison and manipulation of strings.
namespace std {
template <class charT>
class collate : public locale::facet {
public:
typedef charT char_type;
typedef basic_string<charT> string_type;
explicit collate(size_t refs = 0);
int compare(const charT* low1, const charT* high1,
const charT* low2, const charT* high2) const;
string_type transform(const charT* low, const charT* high) const;
long hash(const charT* low, const charT* high) const;
static locale::id id;
protected:
~collate(); //virtual
virtual int do_compare(const charT* low1, const charT* high1,
const charT* low2, const charT* high2) const;
virtual string_type do_transform
(const charT* low, const charT* high) const;
virtual long do_hash (const charT* low, const charT* high) const;
};
}
Member functions used for comparison and hashing of strings.
Lexicographical comparison of strings.
Prototype:
int compare(const charT* low1, const charT* high1,
const charT* low2, const charT* high2) const;Return:
A value of 1 is returned if the first is lexicographically greater than the second. A value of negative 1 is returned if the second is greater than the first. A value of zero is returned if the strings are the same.
Provides a string object to be compared to other transformed strings.
Prototype:
string_type transform
(const charT* low, const charT* high) const; The transform member function is used for comparison of a series of strings.
Return:
Returns a string for comparison.
Determines the hash value for the string.
Prototype:
long hash(const charT* low, const charT* high) const;Return:
Returns the hash value of the string
Localized implementation functions for public collate member functions.
Prototype:
int do_compare
(const charT* low1, const charT* high1, const charT* low2, const charT* high2) const; Prototype:
string_type do_transform(const charT* low, const charT* high) const;
Prototype:
long do_hash(const charT* low, const charT* high) const;
namespace std {
template <class charT>
class collate_byname : public collate<charT> {
public:
typedef basic_string<charT> string_type;
explicit collate_byname(const char*, size_t refs = 0);
protected:
~collate_byname(); // virtual
virtual int do_compare(const charT* low1, const charT* high1,
const charT* low2, const charT* high2) const;
virtual string_type do_transform
(const charT* low, const charT* high) const;
virtual long do_hash (const charT* low, const charT* high) const;
};
}
Classes for localized date and time formatting and manipulation.
namespace std {
class time_base {
public:
enum dateorder { no_order, dmy, mdy, ymd, ydm };
};
template <class charT, class InputIterator = istreambuf_iterator<charT> >
class time_get : public locale::facet, public time_base {
public:
typedef charT char_type;
typedef InputIterator iter_type;
explicit time_get(size_t refs = 0);
dateorder date_order() const { return do_date_order(); }
iter_type get_time(iter_type s, iter_type end, ios_base& f,
ios_base::iostate& err, tm* t) const;
iter_type get_date(iter_type s, iter_type end, ios_base& f,
ios_base::iostate& err, tm* t) const;
iter_type get_weekday(iter_type s, iter_type end, ios_base& f,
ios_base::iostate& err, tm* t) const;
iter_type get_monthname(iter_type s, iter_type end, ios_base& f,
ios_base::iostate& err, tm* t) const;
iter_type get_year(iter_type s, iter_type end, ios_base& f,
ios_base::iostate& err, tm* t) const;
static locale::id id;
protected:
~time_get(); //virtual
virtual dateorder do_date_order() const;
virtual iter_type do_get_time(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_date(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_weekday(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_monthname(iter_type s, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_year(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
};
}
Determines how the date, month and year are ordered.
Prototype:
dateorder date_order() const;Return:
Returns an enumeration representing the date, month, year order. Returns zero if it is un-ordered.
Determines the localized time.
Prototype:
iter_type get_time
(iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t) const; Returns an iterator immediately beyond the last character recognized as a valid time.
Determines the localized date.
Prototype:
iter_type get_date
(iter_type s, iter_type end,ios_base& str, ios_base::iostate& err, tm* t) const; Returns an iterator immediately beyond the last character recognized as a valid date.
Determines the localized weekday.
Prototype:
iter_type get_weekday
(iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t) const; Returns an iterator immediately beyond the last character recognized as a valid weekday.
Determines the localized month name.
Prototype:
iter_type get_monthname
(iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t) const; Returns an iterator immediately beyond the last character recognized as a valid month name.
Prototype:
iter_type get_year(iter_type s, iter_type end,
ios_base& str, ios_base::iostate& err, tm* t) const; Returns an iterator immediately beyond the last character recognized as a valid year.
Localized functions for implementation of the public functions.
Prototype:
dateorder do_date_order() const;
Prototype:
iter_type do_get_time(iter_type s, iter_type end,
ios_base& str, ios_base::iostate& err, tm* t) const; Prototype:
iter_type do_get_date
(iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t) const; Prototype:
iter_type do_get_weekday
(iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t) const; Prototype:
iter_type do_get_monthname
(iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t) const; Prototype:
iter_type do_get_year
(iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t) const; Template class Time_get_byname Synopsis:
Template class time_get_byname
namespace std {
template <class charT, class InputIterator = istreambuf_iterator<charT> >
class time_get_byname : public time_get<charT, InputIterator> {
public:
typedef time_base::dateorder dateorder;
typedef InputIterator iter_type
explicit time_get_byname(const char*, size_t refs = 0);
protected:
~time_get_byname(); // virtual
virtual dateorder do_date_order() const;
virtual iter_type do_get_time(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_date(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_weekday(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_monthname(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
virtual iter_type do_get_year(iter_type s, iter_type end, ios_base&,
ios_base::iostate& err, tm* t) const;
};
}
namespace std {
template <class charT, class OutputIterator = ostreambuf_iterator<charT> >
class time_put : public locale::facet {
public:
typedef charT char_type;
typedef OutputIterator iter_type;
explicit time_put(size_t refs = 0);
// the following is implemented in terms of other member functions.
iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb,
const charT* pattern, const charT* pat_end) const;
iter_type put(iter_type s, ios_base& f, char_type fill,
const tm* tmb, char format, char modifier = 0) const;
static locale::id id;
protected:
~time_put(); //virtual
virtual iter_type do_put(iter_type s, ios_base&, char_type, const tm* t,
char format, char modifier) const;
};
}
Functions used for formatting time.
Prototype:
iter_type put(iter_type s, ios_base& str,
char_type fill, const tm* t, const charT* pattern, const charT*
pat_end) const; iter_type put(iter_type s, ios_base& str,
char_type fill, const tm* t, char format, char modifier = 0) const; Returns an iterator immediately beyond the last character.
Implements localized time functions.
Prototype:
iter_type do_put(iter_type s, ios_base&,
char_type fill, const tm* t, char format, char modifier) const; Implements the public member function put.
namespace std {
template <class charT, class OutputIterator = ostreambuf_iterator<charT> >
class time_put_byname : public time_put<charT, OutputIterator>
{
public:
typedef charT char_type;
typedef OutputIterator iter_type;
explicit time_put_byname(const char*, size_t refs = 0);
protected:
~time_put_byname(); // virtual
virtual iter_type do_put(iter_type s, ios_base&, char_type, const tm* t,
char format, char modifier) const;
};
}
The monetary category is used for localization of monetary formats.
namespace std {
template <class charT,
class InputIterator = istreambuf_iterator<charT> >
class money_get : public locale::facet {
public:
typedef charT char_type;
typedef InputIterator iter_type;
typedef basic_string<charT> string_type;
explicit money_get(size_t refs = 0);
iter_type get(iter_type s, iter_type end, bool intl,
ios_base& f, ios_base::iostate& err,
long double& units) const;
iter_type get(iter_type s, iter_type end, bool intl,
ios_base& f, ios_base::iostate& err,
string_type& digits) const;
static locale::id id;
protected:
~money_get(); //virtual
virtual iter_type do_get(iter_type, iter_type, bool, ios_base&,
ios_base::iostate& err, long double& units) const;
virtual iter_type do_get(iter_type, iter_type, bool, ios_base&,
ios_base::iostate& err, string_type& digits) const;
};
}
Localized member functions for inputting monetary values.
Inputs a localized monetary value.
Prototype:
iter_type get(iter_type s, iter_type end,
bool intl, ios_base& f, ios_base::iostate& err, long double& quant) const; iter_type get( s, iter_type end, bool intl,
ios_base& f, ios_base::iostate& err, string_type& quant) const; Returns an iterator immediately beyond the last character recognized as a valid monetary quantity.
Implementation functions for localization of the money_get public member functions.
Prototype:
iter_type do_get(iter_type s, iter_type end,
bool intl, ios_base& str, ios_base::iostate& err, long double& units) const; iter_type do_get(iter_type s, iter_type end,
bool intl, ios_base& str, ios_base::iostate& err string_type& digits) const; Implements a localized monetary get function.
namespace std {
template <class charT,
class OutputIterator = ostreambuf_iterator<charT> >
class money_put : public locale::facet {
public:
typedef charT char_type;
typedef OutputIterator iter_type;
typedef basic_string<charT> string_type;
explicit money_put(size_t refs = 0);
iter_type put(iter_type s, bool intl, ios_base& f,
char_type fill, long double units) const;
iter_type put(iter_type s, bool intl, ios_base& f,
char_type fill, const string_type& digits) const;
static locale::id id;
protected:
~money_put(); //virtual
virtual iter_type
do_put(iter_type, bool, ios_base&, char_type fill,
long double units) const;
virtual iter_type
do_put(iter_type, bool, ios_base&, char_type fill,
const string_type& digits) const;
};
}
Localized member functions for outputting monetary values.
Outputs a localized monetary value.
Prototype:
iter_type put(iter_type s, bool intl, ios_base& f,
char_type fill, long double quant) const; iter_type put(iter_type s, bool intl, ios_base& f,
char_type fill, const string_type& quant) const; Returns an iterator immediately beyond the last character recognized as a valid monetary quantity.
Implementation functions for localization of the money_put public member functions.
Prototype:
iter_type do_put(iter_type s, bool intl,
ios_base& str, char_type fill, long double units) const; iter_type do_put(iter_type s, bool intl,
ios_base& str, char_type fill, const string_type& digits) const; Implements a localized put function.
An object used for localization of monetary punctuation.
namespace std {
class money_base {
public:
enum part { none, space, symbol, sign, value };
struct pattern { char field[4]; };
};
template <class charT, bool International = false>
class moneypunct : public locale::facet, public money_base {
public:
typedef charT char_type;
typedef basic_string<charT> string_type;
explicit moneypunct(size_t refs = 0);
charT decimal_point() const;
charT thousands_sep() const;
string grouping() const;
string_type curr_symbol() const;
string_type positive_sign() const;
string_type negative_sign() const;
int frac_digits() const;
pattern pos_format() const;
pattern neg_format() const;
static locale::id id;
static const bool intl = International;
protected:
~moneypunct(); //virtual
virtual charT do_decimal_point() const;
virtual charT do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
virtual pattern do_pos_format() const;
virtual pattern do_neg_format() const;
};
}
Member functions to determine the punctuation used for monetary formatting.
Determines what character to use as a decimal point.
Prototype:
charT decimal_point() const;Return:
Returns a char to be used as a decimal point.
Determines which character to use for a thousandths separator.
Prototype:
charT thousands_sep() const;Return:
Returns the character to use for a thousandths separator.
Determines a string that determines the grouping of thousands.
Prototype:
string grouping() const;Return:
Returns the string that determines the grouping of thousands.
Determines a string of the localized currency symbol.
Prototype:
string_type curr_symbol() const;Return:
Returns the string of the localized currency symbol.
Determines a string of the localized positive sign.
Prototype:
string_type positive_sign() const;Return:
Returns the string of the localized positive sign.
Determines a string of the localized negative sign.
Prototype:
string_type negative_sign() const;Return:
Returns the string of the localized negative sign.
Determines a string of the localized fractional digits.
Prototype:
int frac_digits() const;Return:
Returns the string of the localized fractional digits.
Determines the format of the localized non-negative values.
Prototype:
pattern pos_format() const;Return:
Returns the format of the localized non-negative values.
Determines the format of the localized non-negative values.
Prototype:
pattern neg_format() const;Return:
Returns he format of the localized non-negative values.
Virtual functions that implement the localized public member functions.
Prototype:
charT do_decimal_point() const;
Prototype:
charT do_thousands_sep() const;
Prototype:
string do_grouping() const;
Prototype:
string_type do_curr_symbol() const;
Prototype:
string_type do_positive_sign() const;
Prototype:
string_type do_negative_sign() const;
do_negative_sign()
Prototype:
int do_frac_digits() const;
Prototype:
pattern do_pos_format() const;
Prototype:
pattern do_neg_format() const;
namespace std {
template <class charT, bool Intl = false>
class moneypunct_byname : public moneypunct<charT, Intl> {
public:
typedef money_base::pattern pattern;
typedef basic_string<charT> string_type;
explicit moneypunct_byname(const char*, size_t refs = 0);
protected:
~moneypunct_byname(); // virtual
virtual charT do_decimal_point() const;
virtual charT do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
virtual pattern do_pos_format() const;
virtual pattern do_neg_format() const;
};
}
Implements the retrieval of strings from message catalogs.
namespace std {
class messages_base {
public:
typedef int catalog;
};
template <class charT>
class messages : public locale::facet, public messages_base {
public:
typedef charT char_type;
typedef basic_string<charT> string_type;
explicit messages(size_t refs = 0);
catalog open(const basic_string<char>& fn, const locale&) const;
string_type get(catalog c, int set, int msgid,
const string_type& dfault) const;
void close(catalog c) const;
static locale::id id;
protected:
~messages(); //virtual
virtual catalog do_open(const basic_string<char>&, const locale&) const;
virtual string_type do_get(catalog, int set, int msgid,
const string_type& dfault) const;
virtual void do_close(catalog) const;
};
}
Public member functions for catalog message retrieval.
Opens a message catalog for reading
Prototype:
catalog open(const basic_string<char>& name,
const locale& loc) const; Returns a value that may be passed to get to retrieve a message from a message catalog.
Retrieves a message from a message catalog.
Prototype:
string_type get(catalog cat, int set, int msgid,
const string_type& dfault) const; Returns the message in the form of a string.
Prototype:
void close(catalog cat) const;
Virtual functions used to localize the public member functions.
Prototype:
catalog do_open(const basic_string<char>& name,
const locale& loc) const; Prototype:
string_type do_get(catalog cat, int set, int msgid,
const string_type& dfault) const; Prototype:
void do_close(catalog cat) const;
namespace std {
template <class charT>
class messages_byname : public messages<charT> {
public:
typedef messages_base::catalog catalog;
typedef basic_string<charT> string_type;
explicit messages_byname(const char*, size_t refs = 0);
protected:
~messages_byname(); // virtual
virtual catalog do_open(const basic_string<char>&, const locale&) const;
virtual string_type do_get(catalog, int set, int msgid,
const string_type& dfault) const;
virtual void do_close(catalog) const;
};
}
A C++ program may add its own locales to be added to and used
the same as the built in facets. To do this derive a class from locale::facet with the static member static locael::id.id.
The C++ header <clocale> are the same as the C header locale but in standard namespace.
| Type |
Name(s) |
Name(s) |
|---|---|---|