6 static void report_error(const char *class, int ch
)
8 printf("%s classifies char %d (0x%02x) wrongly\n", class, ch
, ch
);
12 static int is_in(const char *s
, int ch
)
14 /* We can't find NUL using strchr. It's classless anyway. */
17 return !!strchr(s
, ch
);
20 #define TEST_CLASS(t,s) { \
22 for (i = 0; i < 256; i++) { \
23 if (is_in(s, i) != t(i)) \
24 report_error(#t, i); \
28 #define DIGIT "0123456789"
29 #define LOWER "abcdefghijklmnopqrstuvwxyz"
30 #define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
32 int cmd__ctype(int argc
, const char **argv
)
34 TEST_CLASS(isdigit
, DIGIT
);
35 TEST_CLASS(isspace
, " \n\r\t");
36 TEST_CLASS(isalpha
, LOWER UPPER
);
37 TEST_CLASS(isalnum
, LOWER UPPER DIGIT
);
38 TEST_CLASS(is_glob_special
, "*?[\\");
39 TEST_CLASS(is_regex_special
, "$()*+.?[\\^{|");
40 TEST_CLASS(is_pathspec_magic
, "!\"#%&',-/:;<=>@_`~");