template< class CharT >
class ctype;
Class ctype
encapsulates character classification features. All stream input operations performed through std::basic_istream<CharT> use the std::ctype<CharT>
of the locale imbued in the stream to identify whitespace characters for input tokenization. Stream output operations apply std::ctype<CharT>::widen()
to narrow-character arguments prior to output.
Inheritance diagram
[edit] SpecializationsThe standard library is guaranteed to provide the following specializations (they are required to be implemented by any locale object):
std::ctype<char>
provides narrow character equivalents of the minimal "C" locale classification. This specialization uses table lookup for character classification std::ctype<wchar_t> provides wide character classification appropriate to the native character set [edit] Nested types Type Definition char_type
CharT
[edit] Data members [edit] Member functions [edit] Protected member functions classifies a character or a character sequence
CharT
CharT
to char
mask
unspecified BitmaskType type (enumeration, integer type, or bitset) Member constants the value of mask
identifying whitespace character classification
mask
identifying printable character classification
mask
identifying control character classification
mask
identifying uppercase character classification
mask
identifying lowercase character classification
mask
identifying alphabetic character classification
mask
identifying digit character classification
mask
identifying punctuation character classification
mask
identifying hexadecimal digit character classification
mask
identifying blank character classification
The following example demonstrates modification of a ctype
other than ctype<char>
to tokenize a CSV file:
#include <iostream> #include <locale> #include <sstream> struct csv_whitespace : std::ctype<wchar_t> { bool do_is(mask m, char_type c) const { if ((m & space) && c == L' ') return false; // space will NOT be classified as whitespace if ((m & space) && c == L',') return true; // comma will be classified as whitespace return ctype::do_is(m, c); // leave the rest to the base class } }; int main() { std::wstring in = L"Column 1,Column 2,Column 3\n123,456,789"; std::wstring token; std::wcout << "default locale:\n"; std::wistringstream s1(in); while (s1 >> token) std::wcout << " " << token << '\n'; std::wcout << "locale with modified ctype:\n"; std::wistringstream s2(in); csv_whitespace* my_ws = new csv_whitespace; s2.imbue(std::locale(s2.getloc(), my_ws)); while (s2 >> token) std::wcout << " " << token << '\n'; }
Output:
default locale: Column 1,Column 2,Column 3 123,456,789 locale with modified ctype: Column 1 Column 2 Column 3 123 456 789[edit] See also specialization of std::ctype for type char
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4