git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Masahiro Yamada" <masahiroy@kernel.org>
Subject: [PATCH 1/5] git-compat-util: add isblank() and isgraph()
Date: Fri, 10 Feb 2023 16:59:35 +0900	[thread overview]
Message-ID: <20230210075939.44949-2-masahiroy@kernel.org> (raw)
In-Reply-To: <20230210075939.44949-1-masahiroy@kernel.org>

git-compat-util.h implements most of is*() macros.

Add isblank() and isgraph(), which are useful to clean up wildmatch.c
in a consistent way (in this and later commits).

Use them with care because they are not robust against the pointer
increment, like isblank(*s++).

The same issue already exists for isspace().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 git-compat-util.h |  4 ++++
 wildmatch.c       | 14 ++------------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 4f0028ce60..90b43b2bc9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1212,10 +1212,12 @@ extern const unsigned char tolower_trans_tbl[256];
 /* Sane ctype - no locale, and works with signed chars */
 #undef isascii
 #undef isspace
+#undef isblank
 #undef isdigit
 #undef isalpha
 #undef isalnum
 #undef isprint
+#undef isgraph
 #undef islower
 #undef isupper
 #undef tolower
@@ -1236,10 +1238,12 @@ extern const unsigned char sane_ctype[256];
 #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 isblank(x) (isspace(x) || (x) == '\t')
 #define isdigit(x) sane_istest(x,GIT_DIGIT)
 #define isalpha(x) sane_istest(x,GIT_ALPHA)
 #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
 #define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
+#define isgraph(x) (isprint(x) && !isspace(x))
 #define islower(x) sane_iscase(x, 1)
 #define isupper(x) sane_iscase(x, 0)
 #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
diff --git a/wildmatch.c b/wildmatch.c
index 7e5a7ea1ea..85c4c7f8a7 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -28,18 +28,8 @@ typedef unsigned char uchar;
 # define ISASCII(c) isascii(c)
 #endif
 
-#ifdef isblank
-# define ISBLANK(c) (ISASCII(c) && isblank(c))
-#else
-# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
-#endif
-
-#ifdef isgraph
-# define ISGRAPH(c) (ISASCII(c) && isgraph(c))
-#else
-# define ISGRAPH(c) (ISASCII(c) && isprint(c) && !isspace(c))
-#endif
-
+#define ISBLANK(c) (ISASCII(c) && isblank(c))
+#define ISGRAPH(c) (ISASCII(c) && isgraph(c))
 #define ISPRINT(c) (ISASCII(c) && isprint(c))
 #define ISDIGIT(c) (ISASCII(c) && isdigit(c))
 #define ISALNUM(c) (ISASCII(c) && isalnum(c))
-- 
2.34.1


  reply	other threads:[~2023-02-10  7:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10  7:59 [PATCH 0/5] Clean up wildmatch.c Masahiro Yamada
2023-02-10  7:59 ` Masahiro Yamada [this message]
2023-02-10 13:16   ` [PATCH 1/5] git-compat-util: add isblank() and isgraph() Ævar Arnfjörð Bjarmason
2023-02-10 16:56     ` Masahiro Yamada
2023-02-10 19:10   ` Junio C Hamano
2023-02-10 19:25     ` Masahiro Yamada
2023-02-10 22:03   ` René Scharfe
2023-02-11  7:01     ` Masahiro Yamada
2023-02-11 13:48       ` René Scharfe
2023-02-11 14:11         ` René Scharfe
2023-02-10  7:59 ` [PATCH 2/5] wildmatch: remove IS*() macros Masahiro Yamada
2023-02-10  7:59 ` [PATCH 3/5] wildmatch: remove NEGATE_CLASS and NEGATE_CLASS2 macros Masahiro Yamada
2023-02-10 13:11   ` Ævar Arnfjörð Bjarmason
2023-02-10 17:03     ` Masahiro Yamada
2023-02-10  7:59 ` [PATCH 4/5] wildmatch: use char instead of uchar Masahiro Yamada
2023-02-10 13:09   ` Ævar Arnfjörð Bjarmason
2023-02-10  7:59 ` [PATCH 5/5] wildmatch: more cleanups after killing uchar Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230210075939.44949-2-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).