STD::CTYPE(3)

πŸ’– std::ctype< _CharT > πŸ’–

Library Functions Manual Β· section 3 β€” ok bestie, this is the big one, the primary class template ctype facet, and we are gonna get through it together 🫢


πŸŽ€ NAME πŸŽ€

std::ctype< _CharT > β€” the primary class template ctype facet. that's the whole vibe. it's the thing that knows what a letter is and what a digit is ✨


✨ SYNOPSIS ✨

#include <locale>

Inherits std::__ctype_abstract_base< _CharT >.

Inherited by std::ctype_byname< _CharT >.

πŸ¦‹ Public Types πŸ¦‹

  • typedef const int * __to_type
  • typedef _CharT char_type
  • typedef __ctype_abstract_base< _CharT >::mask mask

πŸ¦‹ Public Member Functions πŸ¦‹

  • ctype (size_t __refs=0)
  • const char_type * is (const char_type *__lo, const char_type *__hi, mask *__vec) const β€” hand you back a whole mask array, one entry per character.
  • bool is (mask __m, char_type __c) const β€” the vibe check: is this character that kind of character?
  • char narrow (char_type __c, char __dfault) const β€” squish a char_type down into a plain char.
  • const char_type * narrow (const char_type *__lo, const char_type *__hi, char __dfault, char *__to) const β€” squish a whole array of them into a char array.
  • const char_type * scan_is (mask __m, const char_type *__lo, const char_type *__hi) const β€” go find the first char_type that matches a mask.
  • const char_type * scan_not (mask __m, const char_type *__lo, const char_type *__hi) const β€” go find the first char_type that doesn't match a mask.
  • const char_type * tolower (char_type *__lo, const char_type *__hi) const β€” lowercase the whole array, glow-down ✨
  • char_type tolower (char_type __c) const β€” lowercase just one.
  • const char_type * toupper (char_type *__lo, const char_type *__hi) const β€” uppercase the whole array, RISE UP πŸ‘‘
  • char_type toupper (char_type __c) const β€” uppercase just one.
  • char_type widen (char __c) const β€” stretch a plain char out into a char_type.
  • const char * widen (const char *__lo, const char *__hi, char_type *__to) const β€” stretch a whole array out into char_type.

πŸ¦‹ Static Public Attributes πŸ¦‹

  • static const mask alnum
  • static const mask alpha
  • static const mask blank
  • static const mask cntrl
  • static const mask digit
  • static const mask graph
  • static locale::id id β€” the facet id for ctype<char_type>. it's giving identity, it's giving main character πŸŽ€
  • static const mask lower
  • static const mask print
  • static const mask punct
  • static const mask space
  • static const mask upper
  • static const mask xdigit

πŸ¦‹ Protected Member Functions πŸ¦‹

  • virtual const char_type * do_is (const char_type *__lo, const char_type *__hi, mask *__vec) const β€” return a mask array.
  • virtual bool do_is (mask __m, char_type __c) const β€” test char_type classification.
  • virtual char do_narrow (char_type, char __dfault) const β€” narrow char_type to char.
  • virtual const char_type * do_narrow (const char_type *__lo, const char_type *__hi, char __dfault, char *__to) const β€” narrow a char_type array to char.
  • virtual const char_type * do_scan_is (mask __m, const char_type *__lo, const char_type *__hi) const β€” find a char_type matching a mask.
  • virtual const char_type * do_scan_not (mask __m, const char_type *__lo, const char_type *__hi) const β€” find a char_type not matching a mask.
  • virtual const char_type * do_tolower (char_type *__lo, const char_type *__hi) const β€” convert array to lowercase.
  • virtual char_type do_tolower (char_type __c) const β€” convert to lowercase.
  • virtual const char_type * do_toupper (char_type *__lo, const char_type *__hi) const β€” convert array to uppercase.
  • virtual char_type do_toupper (char_type __c) const β€” convert to uppercase.
  • virtual char_type do_widen (char __c) const β€” widen char.
  • virtual const char * do_widen (const char *__lo, const char *__hi, char_type *__dest) const β€” widen a char array.

