在线文档教程
C++
本土化 | Localizations

std::ctype_byname

std::ctype_byname

Defined in header
template< class CharT > class ctype_byname : public std::ctype<CharT>;

std::ctype_byname is a std::ctype facet which encapsulates character classification rules of the locale specified at its construction.

Two specializations are provided by the standard library.

| Defined in header <locale> |

|:----|

| std::ctype_byname<char> | provides narrow character classification. This specialization uses table lookup for character classification |

| std::ctype_byname<wchar_t> | provides wide character classification |

Member types

Member typeDefinition
maskctype<CharT>::mask

Member functions

(constructor)constructs a new ctype_byname facet (public member function)
(destructor)destroys a ctype_byname facet (protected member function)

std::ctype_byname::ctype_byname

explicit ctype_byname( const char* name, std::size_t refs = 0
explicit ctype_byname( const std::string& name, std::size_t refs = 0 (since C++11)

Constructs a new std::ctype_byname facet for a locale with name.

refs is used for resource management: if refs == 0, the implementation destroys the facet, when the last std::locale object holding it is destroyed. Otherwise, the object is not destroyed.

Parameters

name-the name of the locale
refs-the number of references that link to the facet

std::ctype_byname::~ctype_byname

protected: ~ctype_byname(

Destroys the facet.

Inherited from std::ctype<CharT>

Member types

Member typeDefinition
char_typeCharT

Member objects

Member nameType
static std::locale::id id staticid of the locale (public static member constant)

| if CharT is char, the following member of std::ctype<char> is inherited |

| static const std::size_t table_size static | size of the classification table, at least 256 (public static member constant) |

Member functions

isinvokes do_is (public member function of std::ctype)
scan_isinvokes do_scan_is (public member function of std::ctype)
scan_notinvokes do_scan_not (public member function of std::ctype)
toupperinvokes do_toupper (public member function of std::ctype)
tolowerinvokes do_tolower (public member function of std::ctype)
wideninvokes do_widen (public member function of std::ctype)
narrowinvokes do_narrow (public member function of std::ctype)

| if CharT is char, the following members of std::ctype<char> are inherited |

| table | obtains the character classification table (public member function of std::ctype<char>) |

| classic_table static | obtains the "C" locale character classification table (public static member function of std::ctype<char>) |

Protected member functions

do_toupper virtualconverts a character or characters to uppercase (virtual protected member function of std::ctype)
do_tolower virtualconverts a character or characters to lowercase (virtual protected member function of std::ctype)
do_widen virtualconverts a character or characters from char to charT (virtual protected member function of std::ctype)
do_narrow virtualconverts a character or characters from charT to char (virtual protected member function of std::ctype)

| if CharT is char, the following members of std::ctype are NOT inherited |

| do_is virtual | classifies a character or a character sequence (virtual protected member function of std::ctype) |

| do_scan_is virtual | locates the first character in a sequence that conforms to given classification (virtual protected member function of std::ctype) |

| do_scan_not virtual | locates the first character in a sequence that fails given classification (virtual protected member function of std::ctype) |

Inherited from std::ctype_base

Member types

TypeDefinition
maskunspecified bitmask type (enumeration, integer type, or bitset)

Member constants

space staticthe value of mask identifying whitespace character classification (public static member constant)
print staticthe value of mask identifying printable character classification (public static member constant)
cntrl staticthe value of mask identifying control character classification (public static member constant)
upper staticthe value of mask identifying uppercase character classification (public static member constant)
lower staticthe value of mask identifying lowercase character classification (public static member constant)
alpha staticthe value of mask identifying alphabetic character classification (public static member constant)
digit staticthe value of mask identifying digit character classification (public static member constant)
punct staticthe value of mask identifying punctuation character classification (public static member constant)
xdigit staticthe value of mask identifying hexadecimal digit character classification (public static member constant)
blank staticthe value of mask identifying blank character classification (public static member constant)
alnum staticalpha | digit (public static member constant)
graph staticalnum | punct (public static member constant)

Notes

The explicit specialization std::ctype_byname<char> was listed as a separate entry in the header file <locale> until C++11. it was removed in C++11 as defect #1298, but it remains a required specialization, just like std::ctype_byname<wchar_t>.

Example

#include <iostream> #include <locale> int main() { wchar_t c = L'\u00de'; // capital letter thorn std::locale loc("C" std::cout << "isupper('Þ', C locale) returned " << std::boolalpha << std::isupper(c, loc) << '\n'; loc = std::locale(loc, new std::ctype_byname<wchar_t>("en_US.utf8") std::cout << "isupper('Þ', C locale with Unicode ctype) returned " << std::boolalpha << std::isupper(c, loc) << '\n'; }

Output:

isupper('Þ', C locale) returned false isupper('Þ', C locale with Unicode ctype) returned true

See also

ctypedefines character classification tables (class template)
ctype<char>specialization of std::ctype for type char (class template specialization)

© cppreference.com

Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.

http://en.cppreference.com/w/cpp/locale/ctype_byname