Chapter Contents

Previous

Next
Function Categories

New Wide Character Type Macros and Functions

The standard wide character header file <wctype.h> defines three data types and numerous macros and functions that are useful in the analysis of text that contain extended or wide (2 byte) character data.

The three data types declared are wint_t, wctrans_t, and wctype_t. The type wint_t is an integer type that can hold any valid wide character (of type wchar_t) as well as the value of the macro WEOF. The type wctrans_t is a scalar type that can hold values that represent locale-specific character mappings. The type wctype_t is a scalar type that can hold values that represent locale-specific character classifications.

Also defined in the header file <wctype.h> is the macro WEOF. This macro expands to a constant value of type wint_t, which does not correspond to any valid member of the wide character set. It is accepted and returned by several of the functions (or macros) defined in the header file and is used to indicate an error condition.

The wide character classification functions (i.e., the iswXXX functions) and the case mapping functions (that is, the towupper and towlower functions) are defined in the header file as macros. Therefore, one should always include this header if one uses any of these macros; otherwise, the compiler will generate a reference to a function of the same name, which can degrade performance.

The results produced by the functions in all four groups are affected by the current locale's LC_CTYPE category, which may cause a different character type array to be used than the one supplied for the default C locale. And for those functions (or macros) that accept an argument of type wint_t, the argument has to be representable as a valid wide character (that is, of type wchar_t) or have the value of WEOF. Otherwise, its behavior is undefined.

Wide Character Type Macros and Functions and Their Return Values lists the functions (or macros) defined in the <wctype.h> header file. These functions (or macros) can be classified into the following four groups:

Each of these groups is discussed in one of the following sections.


Functions That Provide Wide Character Classification

The following functions provide wide character classification:
iswalnum alphanumeric wide character test
iswalpha alphabetic wide character test
iswcntrl alphabetic wide character test
iswctype wide character attribute test
iswdigit numeric character test
iswgraph graphic wide character test
iswlower lowercase alphabetic character test
iswprint printing character test
iswpunct punctuation test
iswspace whitespace test
iswupper uppercase alphabetic character test
iswxdigit hexadecimal digit test

These classification functions are closely related to the corresponding byte classification functions (that is, the isXXX functions) declared in the header <ctype.h>. These functions return nonzero (true) only if the value of their argument conforms to the specifications stated in the description of the function.


Extensible Functions That Provide Wide Character Classification

The following extensible functions provide wide character classification:
wctype construct wide character property
iswctype wide character attribute test

These extensible functions provide the testing equivalent of the standard wide character classification functions described above. That is, each of the following expressions return true:

( iswctype(wc, wctype("alnum")) == iswalnum(wc) )
( iswctype(wc, wctype("alpha")) == iswalpha(wc) )
( iswctype(wc, wctype("cntrl")) == iswcntrl(wc) )
( iswctype(wc, wctype("digit")) == iswdigit(wc) )
( iswctype(wc, wctype("graph")) == iswgraph(wc) )
( iswctype(wc, wctype("lower")) == iswlower(wc) )
( iswctype(wc, wctype("print")) == iswprint(wc) )
( iswctype(wc, wctype("punct")) == iswpunct(wc) )
( iswctype(wc, wctype("space")) == iswspace(wc) )
( iswctype(wc, wctype("upper")) == iswupper(wc) )
( iswctype(wc, wctype("xdigit")) == iswxdigit(wc) )

These functions also provide the SAS/C Library a standard mechanism to create additional classification functions in the future.


Functions That Provide Wide Character Case Mapping

The following functions provide wide character case mapping:
towlower convert uppercase wide character to wide lowercase.
towupper convert lowercase wide character to wide uppercase.

Each of these functions convert or map the case of a wide character. Each returns its argument unchanged if it does not qualify for the conversion.


Extensible Functions That Provide Wide Character Mapping

The following extensible functions provide wide character mapping:
towctrans wide character mapping
wctrans construct wide character property mapping

These functions also provide the SAS/C Library a standard mechanism to create additional mapping functions in the future.


Wide Character Type Macros and Functions and Their Return Values

Wide Character Type Macros and Functions and Their Return Values
Function
iswalnum(wc)
iswalpha(wc)
iswcntrl(wc)
iswctype(wc,desc)
iswdigit(wc)
iswgraph(wc)
iswlower(wc)
iswprint(wc)
iswpunct(wc)
iswspace(wc)
iswupper(wc)
iswxdigit(wc)
towctrans(wc, desc)
towlower(wc)
towupper(wc)
wctrans(property)
wctype(property)


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.