• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <wctype.h>
2 #include <string.h>
3 
4 #define WCTYPE_ALNUM  1
5 #define WCTYPE_ALPHA  2
6 #define WCTYPE_BLANK  3
7 #define WCTYPE_CNTRL  4
8 #define WCTYPE_DIGIT  5
9 #define WCTYPE_GRAPH  6
10 #define WCTYPE_LOWER  7
11 #define WCTYPE_PRINT  8
12 #define WCTYPE_PUNCT  9
13 #define WCTYPE_SPACE  10
14 #define WCTYPE_UPPER  11
15 #define WCTYPE_XDIGIT 12
16 
iswctype(wint_t wc,wctype_t type)17 int iswctype(wint_t wc, wctype_t type)
18 {
19 	switch (type) {
20 	case WCTYPE_ALNUM:
21 		return iswalnum(wc);
22 	case WCTYPE_ALPHA:
23 		return iswalpha(wc);
24 	case WCTYPE_BLANK:
25 		return iswblank(wc);
26 	case WCTYPE_CNTRL:
27 		return iswcntrl(wc);
28 	case WCTYPE_DIGIT:
29 		return iswdigit(wc);
30 	case WCTYPE_GRAPH:
31 		return iswgraph(wc);
32 	case WCTYPE_LOWER:
33 		return iswlower(wc);
34 	case WCTYPE_PRINT:
35 		return iswprint(wc);
36 	case WCTYPE_PUNCT:
37 		return iswpunct(wc);
38 	case WCTYPE_SPACE:
39 		return iswspace(wc);
40 	case WCTYPE_UPPER:
41 		return iswupper(wc);
42 	case WCTYPE_XDIGIT:
43 		return iswxdigit(wc);
44 	}
45 	return 0;
46 }
47 
wctype(const char * s)48 wctype_t wctype(const char *s)
49 {
50 	int i;
51 	const char *p;
52 	/* order must match! */
53 	static const char names[] =
54 		"alnum\0" "alpha\0" "blank\0"
55 		"cntrl\0" "digit\0" "graph\0"
56 		"lower\0" "print\0" "punct\0"
57 		"space\0" "upper\0" "xdigit";
58 	for (i=1, p=names; *p; i++, p+=6)
59 		if (*s == *p && !strcmp(s, p))
60 			return i;
61 	return 0;
62 }
63 
__iswctype_l(wint_t c,wctype_t t,locale_t l)64 int __iswctype_l(wint_t c, wctype_t t, locale_t l)
65 {
66 	return iswctype(c, t);
67 }
68 
__wctype_l(const char * s,locale_t l)69 wctype_t __wctype_l(const char *s, locale_t l)
70 {
71 	return wctype(s);
72 }
73 
74 weak_alias(__iswctype_l, iswctype_l);
75 weak_alias(__wctype_l, wctype_l);
76