Skip to content

Commit 1890ce8

Browse files
calvin-wan-googlegitster
authored andcommitted
sane-ctype.h: create header for sane-ctype macros
Splitting these macros from git-compat-util.h cleans up the file and allows future third-party sources to not use these overrides if they do not wish to. Signed-off-by: Calvin Wan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 382f694 commit 1890ce8

File tree

2 files changed

+67
-61
lines changed

2 files changed

+67
-61
lines changed

git-compat-util.h

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,67 +1153,7 @@ static inline size_t xsize_t(off_t len)
11531153
/* in ctype.c, for kwset users */
11541154
extern const unsigned char tolower_trans_tbl[256];
11551155

1156-
/* Sane ctype - no locale, and works with signed chars */
1157-
#undef isascii
1158-
#undef isspace
1159-
#undef isdigit
1160-
#undef isalpha
1161-
#undef isalnum
1162-
#undef isprint
1163-
#undef islower
1164-
#undef isupper
1165-
#undef tolower
1166-
#undef toupper
1167-
#undef iscntrl
1168-
#undef ispunct
1169-
#undef isxdigit
1170-
1171-
extern const unsigned char sane_ctype[256];
1172-
extern const signed char hexval_table[256];
1173-
#define GIT_SPACE 0x01
1174-
#define GIT_DIGIT 0x02
1175-
#define GIT_ALPHA 0x04
1176-
#define GIT_GLOB_SPECIAL 0x08
1177-
#define GIT_REGEX_SPECIAL 0x10
1178-
#define GIT_PATHSPEC_MAGIC 0x20
1179-
#define GIT_CNTRL 0x40
1180-
#define GIT_PUNCT 0x80
1181-
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
1182-
#define isascii(x) (((x) & ~0x7f) == 0)
1183-
#define isspace(x) sane_istest(x,GIT_SPACE)
1184-
#define isdigit(x) sane_istest(x,GIT_DIGIT)
1185-
#define isalpha(x) sane_istest(x,GIT_ALPHA)
1186-
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
1187-
#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
1188-
#define islower(x) sane_iscase(x, 1)
1189-
#define isupper(x) sane_iscase(x, 0)
1190-
#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
1191-
#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
1192-
#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
1193-
#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
1194-
GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
1195-
#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
1196-
#define tolower(x) sane_case((unsigned char)(x), 0x20)
1197-
#define toupper(x) sane_case((unsigned char)(x), 0)
1198-
#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)
1199-
1200-
static inline int sane_case(int x, int high)
1201-
{
1202-
if (sane_istest(x, GIT_ALPHA))
1203-
x = (x & ~0x20) | high;
1204-
return x;
1205-
}
1206-
1207-
static inline int sane_iscase(int x, int is_lower)
1208-
{
1209-
if (!sane_istest(x, GIT_ALPHA))
1210-
return 0;
1211-
1212-
if (is_lower)
1213-
return (x & 0x20) != 0;
1214-
else
1215-
return (x & 0x20) == 0;
1216-
}
1156+
#include "sane-ctype.h"
12171157

12181158
/*
12191159
* Like skip_prefix, but compare case-insensitively. Note that the comparison

sane-ctype.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#ifndef SANE_CTYPE_H
2+
#define SANE_CTYPE_H
3+
4+
/* Sane ctype - no locale, and works with signed chars */
5+
#undef isascii
6+
#undef isspace
7+
#undef isdigit
8+
#undef isalpha
9+
#undef isalnum
10+
#undef isprint
11+
#undef islower
12+
#undef isupper
13+
#undef tolower
14+
#undef toupper
15+
#undef iscntrl
16+
#undef ispunct
17+
#undef isxdigit
18+
19+
extern const unsigned char sane_ctype[256];
20+
extern const signed char hexval_table[256];
21+
#define GIT_SPACE 0x01
22+
#define GIT_DIGIT 0x02
23+
#define GIT_ALPHA 0x04
24+
#define GIT_GLOB_SPECIAL 0x08
25+
#define GIT_REGEX_SPECIAL 0x10
26+
#define GIT_PATHSPEC_MAGIC 0x20
27+
#define GIT_CNTRL 0x40
28+
#define GIT_PUNCT 0x80
29+
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
30+
#define isascii(x) (((x) & ~0x7f) == 0)
31+
#define isspace(x) sane_istest(x,GIT_SPACE)
32+
#define isdigit(x) sane_istest(x,GIT_DIGIT)
33+
#define isalpha(x) sane_istest(x,GIT_ALPHA)
34+
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
35+
#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
36+
#define islower(x) sane_iscase(x, 1)
37+
#define isupper(x) sane_iscase(x, 0)
38+
#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
39+
#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
40+
#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
41+
#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
42+
GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
43+
#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
44+
#define tolower(x) sane_case((unsigned char)(x), 0x20)
45+
#define toupper(x) sane_case((unsigned char)(x), 0)
46+
#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)
47+
48+
static inline int sane_case(int x, int high)
49+
{
50+
if (sane_istest(x, GIT_ALPHA))
51+
x = (x & ~0x20) | high;
52+
return x;
53+
}
54+
55+
static inline int sane_iscase(int x, int is_lower)
56+
{
57+
if (!sane_istest(x, GIT_ALPHA))
58+
return 0;
59+
60+
if (is_lower)
61+
return (x & 0x20) != 0;
62+
else
63+
return (x & 0x20) == 0;
64+
}
65+
66+
#endif

0 commit comments

Comments
 (0)