[augeas-devel] augeas: master - libfa: handle the syntax r{min, } properly

David Lutterkort lutter at fedoraproject.org
Tue Feb 9 18:05:59 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=0bb4b11b6b89ddaf69b646aa638e082043c8c8fe
Commit:        0bb4b11b6b89ddaf69b646aa638e082043c8c8fe
Parent:        901dc5608139ccefaa402e67798e824f0d40b8e2
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Sat Jan 23 20:31:34 2010 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Mon Feb 8 16:54:43 2010 -0800

libfa: handle the syntax r{min,} properly

  * src/fa.c (parse_repeated_regexp): set max = -1 when we see r{min,};
    (re_iter_as_string): when max == -1, print r{min,}
  * tests/fatext.c (testExample): add a few tests for this syntax
---
 src/fa.c       |    9 +++++++--
 tests/fatest.c |    2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/fa.c b/src/fa.c
index 43ecc5e..0ce7d51 100644
--- a/src/fa.c
+++ b/src/fa.c
@@ -3313,7 +3313,7 @@ static struct re *parse_repeated_exp(struct re_parse *parse) {
         if (match(parse, ',')) {
             max = parse_int(parse);
             if (max == -1)
-                goto error;
+                max = -1;      /* If it's not an int, it means 'unbounded' */
             if (! match(parse, '}')) {
                 parse->error = REG_EBRACE;
                 goto error;
@@ -3324,7 +3324,7 @@ static struct re *parse_repeated_exp(struct re_parse *parse) {
             parse->error = REG_EBRACE;
             goto error;
         }
-        if (min > max) {
+        if (min > max && max != -1) {
             parse->error = REG_BADBR;
             goto error;
         }
@@ -3693,6 +3693,11 @@ static int re_iter_as_string(const struct re *re, struct re_str *str) {
         quant = "+";
     } else if (re->min == 0 && re->max == 1) {
         quant = "?";
+    } else if (re->max == -1) {
+        r = asprintf(&iter, "{%d,}", re->min);
+        if (r < 0)
+            return -1;
+        quant = iter;
     } else {
         r = asprintf(&iter, "{%d,%d}", re->min, re->max);
         if (r < 0)
diff --git a/tests/fatest.c b/tests/fatest.c
index 28e33b0..a4155cf 100644
--- a/tests/fatest.c
+++ b/tests/fatest.c
@@ -355,6 +355,8 @@ static void testExample(CuTest *tc) {
     assertExample(tc, "vu{2}|[0-9]", "0");
     assertExample(tc, "\\[", "[");
     assertExample(tc, "[\\]", "\\");
+    assertExample(tc, "a{3}", "aaa");
+    assertExample(tc, "a{3,}", "aaa");
 
     assertExample(tc, "\001((\002.)*\001)+\002", "\001\001\002");
     assertExample(tc, "\001((\001.)*\002)+\002", "\001\002\002");




More information about the augeas-devel mailing list