From 7abebdff3422e4a7d0baaa57eaa14205dba14e39 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Thu, 24 Feb 2011 22:45:12 +0200 Subject: [PATCH] regex: minor space saving --- test/test_regex.c | 1 + usual/regex.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_regex.c b/test/test_regex.c index 65fbbd2..bc07956 100644 --- a/test/test_regex.c +++ b/test/test_regex.c @@ -104,6 +104,7 @@ static void test_regex(void *ptr) str_check(e_rx("fo(o", "bar", 0), "EPAREN"); str_check(e_rx("[a-b-c]", "bar", 0), "ERANGE"); str_check(b_rx("(\\1)", "bar", 0), "ESUBREG"); + str_check(e_rx("[[:random:]]", "bar", 0), "ECTYPE"); end:; } diff --git a/usual/regex.c b/usual/regex.c index 4c7d656..767f85d 100644 --- a/usual/regex.c +++ b/usual/regex.c @@ -424,7 +424,7 @@ static void add_char(struct ClassData *cd, unsigned char c, bool icase) struct NamedClass { const char name[7]; - int name_len; + unsigned char name_len; int (*check_func)(int c); }; static const struct NamedClass ctype_list[] = { @@ -440,14 +440,14 @@ static const struct NamedClass ctype_list[] = { { "space", 5, isspace }, { "upper", 5, isupper }, { "xdigit", 6, isxdigit }, - { "" } }; static int fill_class(struct ClassData *cd, const char *name, const char **s_p, bool icase) { unsigned c; const struct NamedClass *cc = ctype_list; - for (cc = ctype_list; cc->name[0]; cc++) { + for (c = 0; c < ARRAY_NELEM(ctype_list); c++) { + cc = ctype_list + c; if (strncmp(name, cc->name, cc->name_len) != 0) continue; name += cc->name_len; -- 2.39.5