Boost.Locale
boost::locale::util Namespace Reference

This namespace provides various utility function useful for Boost.Locale's 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...
 
class  locale_data
 Holder and parser for locale names/identifiers. More...
 

Functions

std::string get_system_locale (bool use_utf8_on_windows=false)
 Return default system locale name in POSIX format. More...
 
std::locale create_info (const std::locale &in, const std::string &name)
 Installs information facet to locale in based on locale name name. More...
 
std::unique_ptr< base_convertercreate_utf8_converter ()
 
std::unique_ptr< base_convertercreate_utf8_converter_unique_ptr ()
 
std::unique_ptr< base_convertercreate_simple_converter (const std::string &encoding)
 
std::unique_ptr< base_convertercreate_simple_converter_unique_ptr (const std::string &encoding)
 
std::locale create_codecvt (const std::locale &in, std::unique_ptr< base_converter > cvt, char_facet_t type)
 
std::locale create_codecvt_from_pointer (const std::locale &in, base_converter *cvt, char_facet_t type)
 
base_convertercreate_utf8_converter_new_ptr ()
 
base_convertercreate_simple_converter_new_ptr (const std::string &encoding)
 
std::locale create_utf8_codecvt (const std::locale &in, char_facet_t type)
 
std::locale create_simple_codecvt (const std::locale &in, const std::string &encoding, char_facet_t type)
 
template<typename Char >
Char * str_end (Char *str)
 Return the end of a C-string, i.e. the pointer to the trailing NULL byte.
 
constexpr bool is_upper_ascii (const char c)
 
constexpr bool is_lower_ascii (const char c)
 
constexpr bool is_numeric_ascii (const char c)
 
constexpr char to_char (unsigned char c)
 Cast an unsigned char to a (possibly signed) char avoiding implementation defined behavior.
 

Detailed Description

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

Function Documentation

◆ create_codecvt()

std::locale boost::locale::util::create_codecvt ( const std::locale &  in,
std::unique_ptr< base_converter cvt,
char_facet_t  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

◆ create_info()

std::locale boost::locale::util::create_info ( const std::locale &  in,
const std::string &  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 character 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"

◆ create_simple_codecvt()

std::locale boost::locale::util::create_simple_codecvt ( const std::locale &  in,
const std::string &  encoding,
char_facet_t  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,

Exceptions
boost::locale::conv::invalid_charset_errorCharacter set is not supported or isn't a single byte character set

◆ create_simple_converter()

std::unique_ptr< base_converter > boost::locale::util::create_simple_converter ( const std::string &  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. So you should check whether the returned pointer is valid/non-NULL

◆ create_utf8_codecvt()

std::locale boost::locale::util::create_utf8_codecvt ( const std::locale &  in,
char_facet_t  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.

◆ create_utf8_converter()

std::unique_ptr< base_converter > boost::locale::util::create_utf8_converter ( )

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

◆ get_system_locale()

std::string boost::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_ALL, LC_CTYPE and LANG environment variables in this order and if all of them are unset, on POSIX platforms it returns "C". On Windows additionally to the above environment variables, this function tries to create the locale name from ISO-639 and ISO-3166 country codes defined for the users default locale. If use_utf8_on_windows is true it sets the encoding to UTF-8, otherwise, if the system locale supports ANSI codepages it defines the ANSI encoding, e.g. windows-1252, otherwise (if ANSI codepage is not available) it uses UTF-8 encoding.