Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale"

From cppreference.com
< cpp
(going to list _base and _byname inside each facet, to avoid cluttering this page. Only ctype has the special <char> version.)
m (See also: -'\n')
 
(28 intermediate revisions by 10 users not shown)
Line 1: Line 1:
 
{{title|Localization library}}
 
{{title|Localization library}}
{{cpp/locale/sidebar}}
+
{{cpp/locale/navbar}}
  
 
The locale facility includes internationalization support for character classification and string collation, numeric, monetary, and date/time formatting and parsing, and message retrieval. Locale settings control the behavior of stream I/O, regular expression library, and other components of the C++ standard library.
 
The locale facility includes internationalization support for character classification and string collation, numeric, monetary, and date/time formatting and parsing, and message retrieval. Locale settings control the behavior of stream I/O, regular expression library, and other components of the C++ standard library.
  
=== Locales ===
+
===Locales and facets===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list header | locale }}
+
{{dsc header|locale}}
 +
{{dsc h2|Locales}}
 +
{{dsc inc|cpp/locale/dsc locale}}
 +
{{dsc inc|cpp/locale/dsc use_facet}}
 +
{{dsc inc|cpp/locale/dsc has_facet}}
  
{{dcl list h2 | Locales and facets }}
+
{{dsc h2|Facet category base classes}}
{{dcl list class | cpp/locale/locale | polymorphic set of facets that comprise a locale }}
+
{{dsc inc|cpp/locale/dsc ctype_base}}
{{dcl list tfun | cpp/locale/use_facet | obtains a facet from a locale }}
+
{{dsc inc|cpp/locale/dsc codecvt_base}}
{{dcl list tfun | cpp/locale/has_facet | checks if a locale implements a specific facet }}
+
{{dsc inc|cpp/locale/dsc messages_base}}
 +
{{dsc inc|cpp/locale/dsc time_base}}
 +
{{dsc inc|cpp/locale/dsc money_base}}
  
{{dcl list h2 | Character classification }}
+
{{dsc h2|ctype facets}}
{{dcl list template | cpp/locale/dcl list isspace}}
+
{{dsc inc|cpp/locale/dsc ctype}}
{{dcl list tfun | cpp/locale/iscntrl | checks if a character is classified as a control character by a locale}}
+
{{dsc inc|cpp/locale/dsc ctype_byname}}
{{dcl list tfun | cpp/locale/isupper | checks if a character is classified as uppercase by a locale}}
+
{{dsc inc|cpp/locale/dsc ctype_char}}
{{dcl list tfun | cpp/locale/islower | checks if a character is classified as lowercase by a locale}}
+
{{dsc inc|cpp/locale/dsc codecvt}}
{{dcl list tfun | cpp/locale/isalpha | checks if a character is classified as alphabetic by a locale}}
+
{{dsc inc|cpp/locale/dsc codecvt_byname}}
{{dcl list tfun | cpp/locale/isdigit | checks if a character is classified as a digit by a locale}}
+
{{dcl list tfun | cpp/locale/ispunct | checks if a character is classified as punctuation by a locale}}
+
{{dcl list tfun | cpp/locale/isxdigit | checks if a character is classified as a hexadecimal digit by a locale}}
+
{{dcl list tfun | cpp/locale/isalnum | checks if a character is classified as alphanumeric by a locale}}
+
{{dcl list tfun | cpp/locale/isprint | checks if a character is classified as printable, including space, by a locale}}
+
{{dcl list tfun | cpp/locale/isgraph | checks if a character is classfied as printable, excluding space, by a locale}}
+
  
{{dcl list h2 | Character conversions }}
+
{{dsc h2|numeric facets}}
{{dcl list tfun | cpp/locale/toupper | converts a character to uppercase using the ctype facet of a locale}}
+
{{dsc inc|cpp/locale/dsc num_get}}
{{dcl list tfun | cpp/locale/tolower | converts a character to lowercase using the ctype facet of a locale}}
+
{{dsc inc|cpp/locale/dsc num_put}}
 +
{{dsc inc|cpp/locale/dsc numpunct}}
 +
{{dsc inc|cpp/locale/dsc numpunct_byname}}
  
