[augeas-devel] [PATCH 5/8] Make regexp_escape strip enclosing parens; make API const correct

David Lutterkort lutter at redhat.com
Mon Aug 31 21:44:31 UTC 2009


  * src/syntax.h (regexp_escape): make const correct
  * src/regexp.h (regexp_escape): strip '(...)' enclosing entire regexp
---
 src/regexp.c |    6 +++++-
 src/syntax.h |    2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/regexp.c b/src/regexp.c
index d3414cd..886875f 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -31,7 +31,7 @@ static const struct string empty_pattern_string = {
 
 static const struct string *const empty_pattern = &empty_pattern_string;
 
-char *regexp_escape(struct regexp *r) {
+char *regexp_escape(const struct regexp *r) {
     char *pat = escape(r->pattern->str, -1);
 
     if (pat == NULL)
@@ -48,6 +48,10 @@ char *regexp_escape(struct regexp *r) {
         }
     }
 
+    if (pat[0] == '(' && pat[strlen(pat)-1] == ')')
+        memmove(pat, pat+1, strlen(pat+1)+1);
+    pat[strlen(pat)-1] = '\0';
+
     return pat;
 }
 
diff --git a/src/syntax.h b/src/syntax.h
index 204baeb..7453f19 100644
--- a/src/syntax.h
+++ b/src/syntax.h
@@ -211,7 +211,7 @@ struct regexp *regexp_make_empty(struct info *);
 void regexp_release(struct regexp *regexp);
 
 /* Produce a printable representation of R */
-char *regexp_escape(struct regexp *r);
+char *regexp_escape(const struct regexp *r);
 
 struct native {
     unsigned int argc;
-- 
1.6.2.5




More information about the augeas-devel mailing list