ctype: support iscntrl, ispunct, isxdigit and isprint

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Oct 15, 2012 at 13:25 UTC 1c149ab2ddc4a6d253e76d90067ea0fff2880ded
2 files changed +21 -5
ctype.c
+8 -5
@@ -11,18 +11,21 @@ enum {
11 D = GIT_DIGIT,
12 G = GIT_GLOB_SPECIAL, /* *, ?, [, \\ */
13 R = GIT_REGEX_SPECIAL, /* $, (, ), +, ., ^, {, | */
14 - P = GIT_PATHSPEC_MAGIC /* other non-alnum, except for ] and } */
14 + P = GIT_PATHSPEC_MAGIC, /* other non-alnum, except for ] and } */
15 + X = GIT_CNTRL,
16 + U = GIT_PUNCT,
17 + Z = GIT_CNTRL | GIT_SPACE
18 };
19
20 const unsigned char sane_ctype[256] = {
18 - 0, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0, /* 0.. 15 */
19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16.. 31 */
21 + X, X, X, X, X, X, X, X, X, Z, Z, X, X, Z, X, X, /* 0.. 15 */
22 + X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 16.. 31 */
23 S, P, P, P, R, P, P, P, R, R, G, R, P, P, R, P, /* 32.. 47 */
24 D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G, /* 48.. 63 */
25 P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 64.. 79 */
23 - A, A, A, A, A, A, A, A, A, A, A, G, G, 0, R, P, /* 80.. 95 */
26 + A, A, A, A, A, A, A, A, A, A, A, G, G, U, R, P, /* 80.. 95 */
27 P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 96..111 */
25 - A, A, A, A, A, A, A, A, A, A, A, R, R, 0, P, 0, /* 112..127 */
28 + A, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X, /* 112..127 */
29 /* Nothing in the 128.. range */
30 };
31
git-compat-util.h
+13
@@ -470,6 +470,10 @@ extern const char tolower_trans_tbl[256];
470 #undef isupper
471 #undef tolower
472 #undef toupper
473 +#undef iscntrl
474 +#undef ispunct
475 +#undef isxdigit
476 +#undef isprint
477 extern const unsigned char sane_ctype[256];
478 #define GIT_SPACE 0x01
479 #define GIT_DIGIT 0x02
@@ -477,6 +481,8 @@ extern const unsigned char sane_ctype[256];
481 #define GIT_GLOB_SPECIAL 0x08
482 #define GIT_REGEX_SPECIAL 0x10
483 #define GIT_PATHSPEC_MAGIC 0x20
484 +#define GIT_CNTRL 0x40
485 +#define GIT_PUNCT 0x80
486 #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
487 #define isascii(x) (((x) & ~0x7f) == 0)
488 #define isspace(x) sane_istest(x,GIT_SPACE)
@@ -487,6 +493,13 @@ extern const unsigned char sane_ctype[256];
493 #define isupper(x) sane_iscase(x, 0)
494 #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
495 #define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
496 +#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
497 +#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
498 + GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
499 +#define isxdigit(x) (hexval_table[x] != -1)
500 +#define isprint(x) (sane_istest(x, GIT_ALPHA | GIT_DIGIT | GIT_SPACE | \
501 + GIT_PUNCT | GIT_REGEX_SPECIAL | GIT_GLOB_SPECIAL | \
502 + GIT_PATHSPEC_MAGIC))
503 #define tolower(x) sane_case((unsigned char)(x), 0x20)
504 #define toupper(x) sane_case((unsigned char)(x), 0)
505 #define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)