Skip to content

Commit c2e9364

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d2d4f9 commit c2e9364

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

git-compat-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ static inline int has_extension(const char *filename, const char *ext)
319319
}
320320

321321
/* Sane ctype - no locale, and works with signed chars */
322+
#undef isascii
322323
#undef isspace
323324
#undef isdigit
324325
#undef isalpha
@@ -332,6 +333,7 @@ extern unsigned char sane_ctype[256];
332333
#define GIT_GLOB_SPECIAL 0x08
333334
#define GIT_REGEX_SPECIAL 0x10
334335
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
336+
#define isascii(x) (((x) & ~0x7f) == 0)
335337
#define isspace(x) sane_istest(x,GIT_SPACE)
336338
#define isdigit(x) sane_istest(x,GIT_DIGIT)
337339
#define isalpha(x) sane_istest(x,GIT_ALPHA)

pretty.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ static int get_one_line(const char *msg)
7575
/* High bit set, or ISO-2022-INT */
7676
int non_ascii(int ch)
7777
{
78-
ch = (ch & 0xff);
79-
return ((ch & 0x80) || (ch == 0x1b));
78+
return !isascii(ch) || ch == '\033';
8079
}
8180

8281
static int is_rfc2047_special(char ch)

0 commit comments

Comments
 (0)