CppCMS
Classes | Functions
booster::locale::util Namespace Reference

This namespace provides various utility function useful for Boost.Locale backends implementations. More...

Classes

class  base_converter
 This class represent a simple stateless converter from UCS-4 and to UCS-4 for each single code point. More...
 

Functions

BOOSTER_API std::string get_system_locale (bool use_utf8_on_windows=false)
 Return default system locale name in POSIX format. More...
 
BOOSTER_API std::locale create_info (std::locale const &in, std::string const &name)
 Installs information facet to locale in based on locale name name. More...
 
BOOSTER_API std::auto_ptr< base_convertercreate_utf8_converter ()
 
BOOSTER_API std::auto_ptr< base_convertercreate_simple_converter (std::string const &encoding)
 
BOOSTER_API std::locale create_codecvt (std::locale const &in, std::auto_ptr< base_converter > cvt, character_facet_type type)
 
BOOSTER_API std::locale create_utf8_codecvt (std::locale const &in, character_facet_type type)
 
BOOSTER_API std::locale create_simple_codecvt (std::locale const &in, std::string const &encoding, character_facet_type type)
 

Detailed Description

This namespace provides various utility function useful for Boost.Locale backends implementations.

Function Documentation

BOOSTER_API std::locale booster::locale::util::create_codecvt ( std::locale const &  in,
std::auto_ptr< base_converter cvt,
character_facet_type  type 
)

Install codecvt facet into locale in and return new locale that is based on in and uses new facet.

codecvt facet would convert between narrow and wide/char16_t/char32_t encodings using cvt converter. If cvt is null pointer, always failure conversion would be used that fails on every first input or output.

Note: the codecvt facet handles both UTF-16 and UTF-32 wide encodings, it knows to break and join Unicode code-points above 0xFFFF to and from surrogate pairs correctly. cvt should be unaware of wide encoding type

Referenced by booster::locale::util::base_converter::from_unicode().

BOOSTER_API std::locale booster::locale::util::create_info ( std::locale const &  in,
std::string const &  name 
)

Installs information facet to locale in based on locale name name.

This function installs boost::locale::info facet into the locale in and returns newly created locale.

Note: all information is based only on parsing of string name;

The name has following format: language[_COUNTRY][.encoding][@variant] Where language is ISO-639 language code like "en" or "ru", COUNTRY is ISO-3166 country identifier like "US" or "RU". the Encoding is a charracter set name like UTF-8 or ISO-8859-1. Variant is backend specific variant like euro or calendar=hebrew.

If some parameters are missing they are specified as blanks, default encoding is assumed to be US-ASCII and missing language is assumed to be "C"

BOOSTER_API std::locale booster::locale::util::create_simple_codecvt ( std::locale const &  in,
std::string const &  encoding,
character_facet_type  type 
)

This function installs codecvt that can be used for conversion between single byte character encodings like ISO-8859-1, koi8-r, windows-1255 and Unicode code points,

Throws boost::locale::conv::invalid_charset_error if the chacater set is not supported or isn't single byte character set

Referenced by booster::locale::util::base_converter::from_unicode().

BOOSTER_API std::auto_ptr<base_converter> booster::locale::util::create_simple_converter ( std::string const &  encoding)

This function creates a base_converter that can be used for conversion between single byte character encodings like ISO-8859-1, koi8-r, windows-1255 and Unicode code points,

If encoding is not supported, empty pointer is returned. You should check if std::auto_ptr<base_converter>::get() != 0

Referenced by booster::locale::util::base_converter::from_unicode().

BOOSTER_API std::locale booster::locale::util::create_utf8_codecvt ( std::locale const &  in,
character_facet_type  type 
)

Install utf8 codecvt to UTF-16 or UTF-32 into locale in and return new locale that is based on in and uses new facet.

Referenced by booster::locale::util::base_converter::from_unicode().

BOOSTER_API std::auto_ptr<base_converter> booster::locale::util::create_utf8_converter ( )

This function creates a base_converter that can be used for conversion between UTF-8 and unicode code points

Referenced by booster::locale::util::base_converter::from_unicode().

BOOSTER_API std::string booster::locale::util::get_system_locale ( bool  use_utf8_on_windows = false)

Return default system locale name in POSIX format.

This function tries to detect the locale using, LC_CTYPE, LC_ALL and LANG environment variables in this order and if all of them unset, in POSIX platforms it returns "C"

On Windows additionally to check the above environment variables, this function tries to creates locale name from ISO-339 and ISO-3199 country codes defined for user default locale. If use_utf8_on_windows is true it sets the encoding to UTF-8, otherwise, if system locale supports ANSI code-page it defines the ANSI encoding like windows-1252, otherwise it fall-backs to UTF-8 encoding if ANSI code-page is not available.