πŸ¦‹ Static Protected Member Functions πŸ¦‹

  • static __c_locale _S_clone_c_locale (__c_locale &__cloc) throw ()
  • static void _S_create_c_locale (__c_locale &__cloc, const char *__s, __c_locale __old=0)
  • static void _S_destroy_c_locale (__c_locale &__cloc)
  • static __c_locale _S_get_c_locale ()
  • static const char * _S_get_c_name () throw ()
  • static __c_locale _S_lc_ctype_c_locale (__c_locale __cloc, const char *__s)

🌸 Detailed Description 🌸

template<typename _CharT>
    class std::ctype< _CharT >"Primary class template ctype facet.

ok so listen πŸ‘‚ this template class defines the classification and conversion functions for character sets. it wraps cctype functionality. Ctype gets used by streams for so many I/O operations, like it's booked and busy.

This template provides the protected virtual functions the developer will have to replace in a derived class or specialization to make a working facet. The public functions that access them are defined in __ctype_abstract_base, to allow for implementation flexibility. See ctype<wchar_t> for an example. The functions are documented in __ctype_abstract_base.

Note: implementations are provided for all the protected virtual functions, but will likely not be useful. 😭 (not the default impls being mid, but here we are)

πŸ’… Member Function Documentation πŸ’…

template<typename _CharT> virtual const char_type * std::ctype< _CharT >::do_is (const char_type * __lo, const char_type * __hi, mask * __vec) const [protected], [virtual]

Return a mask array. This function finds the mask for each char_type in the range [lo,hi) and successively writes it to vec. vec must have as many elements as the input. πŸ”₯

do_is() is a hook for a derived facet to change the behavior of classifying. do_is() must always return the same result for the same input. (consistency bestie, we stan ✨)

Parameters

  • __lo β€” Pointer to start of range.
  • __hi β€” Pointer to end of range.
  • __vec β€” Pointer to an array of mask storage.

Returns

__hi.

Implements std::__ctype_abstract_base< _CharT >.


template<typename _CharT> virtual bool std::ctype< _CharT >::do_is (mask __m, char_type __c) const [protected], [virtual]

Test char_type classification. This function finds a mask M for c and compares it to mask m.

do_is() is a hook for a derived facet to change the behavior of classifying. do_is() must always return the same result for the same input.

Parameters

  • __c β€” The char_type to find the mask of.
  • __m β€” The mask to compare against.

Returns

(M & __m) != 0.

Implements std::__ctype_abstract_base< _CharT >.


template<typename _CharT> virtual char std::ctype< _CharT >::do_narrow (char_type __c, char __dfault) const [protected], [virtual]

Narrow char_type to char. This virtual function converts the argument to char using the simplest reasonable transformation. If the conversion fails, dfault is returned instead.

do_narrow() is a hook for a derived facet to change the behavior of narrowing. do_narrow() must always return the same result for the same input.

Note: this is not what you want for codepage conversions. See codecvt for that. 🫠 don't do it, bestie, that's a different department.

Parameters

  • __c β€” The char_type to convert.
  • __dfault β€” char to return if conversion fails.

Returns

The converted char.

Implements std::__ctype_abstract_base< _CharT >.

Referenced by std::ctype< char >::narrow(), and std::ctype< char >::narrow().


template<typename _CharT> virtual const char_type * std::ctype< _CharT >::do_narrow (const char_type * __lo, const char_type * __hi, char __dfault, char * __to) const [protected], [virtual]

Narrow char_type array to char. This virtual function converts each char_type in the range [__lo,__hi) to char using the simplest reasonable transformation and writes the results to the destination array. For any element in the input that cannot be converted, __dfault is used instead. πŸ’–

do_narrow() is a hook for a derived facet to change the behavior of narrowing. do_narrow() must always return the same result for the same input.

Note: this is not what you want for codepage conversions. See codecvt for that.

Parameters

  • __lo β€” Pointer to start of range.
  • __hi β€” Pointer to end of range.
  • __dfault β€” char to use if conversion fails.
  • __to β€” Pointer to the destination array.

Returns

__hi.

Implements std::__ctype_abstract_base< _CharT >.


template<typename _CharT> virtual const char_type * std::ctype< _CharT >::do_scan_is (mask __m, const char_type * __lo, const char_type * __hi) const [protected], [virtual]

Find char_type matching mask. This function searches for and returns the first char_type c in [__lo,__hi) for which is(__m,c) is true. πŸ”

do_scan_is() is a hook for a derived facet to change the behavior of match searching. do_is() must always return the same result for the same input.

