regex: minor space saving
authorMarko Kreen <markokr@gmail.com>
Thu, 24 Feb 2011 20:45:12 +0000 (22:45 +0200)
committerMarko Kreen <markokr@gmail.com>
Thu, 24 Feb 2011 20:45:12 +0000 (22:45 +0200)
test/test_regex.c
usual/regex.c

index 65fbbd2bce313393dab45b4929f3f4dea178bb41..bc07956acdda3eb7fe8543736318b853a0eb8803 100644 (file)
@@ -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:;
 }
 
index 4c7d656208a2a761e8ee498a7482c5179192e19c..767f85d9fc814909740950978fab73fe9ffd5315 100644 (file)
@@ -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;