Next: Using Wide Char Classes, Previous: Case Conversion, Up: Character Handling
Amendment 1 to ISO C90 defines functions to classify wide
characters. Although the original ISO C90 standard already defined
the type wchar_t
, no functions operating on them were defined.
The general design of the classification functions for wide characters
is more general. It allows extensions to the set of available
classifications, beyond those which are always available. The POSIX
standard specifies how extensions can be made, and this is already
implemented in the GNU C library implementation of the localedef
program.
The character class functions are normally implemented with bitsets, with a bitset per character. For a given character, the appropriate bitset is read from a table and a test is performed as to whether a certain bit is set. Which bit is tested for is determined by the class.
For the wide character classification functions this is made visible.
There is a type classification type defined, a function to retrieve this
value for a given class, and a function to test whether a given
character is in this class, using the classification value. On top of
this the normal character classification functions as used for
char
objects can be defined.
The
wctype_t
can hold a value which represents a character class. The only defined way to generate such a value is by using thewctype
function.
The
wctype
returns a value representing a class of wide characters which is identified by the string property. Beside some standard properties each locale can define its own ones. In case no property with the given name is known for the current locale selected for theLC_CTYPE
category, the function returns zero.The properties known in every locale are:
"alnum"
"alpha"
"cntrl"
"digit"
"graph"
"lower"
"print"
"punct"
"space"
"upper"
"xdigit"
To test the membership of a character to one of the non-standard classes the ISO C standard defines a completely new function.
This function returns a nonzero value if wc is in the character class specified by desc. desc must previously be returned by a successful call to
wctype
.
To make it easier to use the commonly-used classification functions,
they are defined in the C library. There is no need to use
wctype
if the property string is one of the known character
classes. In some situations it is desirable to construct the property
strings, and then it is important that wctype
can also handle the
standard classes.
This function returns a nonzero value if wc is an alphanumeric character (a letter or number); in other words, if either
iswalpha
oriswdigit
is true of a character, theniswalnum
is also true.This function can be implemented using
iswctype (wc, wctype ("alnum"))
Returns true if wc is an alphabetic character (a letter). If
iswlower
oriswupper
is true of a character, theniswalpha
is also true.In some locales, there may be additional characters for which
iswalpha
is true—letters which are neither upper case nor lower case. But in the standard"C"
locale, there are no such additional characters.This function can be implemented using
iswctype (wc, wctype ("alpha"))
Returns true if wc is a control character (that is, a character that is not a printing character).
This function can be implemented using
iswctype (wc, wctype ("cntrl"))
Returns true if wc is a digit (e.g., `0' through `9'). Please note that this function does not only return a nonzero value for decimal digits, but for all kinds of digits. A consequence is that code like the following will not work unconditionally for wide characters:
n = 0; while (iswdigit (*wc)) { n *= 10; n += *wc++ - L'0'; }This function can be implemented using
iswctype (wc, wctype ("digit"))
Returns true if wc is a graphic character; that is, a character that has a glyph associated with it. The whitespace characters are not considered graphic.
This function can be implemented using
iswctype (wc, wctype ("graph"))
Returns true if wc is a lower-case letter. The letter need not be from the Latin alphabet, any alphabet representable is valid.
This function can be implemented using
iswctype (wc, wctype ("lower"))
Returns true if wc is a printing character. Printing characters include all the graphic characters, plus the space (` ') character.
This function can be implemented using
iswctype (wc, wctype ("print"))
Returns true if wc is a punctuation character. This means any printing character that is not alphanumeric or a space character.
This function can be implemented using
iswctype (wc, wctype ("punct"))
Returns true if wc is a whitespace character. In the standard
"C"
locale,iswspace
returns true for only the standard whitespace characters:
L' '
- space
L'\f'
- formfeed
L'\n'
- newline
L'\r'
- carriage return
L'\t'
- horizontal tab
L'\v'
- vertical tab
This function can be implemented using
iswctype (wc, wctype ("space"))
Returns true if wc is an upper-case letter. The letter need not be from the Latin alphabet, any alphabet representable is valid.
This function can be implemented using
iswctype (wc, wctype ("upper"))
Returns true if wc is a hexadecimal digit. Hexadecimal digits include the normal decimal digits `0' through `9' and the letters `A' through `F' and `a' through `f'.
This function can be implemented using
iswctype (wc, wctype ("xdigit"))
The GNU C library also provides a function which is not defined in the ISO C standard but which is available as a version for single byte characters as well.