{{dcl list h2 | String and stream conversions }}
+
{{dsc h2|collate facets}}
{{dcl list tclass | cpp/locale/wstring_convert | performs conversions between a wide string and a byte string | notes={{mark c++11}} }}
+
{{dsc inc|cpp/locale/dsc collate}}
{{dcl list tclass | cpp/locale/wbuffer_convert | performs conversion between a byte stream buffer and a wide stream buffer | notes={{mark c++11}}}}
+
{{dsc inc|cpp/locale/dsc collate_byname}}
  
{{dcl list h2 | Facet categories }}
+
{{dsc h2|time facets}}
{{dcl list tclass | cpp/locale/ctype | defines character classification tables }}
+
{{dsc inc|cpp/locale/dsc time_get}}
{{dcl list ptclass | cpp/locale/ctype_char | title=ctype{{small|<char>}} | specialization of {{cpp|std::ctype}} for type {{cpp|char}} }}
+
{{dsc inc|cpp/locale/dsc time_get_byname}}
{{dcl list tclass | cpp/locale/codecvt | converts between character encodings, including multibyte and wide}}
+
{{dsc inc|cpp/locale/dsc time_put}}
{{dcl list tclass | cpp/locale/collate | defines lexicographical comparison and hashing of strings}}
+
{{dsc inc|cpp/locale/dsc time_put_byname}}
{{dcl list tclass | cpp/locale/messages | implements retrieval of strings from message catalogs}}
+
{{dcl list tclass | cpp/locale/time_get | parses time/date values from an input character sequence into {{cpp|struct std::tm}}}}
+
{{dcl list tclass | cpp/locale/time_put | formats contents of {{cpp|struct std::tm}} for output as character sequence}}
+
{{dcl list tclass | cpp/locale/num_get | parses numeric values from an input character sequence}}
+
{{dcl list tclass | cpp/locale/num_put | formats numeric values for output as character sequence}}
+
{{dcl list tclass | cpp/locale/numpunct | defines numeric punctuation rules }}
+
{{dcl list tclass | cpp/locale/money_get | parses and constructs a monetary value from an input character sequence}}
+
{{dcl list tclass | cpp/locale/money_put | formats a monetary value for output as a character sequence }}
+
{{dcl list tclass | cpp/locale/moneypunct | defines monetary formatting parameters used by {{cpp|std::money_get}} and {{cpp|std::money_put}} }}
+
{{dcl list end}}
+
  
=== Standard code conversion facets ===
+
{{dsc h2|monetary facets}}
{{dcl list begin}}
+
{{dsc inc|cpp/locale/dsc money_get}}
{{dcl list header | codecvt }}
+
{{dsc inc|cpp/locale/dsc money_put}}
{{dcl list tclass | cpp/locale/codecvt_utf8 | converts between UTF8 and UCS2/UCS4 | notes={{mark c++11}}}}
+
{{dsc inc|cpp/locale/dsc moneypunct}}
{{dcl list tclass | cpp/locale/codecvt_utf16 | converts between UTF16 and UCS2/UCS4 | notes={{mark c++11}}}}
+
{{dsc inc|cpp/locale/dsc moneypunct_byname}}
{{dcl list tclass | cpp/locale/codecvt_utf8_utf16 | converts between UTF8 and UTF16 | notes={{mark c++11}}}}
+
{{dcl list class | cpp/locale/codecvt_mode | tags to alter behavior of the standard codecvt facets| notes={{mark c++11}}}}
+
{{dcl list end}}
+
  
=== C library locales ===
+
{{dsc h2|messages facets}}
{{dcl list begin}}
+
{{dsc inc|cpp/locale/dsc messages}}
{{dcl list header | clocale }}
+
{{dsc inc|cpp/locale/dsc messages_byname}}
{{dcl list template | cpp/locale/dcl list setlocale}}
+
{{dsc end}}
{{dcl list macro const | cpp/locale/LC_ALL | full locale category for {{cpp|std::setlocale}}}}
+
 