Parameters

  • __m β€” The mask to compare against.
  • __lo β€” Pointer to start of range.
  • __hi β€” Pointer to end of range.

Returns

Pointer to a matching char_type if found, else __hi.

Implements std::__ctype_abstract_base< _CharT >.


template<typename _CharT> virtual const char_type * std::ctype< _CharT >::do_scan_not (mask __m, const char_type * __lo, const char_type * __hi) const [protected], [virtual]

Find char_type not matching mask. This function searches for and returns a pointer to the first char_type c of [lo,hi) for which is(m,c) is false. 🚫

do_scan_is() is a hook for a derived facet to change the behavior of match searching. do_is() must always return the same result for the same input.

Parameters

  • __m β€” The mask to compare against.
  • __lo β€” Pointer to start of range.
  • __hi β€” Pointer to end of range.

Returns

Pointer to a non-matching char_type if found, else __hi.

Implements std::__ctype_abstract_base< _CharT >.


template<typename _CharT> virtual const char_type * std::ctype< _CharT >::do_tolower (char_type * __lo, const char_type * __hi) const [protected], [virtual]

Convert array to lowercase. This virtual function converts each char_type in the range [__lo,__hi) to lowercase if possible. Other elements remain untouched. πŸ“

do_tolower() is a hook for a derived facet to change the behavior of lowercasing. do_tolower() must always return the same result for the same input.

Parameters

  • __lo β€” Pointer to start of range.
  • __hi β€” Pointer to end of range.

Returns

__hi.

Implements std::__ctype_abstract_base< _CharT >.


template<typename _CharT> virtual char_type std::ctype< _CharT >::do_tolower (char_type __c) const [protected], [virtual]

Convert to lowercase. This virtual function converts the argument to lowercase if possible. If not possible (for example, '2'), returns the argument. bestie a '2' is a '2', we can't lowercase it and that's fine πŸ™ˆ

do_tolower() is a hook for a derived facet to change the behavior of lowercasing. do_tolower() must always return the same result for the same input.

Parameters

  • __c β€” The char_type to convert.

Returns

The lowercase char_type if convertible, else __c.

Implements std::__ctype_abstract_base< _CharT >.

Referenced by std::ctype< char >::tolower(), and std::ctype< char >::tolower().

do_toupper β€” array edition πŸ’…

template<typename _CharT> virtual const char_type * std::ctype< _CharT >::do_toupper (char_type * __lo, const char_type * __hi) const

[protected], [virtual]

okay so this one converts every single char_type in the range [__lo,__hi) to uppercase if possible. Anything it can't convert just stays exactly as it was β€” no touchy. ✨

do_toupper() is a hook so a derived facet can change the behavior of uppercasing. And the rule? do_toupper() must always return the same result for the same input. no cap. πŸ”₯

Parameters

  • __lo β€” pointer to the start of the range.
  • __hi β€” pointer to the end of the range.

Returns

__hi.

Implements std::__ctype_abstract_base< _CharT >.


do_toupper β€” single char edition πŸŽ€

template<typename _CharT> virtual char_type std::ctype< _CharT >::do_toupper (char_type __c) const

[protected], [virtual]

Converts the char_type argument to uppercase if possible. If it's not possible (think '2'), it just hands the argument right back to you, unchanged. πŸ’–

Same deal as before: do_toupper() is a hook for a derived facet to change the behavior of uppercasing, and do_toupper() must always return the same result for the same input.

Parameters

  • __c β€” the char_type to convert.

Returns

The uppercase char_type if convertible, else __c.

Implements std::__ctype_abstract_base< _CharT >.

Referenced by std::ctype< char >::toupper(), and std::ctype< char >::toupper().

bestie it literally says the same referencer twice in the source. we don't make the rules πŸ’€

do_widen β€” one char in πŸ¦‹

template<typename _CharT> virtual char_type std::ctype< _CharT >::do_widen (char __c) const

[protected], [virtual]

Widening time! This virtual function converts the char to char_type using the simplest reasonable transformation.

do_widen() is a hook for a derived facet to change the behavior of widening, and do_widen() must always return the same result for the same input.

Note: this is not what you want for codepage conversions. See codecvt for that. πŸ™ˆ

Parameters

  • __c β€” the char to convert.

Returns

The converted char_type.

Implements std::__ctype_abstract_base< _CharT >.

