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