{{dcl list macro const | cpp/locale/LC_COLLATE | string comparison locale category for {{cpp|std::setlocale}}}}
+
===Character classification and conversion===
{{dcl list macro const | cpp/locale/LC_CTYPE | character classification locale category for {{cpp|std::setlocale}}}}
+
{{dsc begin}}
{{dcl list macro const | cpp/locale/LC_MONETARY | monetary formatting locale category for {{cpp|std::setlocale}}}}
+
{{dsc header|locale}}
{{dcl list macro const | cpp/locale/LC_NUMERIC | nonmonetary numeric formatting locale category for {{cpp|std::setlocale}}}}
+
{{dsc h2|Character classification}}
{{dcl list macro const | cpp/locale/LC_TIME | time formatting locale category for {{cpp|std::setlocale}}}}
+
{{dsc inc|cpp/locale/dsc isspace}}
{{dcl list fun | cpp/types/localeconv | queries numeric and monetary formatting details of the current locale}}
+
{{dsc inc|cpp/locale/dsc isblank}}
{{dcl list class | cpp/types/lconv | formatting details, returned by {{cpp|std::localeconv}} }}
+
{{dsc inc|cpp/locale/dsc iscntrl}}
{{dcl list end}}
+
{{dsc inc|cpp/locale/dsc isupper}}
 +
{{dsc inc|cpp/locale/dsc islower}}
 +
{{dsc inc|cpp/locale/dsc isalpha}}
 +
{{dsc inc|cpp/locale/dsc isdigit}}
 +
{{dsc inc|cpp/locale/dsc ispunct}}
 +
{{dsc inc|cpp/locale/dsc isxdigit}}
 +
{{dsc inc|cpp/locale/dsc isalnum}}
 +
{{dsc inc|cpp/locale/dsc isprint}}
 +
{{dsc inc|cpp/locale/dsc isgraph}}
 +
 
 +
{{dsc h2|Character conversions}}
 +
{{dsc inc|cpp/locale/dsc toupper}}
 +
{{dsc inc|cpp/locale/dsc tolower}}
 +
 
 +
{{dsc h2|String and stream conversions}}
 +
{{dsc inc|cpp/locale/dsc wstring_convert}}
 +
{{dsc inc|cpp/locale/dsc wbuffer_convert}}
 +
{{dsc end}}
 +
 
 +
 
 +
{{rrev|since=c++26|
 +
===Text encoding identifications===
 +
{{dsc begin}}
 +
{{dsc header|text_encoding}}
 +
{{dsc inc|cpp/locale/dsc text_encoding}}
 +
{{dsc end}}
 +
}}
 +
 
 +
 
 +
{{rrev|until=c++26|
 +
===Locale-independent unicode conversion facets===
 +
{{dsc begin}}
 +
{{dsc header|codecvt}}
 +
{{dsc inc|cpp/locale/dsc codecvt_utf8}}
 +
{{dsc inc|cpp/locale/dsc codecvt_utf16}}
 +
{{dsc inc|cpp/locale/dsc codecvt_utf8_utf16}}
 +
{{dsc inc|cpp/locale/dsc codecvt_mode}}
 +
{{dsc end}}
 +
}}
 +
 
 +
===C library locales===
 +
{{dsc begin}}
 +
{{dsc header|clocale}}
 +
{{dsc inc|cpp/locale/dsc setlocale}}
 +
{{dsc inc|cpp/locale/dsc LC_categories}}
 +
{{dsc inc|cpp/locale/dsc localeconv}}
 +
{{dsc inc|cpp/locale/dsc lconv}}
 +
{{dsc end}}
 +
 
 +
