wctype() — Get Handle for Character Property Classification

Format

#include <wctype.h>
wctype_t wctype(const char *property);

Language Level: XPG4

Threadsafe: Yes.

Description

The wctype() function is defined for valid character class names. The property is a string that identifies a generic character class. These character class names are defined in all locales: alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit. The function returns a value of type wctype_t, which can be used as the second argument to a call of the iswctype() function.

The wctype() function determines values of wctype_t according to rules of the coded character set that are defined by character type information in the program's locale (category LC_CTYPE). Values that are returned by the wctype() are valid until a call to setlocale() that changes the category LC_CTYPE.

Return Value

The wctype() function returns zero if the given property name is not valid. Otherwise, it returns a value of type wctype_t that can be used in calls to iswctype().

Example that uses wctype()

#include <wchar.h>
 
#define   UPPER_LIMIT   0xFF
      int   main(void)
      {
         int   wc;
         for   (wc   =   0;   wc  <=   UPPER_LIMIT;   wc++)   {
            printf("%#4x ",   wc);
            printf("%c",   iswctype(wc,   wctype("print"))  ?   wc    : "
");
            printf("%s",   iswctype(wc,   wctype("alnum"))  ?   "AN"  : "
");
            printf("%s",   iswctype(wc,   wctype("alpha"))  ?   "A"   : "
");
            printf("%s",   iswctype(wc,   wctype("blank"))  ?   "B"   : "
");
            printf("%s",   iswctype(wc,   wctype("cntrl"))  ?   "C"   : "
");
            printf("%s",   iswctype(wc,   wctype("digit"))  ?   "D"   : "
");
            printf("%s",   iswctype(wc,   wctype("graph"))  ?   "G"   : "
");
            printf("%s",   iswctype(wc,   wctype("lower"))  ?   "L"   : "
");
            printf("%s",   iswctype(wc,   wctype("punct"))  ?   "PU"  : "
");
            printf("%s",   iswctype(wc,   wctype("space"))  ?   "S"   : "
");
            printf("%s",   iswctype(wc,   wctype("print"))  ?   "PR"  : "
");
            printf("%s",   iswctype(wc,   wctype("upper"))  ?   "U"   : "
");
            printf("%s",   iswctype(wc,   wctype("xdigit")) ?   "X"   : "
");
            putchar('\n');
         }
         return   0;
        /***********************************************************************
            The   output   should   be   similar   to   :
             :
            0x1f              C
            0x20           B                   S    PR
            0x21   !                  G       PU      PR
            0x22   "                  G       PU      PR
            0x23   #                  G       PU      PR
            0x24   $                  G       PU      PR
            0x25   %                  G       PU      PR
            0x26   &                  G       PU      PR
            0x27   '                  G       PU      PR
            0x28   (                  G       PU      PR
            0x29   )                  G       PU      PR
            0x2a   *                  G       PU      PR
            0x2b   +                  G       PU      PR
            0x2c   ,                   G       PU      PR
            0x2d   -                  G       PU      PR
            0x2e   .                   G       PU      PR
            0x2f   /                   G       PU      PR
            0x30   0   AN            D    G             PR      X
            0x31   1   AN            D    G             PR      X
            0x32   2   AN            D    G             PR      X
            0x33   3   AN            D    G             PR      X
            0x34   4   AN            D    G             PR      X
            0x35   5   AN            D    G             PR      X
             :
         ***********************************************************************
      }

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]