Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

ctype

Library:  Localization


ctype_base ctype ... locale::facet

Local Index

Members

Summary

A facet that includes character classification facilities.

Synopsis

#include <locale>

namespace std {
  class ctype_base;
  template <class charT> class ctype;
}

Specializations

  template <> class ctype<char>; 
  template <> class ctype<wchar_t>;

Description

The class template ctype is a facet that allows you to classify characters and perform simple conversions. ctype also converts upper to lower and lower to upper case, and converts between charT and char. ctype relies on ctype_base for a set of masks that classify the different kinds of characters. The masks are illustrated in Table 17.

Table 17: Ctype masks provided by ctype_base

Class Description Characters included in the classic C locale

alnum

Characters classified as letters or digits.

All of alpha and digit.

alpha

Characters classified as letters.

All of lower and upper.

cntrl

Characters classified as control characters.

None of alpha or print.

digit

Characters classified as decimal digits.

The characters '0' through '9'.

graph

Characters classified as printable characters, excluding the space (' ').

All of alpha, digit, and punct, and none of cntrl.

lower

Characters classified as lowercase letters.

The characters 'a' through 'z'.

print

Characters classified as printable characters, including the space (' ').

The space (' '), all of graph, and none of cntrl.

punct

Characters classified as punctuators.

Neither the space (' ') character, nor any of alpha, digit, or cntrl.

space

Characters classified as whitespace.

The space (' '), form-feed ('\f'), new line ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') characters.

upper

Characters classified as uppercase letters.

The characters 'A' through 'Z'.

xdigit

Characters classified as hexadecimal digits.

The characters 'A' through 'F', 'a' through 'f', and all of digit.

The masks are passed to member functions of ctype to obtain the classifications of a character or range of characters.

Interface

Member Type

char_type

Constructor

explicit ctype(size_t refs = 0) 
explicit ctype(const mask* tab = 0, bool del = false, size_t
               refs = 0);

Destructor

virtual ~ctype();

Public Member Functions

The public members of the ctype facet include an interface to protected members. Each public member function xxx() calls the corresponding protected virtual member function do_xxx(). For instance, the public widen() function calls its protected cousin do_widen(). The result of the call may be cached. Subsequent calls to the public function may return the cached result to avoid the expense of repeatedly calling the virtual function. The public interface to the protected virtual functions is provided in order to allow derived classes to override some but not necessarily all of the often overloaded virtual functions without hiding those overloads that are not overridden.

When (static_cast<unsigned char>(c) >= table_size), member functions of the ctype<char> specialization do not use table() to perform the lookup of the character mask, but instead use an unspecified algorithm to obtain its value.

bool         
is(mask m, char_type c) const; 
const char_type* 
is(const char_type* low, 
   const char_type* high, mask* vec) const;
char
narrow(char_type c, char dfault) const;
const char_type* 
narrow(const char_type* low, const char_type*, char dfault,
       char* to) const; 
const char_type* 
scan_is(mask m, const char_type*, const char_type* high)
        const; 
const char_type* 
scan_not(mask m, const char_type* low, const char_type* high)
         const; 
char_type        
tolower(char_type c) const;
const char_type* 
tolower(char_type* low, const char_type* high) const; 
char_type        
toupper(char_type c) const;
const char_type* 
toupper(char_type* low, const char_type* high) const; 
char_type        
widen(char c) const;
const char*  
widen(const char* low, const char* high, char_type* to) const; 
const mask*
table() const throw();

Facet ID

static locale::id id;

Protected Member Functions

static const mask*
classic_table() throw();
virtual bool         
do_is(mask m, char_type c) const; 
virtual const char_type* 
do_is(const char_type* low, const char_type* high,
      mask* vec) const; 
virtual char
do_narrow(char_type c, char dfault) const; 
virtual const char_type* 
do_narrow(const char_type* low, const char_type* high,
          char dfault, char* dest) const; 
virtual const char_type* 
do_scan_is(mask m, const char_type* low, const char_type*
           high) const; 
virtual const char_type* 
do_scan_not(mask m, const char_type* low, 
            const charT* high) const;
virtual char_type        
do_tolower(char_type c) const; 
virtual const char_type* 
do_tolower(char_type* low, const char_type* high) const; 
virtual char_type       
do_toupper(char_type c) const; 
virtual const char_type* 
do_toupper(char_type* low, const char_type* high) const; 
virtual char_type        
do_widen(char c) const; 
virtual const char*  
do_widen(const char* low, const char* high, 
         char_type* dest) const; 

Example

See Also

locale, Facets, collate, ctype_byname

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 22.2.1.1



Previous fileTop of DocumentContentsIndex pageNext file