[locale.ctype]

# 28 Text processing library [[text]](./#text)

## 28.3 Localization library [[localization]](localization#locale.ctype)

### 28.3.4 Standard locale categories [[locale.categories]](locale.categories#locale.ctype)

#### 28.3.4.2 The ctype category [[category.ctype]](category.ctype#locale.ctype)

#### 28.3.4.2.2 Class template ctype [locale.ctype]

#### [28.3.4.2.2.1](#general) General [[locale.ctype.general]](locale.ctype.general)

[ð](#lib:ctype)

namespace std {template<class charT>class ctype : public locale::facet, public ctype_base {public:using char_type = charT; explicit ctype(size_t refs = 0); bool is(mask m, charT c) const; const charT* is(const charT* low, const charT* high, mask* vec) const; const charT* scan_is(mask m, const charT* low, const charT* high) const; const charT* scan_not(mask m, const charT* low, const charT* high) const;
 charT toupper(charT c) const; const charT* toupper(charT* low, const charT* high) const;
 charT tolower(charT c) const; const charT* tolower(charT* low, const charT* high) const;

 charT widen(char c) const; const char* widen(const char* low, const char* high, charT* to) const; char narrow(charT c, char dfault) const; const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const; static locale::id id; protected:~ctype(); virtual bool do_is(mask m, charT c) const; virtual const charT* do_is(const charT* low, const charT* high, mask* vec) const; virtual const charT* do_scan_is(mask m, const charT* low, const charT* high) const; virtual const charT* do_scan_not(mask m, const charT* low, const charT* high) const; virtual charT do_toupper(charT) const; virtual const charT* do_toupper(charT* low, const charT* high) const; virtual charT do_tolower(charT) const; virtual const charT* do_tolower(charT* low, const charT* high) const; virtual charT do_widen(char) const; virtual const char* do_widen(const char* low, const char* high, charT* dest) const; virtual char do_narrow(charT, char dfault) const; virtual const charT* do_narrow(const charT* low, const charT* high, char dfault, char* dest) const; };}

[1](#general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1395)

Class ctype encapsulates the C library [<cctype>](cctype.syn#header:%3ccctype%3e "28.7.1 Header <cctype> synopsis [cctype.syn]") features[.](#general-1.sentence-1)

istream members are required to use ctype<> for character classing during input parsing[.](#general-1.sentence-2)

[2](#general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1400)

The specializations
required in Table [91](locale.category#tab:locale.category.facets "Table 91: Locale category facets") ([[locale.category]](locale.category "28.3.3.1.2.1 Type locale​::​category")),
namely ctype<char> and ctype<wchar_t>,
implement character classing appropriate
to the implementation's native character set[.](#general-2.sentence-1)

#### [28.3.4.2.2.2](#members) ctype members [[locale.ctype.members]](locale.ctype.members)

[ð](#lib:ctype,is)

`bool         is(mask m, charT c) const;
const charT* is(const charT* low, const charT* high, mask* vec) const;
`

[1](#members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1416)

*Returns*: do_is(m, c) or do_is(low, high, vec)[.](#members-1.sentence-1)

[ð](#lib:ctype,scan_is)

`const charT* scan_is(mask m, const charT* low, const charT* high) const;
`

[2](#members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1427)

*Returns*: do_scan_is(m, low, high)[.](#members-2.sentence-1)

[ð](#lib:ctype,scan_not)

`const charT* scan_not(mask m, const charT* low, const charT* high) const;
`

[3](#members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1438)

*Returns*: do_scan_not(m, low, high)[.](#members-3.sentence-1)

[ð](#lib:ctype,toupper)

`charT        toupper(charT c) const;
const charT* toupper(charT* low, const charT* high) const;
`

[4](#members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1450)

*Returns*: do_toupper(c) or do_toupper(low, high)[.](#members-4.sentence-1)

[ð](#lib:ctype,tolower)

`charT        tolower(charT c) const;
const charT* tolower(charT* low, const charT* high) const;
`

[5](#members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1462)

*Returns*: do_tolower(c) or do_tolower(low, high)[.](#members-5.sentence-1)

[ð](#lib:ctype,widen)

`charT       widen(char c) const;
const char* widen(const char* low, const char* high, charT* to) const;
`

[6](#members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1474)

*Returns*: do_widen(c) or do_widen(low, high, to)[.](#members-6.sentence-1)

[ð](#lib:ctype,narrow)

`char         narrow(charT c, char dfault) const;
const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
`

[7](#members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1486)

*Returns*: do_narrow(c, dfault) or do_narrow(low, high, dfault, to)[.](#members-7.sentence-1)

#### [28.3.4.2.2.3](#virtuals) ctype virtual functions [[locale.ctype.virtuals]](locale.ctype.virtuals)

[ð](#lib:ctype,do_is)

`bool         do_is(mask m, charT c) const;
const charT* do_is(const charT* low, const charT* high, mask* vec) const;
`

[1](#virtuals-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1500)

*Effects*: Classifies a character or sequence of characters[.](#virtuals-1.sentence-1)

For each argument character,
identifies a value M of type ctype_base​::​mask[.](#virtuals-1.sentence-2)

The second form identifies a value M of type ctype_base​::​mask for each *p where (low <= p && p < high),
and places it into vec[p - low][.](#virtuals-1.sentence-3)

[2](#virtuals-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1509)

*Returns*: The first form returns the result of the expression (M & m) != 0;
i.e., true if the character has the characteristics specified[.](#virtuals-2.sentence-1)

The second form returns high[.](#virtuals-2.sentence-2)

[ð](#lib:ctype_base,do_scan_is)

`const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
`

[3](#virtuals-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1522)

*Effects*: Locates a character in a buffer that conforms to a classification m[.](#virtuals-3.sentence-1)

[4](#virtuals-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1526)

*Returns*: The smallest pointer p in the range [low, high)
such that is(m, *p) would return true;
otherwise, returns high[.](#virtuals-4.sentence-1)

[ð](#lib:ctype,do_scan_not)

`const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
`

[5](#virtuals-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1539)

*Effects*: Locates a character in a buffer that fails to conform to a classificationm[.](#virtuals-5.sentence-1)

[6](#virtuals-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1544)

*Returns*: The smallest pointer p, if any, in the range [low, high)
such that is(m, *p) would return false;
otherwise, returns high[.](#virtuals-6.sentence-1)

[ð](#lib:ctype,do_toupper)

`charT        do_toupper(charT c) const;
const charT* do_toupper(charT* low, const charT* high) const;
`

[7](#virtuals-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1558)

*Effects*: Converts a character or characters to upper case[.](#virtuals-7.sentence-1)

The second form replaces
each character *p in the range [low, high)
for which a corresponding upper-case character exists,
with that character[.](#virtuals-7.sentence-2)

[8](#virtuals-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1566)

*Returns*: The first form returns
the corresponding upper-case character if it is known to exist, or
its argument if not[.](#virtuals-8.sentence-1)

The second form returns high[.](#virtuals-8.sentence-2)

[ð](#lib:ctype,do_tolower)

`charT        do_tolower(charT c) const;
const charT* do_tolower(charT* low, const charT* high) const;
`

[9](#virtuals-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1581)

*Effects*: Converts a character or characters to lower case[.](#virtuals-9.sentence-1)

The second form replaces
each character *p in the range [low, high)
and for which a corresponding lower-case character exists,
with that character[.](#virtuals-9.sentence-2)

[10](#virtuals-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1589)

*Returns*: The first form returns
the corresponding lower-case character if it is known to exist, or
its argument if not[.](#virtuals-10.sentence-1)

The second form returns high[.](#virtuals-10.sentence-2)

[ð](#lib:ctype,do_widen)

`charT        do_widen(char c) const;
const char*  do_widen(const char* low, const char* high, charT* dest) const;
`

[11](#virtuals-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1604)

*Effects*: Applies the simplest reasonable transformation
from a char value or sequence of char values
to the corresponding charT value or values[.](#virtuals-11.sentence-1)[217](#footnote-217 "The parameter c of do_­widen is intended to accept values derived from character-literals for conversion to the locale's encoding.")

The only characters for which unique transformations are required
are those in the basic character set ([[lex.charset]](lex.charset "5.3.1 Character sets"))[.](#virtuals-11.sentence-2)

For any named ctype category with
a ctype<char> facet ctc and
valid ctype_base​::​mask value M,(ctc.​is(M, c) || !is(M, do_widen(c)) ) is true[.](#virtuals-11.sentence-3)[218](#footnote-218 "In other words, the transformed character is not a member of any character classification that c is not also a member of.")

The second form transforms
each character *p in the range [low, high),
placing the result in dest[p - low][.](#virtuals-11.sentence-4)

[12](#virtuals-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1631)

*Returns*: The first form returns the transformed value[.](#virtuals-12.sentence-1)

The second form returns high[.](#virtuals-12.sentence-2)

[ð](#lib:ctype,do_narrow)

`char         do_narrow(charT c, char dfault) const;
const charT* do_narrow(const charT* low, const charT* high, char dfault, char* dest) const;
`

[13](#virtuals-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1644)

*Effects*: Applies the simplest reasonable transformation
from a charT value or sequence of charT values
to the corresponding char value or values[.](#virtuals-13.sentence-1)

For any character c in the basic character set ([[lex.charset]](lex.charset "5.3.1 Character sets"))
the transformation is such thatdo_widen(do_narrow(c, 0)) == c

For any named ctype category with
a ctype<char> facet ctc however, andctype_base​::​mask value M,(is(M, c) || !ctc.is(M, do_narrow(c, dfault)) ) is true (unless do_narrow returns dfault)[.](#virtuals-13.sentence-3)

In addition, for any digit character c,
the expression (do_narrow(c, dfault) - '0') evaluates to the digit value of the character[.](#virtuals-13.sentence-4)

The second form transforms
each character *p in the range [low, high),
placing the result
(or dfault if no simple transformation is readily available)
in dest[p - low][.](#virtuals-13.sentence-5)

[14](#virtuals-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L1672)

*Returns*: The first form returns the transformed value;
or dfault if no mapping is readily available[.](#virtuals-14.sentence-1)

The second form returns high[.](#virtuals-14.sentence-2)

[217)](#footnote-217)[217)](#footnoteref-217)

The parameter c of do_widen is intended to
accept values derived from [*character-literal*](lex.ccon#nt:character-literal "5.13.3 Character literals [lex.ccon]")*s* for conversion to the locale's encoding[.](#footnote-217.sentence-1)

[218)](#footnote-218)[218)](#footnoteref-218)

In other words, the transformed character is not
a member of any character classification
that c is not also a member of[.](#footnote-218.sentence-1)