===See also===
 +
{{dsc begin}}
 +
{{dsc see c|c/locale|Localization support|nomono=true}}
 +
{{dsc end}}
 +
 
 +
{{langlinks|ar|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 20:29, 30 December 2023

 
 
 

The locale facility includes internationalization support for character classification and string collation, numeric, monetary, and date/time formatting and parsing, and message retrieval. Locale settings control the behavior of stream I/O, regular expression library, and other components of the C++ standard library.

Contents

[edit] Locales and facets

Defined in header <locale>
Locales
set of polymorphic facets that encapsulate cultural differences
(class) [edit]
obtains a facet from a locale
(function template) [edit]
checks if a locale implements a specific facet
(function template) [edit]
Facet category base classes
defines character classification categories
(class) [edit]
defines character conversion errors
(class) [edit]
defines messages catalog type
(class) [edit]
defines date format constants
(class) [edit]
defines monetary formatting patterns
(class) [edit]
ctype facets
defines character classification tables
(class template) [edit]
represents the system-supplied std::ctype for the named locale
(class template) [edit]
specialization of std::ctype for type char
(class template specialization) [edit]
converts between character encodings, including UTF-8, UTF-16, UTF-32
(class template) [edit]
represents the system-supplied std::codecvt for the named locale
(class template) [edit]
numeric facets
parses numeric values from an input character sequence
(class template) [edit]
formats numeric values for output as character sequence
(class template) [edit]
defines numeric punctuation rules
(class template) [edit]
represents the system-supplied std::numpunct for the named locale
(class template) [edit]
collate facets
defines lexicographical comparison and hashing of strings
(class template) [edit]
represents the system-supplied std::collate for the named locale
(class template) [edit]
time facets
parses time/date values from an input character sequence into std::tm
(class template) [edit]
represents the system-supplied std::time_get for the named locale
(class template) [edit]
formats contents of std::tm for output as character sequence
(class template) [edit]
represents the system-supplied std::time_put for the named locale
(class template) [edit]
monetary facets
parses and constructs a monetary value from an input character sequence
(class template) [edit]
formats a monetary value for output as a character sequence
(class template) [edit]
defines monetary formatting parameters used by std::money_get and std::money_put
(class template) [edit]
represents the system-supplied std::moneypunct for the named locale
(class template) [edit]
messages facets
implements retrieval of strings from message catalogs
(class template) [edit]
represents the system-supplied std::messages for the named locale
(class template) [edit]

[edit] Character classification and conversion

Defined in header <locale>
Character classification
checks if a character is classified as whitespace by a locale
(function template) [edit]
checks if a character is classified as a blank character by a locale
(function template) [edit]
checks if a character is classified as a control character by a locale
(function template) [edit]
checks if a character is classified as uppercase by a locale
(function template) [edit]
checks if a character is classified as lowercase by a locale
(function template) [edit]
checks if a character is classified as alphabetic by a locale
(function template) [edit]
checks if a character is classified as a digit by a locale
(function template) [edit]
checks if a character is classified as punctuation by a locale
(function template) [edit]
checks if a character is classified as a hexadecimal digit by a locale
(function template) [edit]
checks if a character is classified as alphanumeric by a locale
(function template) [edit]
checks if a character is classified as printable by a locale
(function template) [edit]
checks if a character is classified as graphical by a locale
(function template) [edit]
Character conversions
converts a character to uppercase using the ctype facet of a locale
(function template) [edit]
converts a character to lowercase using the ctype facet of a locale
(function template) [edit]
String and stream conversions
(C++11)(deprecated in C++17)(removed in C++26)
performs conversions between a wide string and a byte string
(class template) [edit]
(C++11)(deprecated in C++17)(removed in C++26)
performs conversion between a byte stream buffer and a wide stream buffer
(class template) [edit]


Text encoding identifications

Defined in header <text_encoding>
describes an interface for accessing the IANA Character Sets registry
(class) [edit]
(since C++26)


Locale-independent unicode conversion facets

Defined in header <codecvt>
(C++11)(deprecated in C++17)(removed in C++26)
converts between UTF-8 and UCS-2/UCS-4
(class template) [edit]
(C++11)(deprecated in C++17)(removed in C++26)
converts between UTF-16 and UCS-2/UCS-4
(class template) [edit]
(C++11)(deprecated in C++17)(removed in C++26)
converts between UTF-8 and UTF-16
(class template) [edit]
(C++11)(deprecated in C++17)(removed in C++26)
tags to alter behavior of the standard codecvt facets
(enum) [edit]
(until C++26)

[edit] C library locales

Defined in header <clocale>
gets and sets the current C locale
(function) [edit]
locale categories for std::setlocale
(macro constant) [edit]
queries numeric and monetary formatting details of the current locale
(function) [edit]
formatting details, returned by std::localeconv
(class) [edit]

[edit] See also

C documentation for Localization support