Team LiB   Previous Section   Next Section

13.21 <cwctype>

The <cwctype> header is the C++ version of the C standard <wctype.h> header, which declares types and functions for classifying and converting wide characters.

Most of the functions in this header are wide equivalents of functions found in <cctype>. For example, iswalnum determines whether a wide character is alphanumeric, just as isalnum determines whether a narrow (byte) character is alphanumeric. The behavior of the wide functions is similar to their narrow equivalents. In particular, for any narrow character c, its wide character equivalent wc, and classification functions isxyz and iswxyx, if isxyz(c) is true, then iswxyz(wc) is true and vice versa. The only exception is that iswgraph and iswpunct behave slightly differently than isgraph and ispunct for whitespace characters other than ' '.

The behavior of the <cwctype> functions depend on the C locale, as set with the setlocale function in <clocale>. For more flexibility in dealing with multiple locales, you can use C++ locales, in particular the ctype facet in <locale>.

iswalnum function Determines whether a wide character is alphanumeric

int iswalnum(wint_t wc)

The iswalnum function returns true (nonzero) if either iswalpha(wc) or iswdigit(wc) is true.

See Also

iswalpha function, iswdigit function, isalnum in <cctype>

iswalpha function Determines whether a wide character is alphabetic

int iswalpha(wint_t wc)

The iswalpha function returns true (nonzero) if wc is an alphabetic character, that is, a wide character for which iswcntrl, iswdigit, iswpunct, and iswspace all return false (0).

See Also

iswcntrl function, iswdigit function, iswpunct function, iswspace function, isalpha in <cctype>

iswcntrl function Determines whether a wide character is a control character

int iswcntrl(wint_t wc)

The iswcntrl function returns true (nonzero) if wc is a wide control character, that is, a wide character for which iswalnum, iswpunct, and iswspace all return false (0).

See Also

iswalnum function, iswpunct function, iswspace function, iscntrl in <cctype>

iswctype function Tests any category of a wide character

int iswctype(wint_t wc, wctype_t desc)

The iswctype function tests any category of the wide character wc. The category to test is specified by desc, which must be obtained by calling wctype. The setting of the LC_CTYPE category must be the same for the call to iswctype and the call to wctype that returned desc.

Using iswctype, you can implement all the isw . . . functions. For example, you can implement the iswalnum function as follows:

int iswalnum(wint_t wc)
{
  return std::iswctype(wc, std::wctype("alnum"));
}

See Also

wctype function, wctype_t type

iswdigit function Determines whether a wide character is a digit

int iswdigit(wint_t wc)

The iswdigit function returns true (nonzero) if wc is a decimal digit character—that is, '0'-'9'—regardless of locale.

See Also

iswxdigit function, isdigit in <cctype>

iswgraph function Determines whether a wide character is graphic

int iswgraph(wint_t wc)

The iswgraph function returns true (nonzero) if iswprint(wc) is true and iswspace(wc) is false. Note that iswgraph is slightly different from isgraph in that it returns true for whitespace characters other than ' '.

See Also

iswprint function, iswspace function

iswlower function Determines whether a wide character is lowercase

int iswlower(wint_t wc)

The iswlower function returns true (nonzero) if wc is a lowercase character.

See Also

iswalpha function, iswupper function, towlower function, islower in <cctype>

iswprint function Determines whether a wide character is printable

int iswprint(wint_t wc)

The iswprint function returns true (nonzero) if wc is a printable wide character.

See Also

iswgraph function, isprint in <cctype>

iswpunct function Determines whether a wide character is punctuation

int iswpunct(wint_t wc)

The iswpunct function returns true (nonzero) if iswalnum(wc), iswcntrl(wc), and iswspace(wc) are false.

See Also

iswalnum function, iswcntrl function, iswspace function, ispunct in <cctype>

iswspace function Determines whether a wide character is whitespace

int iswspace(wint_t wc)

The iswspace function returns true (nonzero) if wc is a whitespace character.

See Also

iswgraph function, iswprint function, isspace in <cctype>

iswupper function Determines whether a wide character is uppercase

int iswupper(wint_t wc)

The iswupper function returns true (nonzero) if wc is an uppercase character.

See Also

iswalpha function, iswlower function, towupper function, isupper in <cctype>

iswxdigit function Determines whether a wide character is a hexadecimal digit

int iswxdigit(wint_t wc)

The iswxdigit function returns true (nonzero) if wc is a hexadecimal digit character—that is, '0'-'9', 'a'-'f', or 'A'-'F'—regardless of locale.

See Also

iswdigit function, isxdigit in <cctype>

towctrans function Translates a wide character's case

wint_t towctrans(wint_t wc, wctrans_t desc)

The towctrans function translates the wide character wc according to the description desc, which was returned from the wctrans function. For example, the towlower function can be implemented using towctrans:

wint_t towlower(wint_t wc)
{
  return std::towctrans(wc, std::wctrans("tolower"));
}

See Also

wctrans function, wctrans_t type

towlower function Converts a wide character to lowercase

wint_t towlower(wint_t wc)

The towlower function maps the wide character wc to lowercase. If iswupper(wc) is false, or if wc has no lowercase mapping, wc is returned unchanged.

See Also

towctrans function, towupper function, tolower in <cctype>

towupper function Converts a wide character to uppercase

wint_t towupper(wint_t wc)

The towupper function maps the wide character wc to uppercase. If iswlower(wc) is false, or if wc has no uppercase mapping, wc is returned unchanged.

See Also

towctrans function, towlower function, toupper in <cctype>

wctrans function Construct a wctrans_t object

wctrans_t wctrans(const char* property)

The wctrans function constructs a wctrans_t object according to the given property. Table 13-7 lists the properties defined in the standard.

Table 13-7. Character translation properties

Property

Description

"tolower"

Maps from uppercase to lowercase

"toupper"

Maps from lowercase to uppercase

See Also

towctrans function, wctrans_t type

wctrans_t type Represents a wide character translation

typedef  . . .  wctrans_t

The wctrans_t type is a scalar type used to represent character mappings for the towctrans function.

See Also

towctrans function, wctrans function, <clocale>

wctype function Constructs a wctype_t object

wctype_t wctype(const char* property)

The wctype function constructs a wctype_t object that describes wide characters that have the given property. Table 13-8 lists the properties that are supported by this standard.

Table 13-8. Character classification properties

Property

Description

"alnum"

Alphanumeric

"alpha"

Alphabetic

"cntrl"

Control

"digit"

Digit

"graph"

Non-space printable

"lower"

Lowercase

"print"

Printable or whitespace

"punct"

Punctuation

"space"

Whitespace

"upper"

Uppercase

"xdigit"

Hexadecimal digit

See Also

iswctype function, wctype_t type, <clocale>

wctype_t type Represents a character classification

typedef  . . .  wctype_t

The wctype_t type is a scalar type used to represent character classifications for the iswctype function.

See Also

iswctype function, wctype function, <clocale>

WEOF macro End-of-file or error

wint_t WEOF

The WEOF macro expands to a constant integer value that does not correspond to any valid wide character value. Unlike EOF, WEOF is not guaranteed to be negative.

See Also

WEOF in <cwchar>, EOF in <cstdio>

wint_t type Integer representation of a wide character

typedef  . . .  wint_t

The wint_t type is an integral type that represents wide characters. It can hold the value for any character in the extended character set plus the value WEOF.

See Also

wint_t in <cwchar>

    Team LiB   Previous Section   Next Section