cleanup: add isascii()
Add a standard definition of isascii() and use it to replace an open coded high-bit test in pretty.c. While we're there, write the ESC char as the more commonly used '\033' instead of as 0x1b to enhance its grepability. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Mar 7, 2009 at 14:06 UTC
c2e9364a06df55e70d7652d37bb4d712f6b3bb3e
2 files changed
+3
-2
git-compat-util.h
+2
@@ -319,6 +319,7 @@ static inline int has_extension(const char *filename, const char *ext)
319
}
320
321
/* Sane ctype - no locale, and works with signed chars */
322
+#undef isascii
323
#undef isspace
324
#undef isdigit
325
#undef isalpha
@@ -332,6 +333,7 @@ extern unsigned char sane_ctype[256];
333
#define GIT_GLOB_SPECIAL 0x08
334
#define GIT_REGEX_SPECIAL 0x10
335
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
336
+#define isascii(x) (((x) & ~0x7f) == 0)
337
#define isspace(x) sane_istest(x,GIT_SPACE)
338
#define isdigit(x) sane_istest(x,GIT_DIGIT)
339
#define isalpha(x) sane_istest(x,GIT_ALPHA)
pretty.c
+1
-2
@@ -75,8 +75,7 @@ static int get_one_line(const char *msg)
75
/* High bit set, or ISO-2022-INT */
76
int non_ascii(int ch)
77
{
78
- ch = (ch & 0xff);
79
- return ((ch & 0x80) || (ch == 0x1b));
78
+ return !isascii(ch) || ch == '\033';
79
}
80
81
static int is_rfc2047_special(char ch)