• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 /*
7   wctype.c
8   7.25.2.2.2 The wctype function
9 
10   Contributed by: Danny Smith  <dannysmith@usesr.sourcefoge.net>
11 		  2005-02-24
12 
13   This source code is placed in the PUBLIC DOMAIN. It is modified
14   from the Q8 package created by Doug Gwyn <gwyn@arl.mil>
15 
16   The wctype function constructs a value with type wctype_t that
17   describes a class of wide characters identified by the string
18   argument property.
19 
20   In particular, we map the property strings so that:
21 
22   iswctype(wc, wctype("alnum")) == iswalnum(wc)
23   iswctype(wc, wctype("alpha")) == iswalpha(wc)
24   iswctype(wc, wctype("cntrl")) == iswcntrl(wc)
25   iswctype(wc, wctype("digit")) == iswdigit(wc)
26   iswctype(wc, wctype("graph")) == iswgraph(wc)
27   iswctype(wc, wctype("lower")) == iswlower(wc)
28   iswctype(wc, wctype("print")) == iswprint(wc)
29   iswctype(wc, wctype("punct")) == iswpunct(wc)
30   iswctype(wc, wctype("space")) == iswspace(wc)
31   iswctype(wc, wctype("upper")) == iswupper(wc)
32   iswctype(wc, wctype("xdigit")) == iswxdigit(wc)
33 
34 */
35 
36 #include	<string.h>
37 #include	<wctype.h>
38 
39 /* Using the bit-OR'd ctype character classification flags as return
40    values achieves compatibility with MS iswctype().  */
41 static const struct {
42   const char *name;
43   wctype_t flags;} cmap[] = {
44     {"alnum", _ALPHA|_DIGIT},
45     {"alpha", _ALPHA},
46     {"cntrl", _CONTROL},
47     {"digit", _DIGIT},
48     {"graph", _PUNCT|_ALPHA|_DIGIT},
49     {"lower", _LOWER},
50     {"print", _BLANK|_PUNCT|_ALPHA|_DIGIT},
51     {"punct", _PUNCT},
52     {"space", _SPACE},
53     {"upper", _UPPER},
54     {"xdigit", _HEX}
55   };
56 
57 #define NCMAP	(sizeof cmap / sizeof cmap[0])
wctype(const char * property)58 wctype_t wctype (const char *property)
59 {
60   int i;
61   for (i = 0; i < (int) NCMAP; ++i)
62     if (strcmp (property, cmap[i].name) == 0)
63       return cmap[i].flags;
64   return 0;
65 }
66