Referenced by std::ctype< char >::widen(), and std::ctype< char >::widen().


do_widen β€” whole array 🌈

template<typename _CharT> virtual const char * std::ctype< _CharT >::do_widen (const char * __lo, const char * __hi, char_type * __to) const

[protected], [virtual]

Widen char array ✨ β€” this function converts each char in the input to char_type using the simplest reasonable transformation.

do_widen() is a hook for a derived facet to change the behavior of widening, and do_widen() must always return the same result for the same input.

Note: this is not what you want for codepage conversions. See codecvt for that. πŸ™ˆ

Parameters

  • __lo β€” pointer to start range.
  • __hi β€” pointer to end of range.
  • __to β€” pointer to the destination array.

Returns

__hi.

Implements std::__ctype_abstract_base< _CharT >.


is β€” mask array version πŸ‘‘

template<typename _CharT> const char_type * std::__ctype_abstract_base< _CharT >::is (const char_type * __lo, const char_type * __hi, mask * __vec) const

[inline], [inherited]

Return a mask array. This function finds the mask for each char_type in the range [lo,hi) and successively writes it to vec. Important: vec must have as many elements as the char array. It does all this by returning the value of ctype<char_type>::do_is().

Parameters

  • __lo β€” pointer to start of range.
  • __hi β€” pointer to end of range.
  • __vec β€” pointer to an array of mask storage.

Returns

__hi.


is β€” single char check πŸ’œ

template<typename _CharT> bool std::__ctype_abstract_base< _CharT >::is (mask __m, char_type __c) const

[inline], [inherited]

Test char_type classification, bestie. This function finds a mask M for __c and compares it to mask __m. It does so by returning the value of ctype<char_type>::do_is().

Parameters

  • __c β€” the char_type to compare the mask of.
  • __m β€” the mask to compare against.

Returns

(M & __m) != 0.

Referenced by std::time_get< _CharT, _InIter >::get().


narrow β€” single char down to char 🌸

template<typename _CharT> char std::__ctype_abstract_base< _CharT >::narrow (char_type __c, char __dfault) const

[inline], [inherited]

Narrow char_type to char. This function converts the char_type to char using the simplest reasonable transformation. If the conversion fails, dfault is returned instead. It does so by returning ctype<char_type>::do_narrow(__c).

Note: this is not what you want for codepage conversions. See codecvt for that. πŸ™ˆ

Parameters

  • __c β€” the char_type to convert.
  • __dfault β€” char to return if conversion fails.

Returns

The converted char.

Referenced by std::time_get< _CharT, _InIter >::do_get_year(), std::time_get< _CharT, _InIter >::get(), and std::time_put< _CharT, _OutIter >::put().


narrow β€” whole array edition 🧚

template<typename _CharT> const char_type * std::__ctype_abstract_base< _CharT >::narrow (const char_type * __lo, const char_type * __hi, char __dfault, char * __to) const

[inline], [inherited]

Narrow array to char array. This function converts each char_type in the input to char using the simplest reasonable transformation and writes the results to the destination array. For any char_type in the input that cannot be converted, dfault is used instead. It does so by returning ctype<char_type>::do_narrow(__lo, __hi, __dfault, __to).

Note: this is not what you want for codepage conversions. See codecvt for that. πŸ™ˆ

Parameters

  • __lo β€” pointer to start of range.
  • __hi β€” pointer to end of range.
  • __dfault β€” char to use if conversion fails.
  • __to β€” pointer to the destination array.

Returns

__hi.


scan_is β€” find the first match πŸ”

template<typename _CharT> const char_type * std::__ctype_abstract_base< _CharT >::scan_is (mask __m, const char_type * __lo, const char_type * __hi) const

[inline], [inherited]

Find char_type matching a mask. This function searches for and returns the first char_type c in [lo,hi) for which is(m,c) is true. It does so by returning ctype<char_type>::do_scan_is().

Parameters

  • __m β€” the mask to compare against.
  • __lo β€” pointer to start of range.
  • __hi β€” pointer to end of range.

Returns

Pointer to matching char_type if found, else __hi.


scan_not β€” find the first non-match πŸ™…

template<typename _CharT> const char_type * std::__ctype_abstract_base< _CharT >::scan_not (mask __m, const char_type * __lo, const char_type * __hi) const

[inline], [inherited]

