Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 1c149ab

Browse files
pcloudsgitster
authored andcommitted
ctype: support iscntrl, ispunct, isxdigit and isprint
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca5ab7d commit 1c149ab

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

ctype.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ enum {
1111
D = GIT_DIGIT,
1212
G = GIT_GLOB_SPECIAL, /* *, ?, [, \\ */
1313
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
1518
};
1619

1720
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 */
2023
S, P, P, P, R, P, P, P, R, R, G, R, P, P, R, P, /* 32.. 47 */
2124
D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G, /* 48.. 63 */
2225
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 */
2427
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 */
2629
/* Nothing in the 128.. range */
2730
};
2831

git-compat-util.h

+13
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,19 @@ extern const char tolower_trans_tbl[256];
470470
#undef isupper
471471
#undef tolower
472472
#undef toupper
473+
#undef iscntrl
474+
#undef ispunct
475+
#undef isxdigit
476+
#undef isprint
473477
extern const unsigned char sane_ctype[256];
474478
#define GIT_SPACE 0x01
475479
#define GIT_DIGIT 0x02
476480
#define GIT_ALPHA 0x04
477481
#define GIT_GLOB_SPECIAL 0x08
478482
#define GIT_REGEX_SPECIAL 0x10
479483
#define GIT_PATHSPEC_MAGIC 0x20
484+
#define GIT_CNTRL 0x40
485+
#define GIT_PUNCT 0x80
480486
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
481487
#define isascii(x) (((x) & ~0x7f) == 0)
482488
#define isspace(x) sane_istest(x,GIT_SPACE)
@@ -487,6 +493,13 @@ extern const unsigned char sane_ctype[256];
487493
#define isupper(x) sane_iscase(x, 0)
488494
#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
489495
#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))
490503
#define tolower(x) sane_case((unsigned char)(x), 0x20)
491504
#define toupper(x) sane_case((unsigned char)(x), 0)
492505
#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)

0 commit comments

Comments
 (0)