* [PATCH] cleanup: add isascii()
@ 2009-03-07 13:06 René Scharfe
0 siblings, 0 replies; only message in thread
From: René Scharfe @ 2009-03-07 13:06 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
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>
---
git-compat-util.h | 2 ++
pretty.c | 3 +--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index dcf4127..878d83d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -319,6 +319,7 @@ static inline int has_extension(const char *filename, const char *ext)
}
/* Sane ctype - no locale, and works with signed chars */
+#undef isascii
#undef isspace
#undef isdigit
#undef isalpha
@@ -332,6 +333,7 @@ extern unsigned char sane_ctype[256];
#define GIT_GLOB_SPECIAL 0x08
#define GIT_REGEX_SPECIAL 0x10
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
+#define isascii(x) (((x) & ~0x7f) == 0)
#define isspace(x) sane_istest(x,GIT_SPACE)
#define isdigit(x) sane_istest(x,GIT_DIGIT)
#define isalpha(x) sane_istest(x,GIT_ALPHA)
diff --git a/pretty.c b/pretty.c
index f499294..c018408 100644
--- a/pretty.c
+++ b/pretty.c
@@ -83,8 +83,7 @@ static int get_one_line(const char *msg)
/* High bit set, or ISO-2022-INT */
int non_ascii(int ch)
{
- ch = (ch & 0xff);
- return ((ch & 0x80) || (ch == 0x1b));
+ return !isascii(ch) || ch == '\033';
}
static int is_rfc2047_special(char ch)
--
1.6.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-03-07 13:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-07 13:06 [PATCH] cleanup: add isascii() René Scharfe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).