Find char_type not matching a mask. This function searches for and returns the first char_type c in [lo,hi) for which is(m,c) is false. It does so by returning ctype<char_type>::do_scan_not().

Parameters

  • __m β€” the mask to compare against.
  • __lo β€” pointer to first char in range.
  • __hi β€” pointer to end of range.

Returns

Pointer to non-matching char if found, else __hi.


tolower β€” array edition πŸ“

template<typename _CharT> const char_type * std::__ctype_abstract_base< _CharT >::tolower (char_type * __lo, const char_type * __hi) const

[inline], [inherited]

Convert array to lowercase. This function converts each char_type in the range [__lo,__hi) to lowercase if possible. Other elements remain untouched. It does so by returning ctype<char_type>:: do_tolower(__lo, __hi).

Parameters

  • __lo β€” pointer to start of range.
  • __hi β€” pointer to end of range.

Returns

__hi.


tolower β€” single char 🌱

template<typename _CharT> char_type std::__ctype_abstract_base< _CharT >::tolower (char_type __c) const

[inline], [inherited]

Convert to lowercase. This function converts the argument to lowercase if possible. If not possible (for example, '2'), it returns the argument. It does so by returning ctype<char_type>::do_tolower(c).

Parameters

  • __c β€” the char_type to convert.

Returns

The lowercase char_type if convertible, else __c.

Referenced by std::time_get< _CharT, _InIter >::get().


toupper β€” array edition ⬆️

template<typename _CharT> const char_type * std::__ctype_abstract_base< _CharT >::toupper (char_type * __lo, const char_type * __hi) const

[inline], [inherited]

Convert array to uppercase. This function converts each char_type in the range [lo,hi) to uppercase if possible. Other elements remain untouched. It does so by returning ctype<char_type>:: do_toupper(lo, hi).

Parameters

  • __lo β€” pointer to start of range.
  • __hi β€” pointer to end of range.

Returns

__hi.


toupper β€” single char πŸ†™

template<typename _CharT> char_type std::__ctype_abstract_base< _CharT >::toupper (char_type __c) const

[inline], [inherited]

Convert to uppercase. This function converts the argument to uppercase if possible. If not possible (for example, '2'), it returns the argument. It does so by returning ctype<char_type>::do_toupper().

Parameters

  • __c β€” the char_type to convert.

Returns

The uppercase char_type if convertible, else __c.

Referenced by std::time_get< _CharT, _InIter >::get().


widen β€” one char up 🫢

template<typename _CharT> char_type std::__ctype_abstract_base< _CharT >::widen (char __c) const

[inline], [inherited]

Widen char to char_type. This function converts the char argument to char_type using the simplest reasonable transformation. It does so by returning ctype<char_type>::do_widen(c).

Note: this is not what you want for codepage conversions. See codecvt for that. πŸ™ˆ

Parameters

  • __c β€” the char to convert.

Returns

The converted char_type.

Referenced by std::money_get< _CharT, _InIter >::do_get(), std::time_get< _CharT, _InIter >::do_get(), std::money_put< _CharT, _OutIter >::do_put(), and std::time_put< _CharT, _OutIter >::do_put().


widen β€” whole array, go 🌟

template<typename _CharT> const char * std::__ctype_abstract_base< _CharT >::widen (const char * __lo, const char * __hi, char_type * __to) const

[inline], [inherited]

Widen array to char_type. This function converts each char in the input to char_type using the simplest reasonable transformation. It does so by returning ctype<char_type>::do_widen(c).

Note: this is not what you want for codepage conversions. See codecvt for that. πŸ™ˆ

Parameters

  • __lo β€” pointer to start of range.
  • __hi β€” pointer to end of range.
  • __to β€” pointer to the destination array.

Returns

__hi.


Member Data Documentation 🌈

id β€” the facet id πŸ’…

template<typename _CharT> locale::id std::ctype< _CharT >::id

[static]

The facet id for ctype<char_type>. That's it, that's the whole vibe check. ⭐


Author ✍️

Generated automatically by Doxygen for libstdc++ from the source code.


okay bestie that's the whole page πŸ’– this one came straight out of the libstdc++ docs β€” it's page std::ctype< _CharT >(3) in the libstdc++ manual, so if you ever need to cite it, that's the flex. go convert some chars, you're doing amazing πŸŽ€βœ¨πŸ‘‘

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms