[augeas-devel] augeas: master - Make regexp_escape strip enclosing parens; make API const correct

David Lutterkort lutter at fedoraproject.org
Tue Sep 1 18:09:04 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=15eb39a97ad98be637c9093cd1cfeee455cfefef
Commit:        15eb39a97ad98be637c9093cd1cfeee455cfefef
Parent:        c3259d1e612bbf93b286c2e4c1a918e05b317a4b
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Tue Aug 25 15:35:34 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Mon Aug 31 14:36:27 2009 -0700

Make regexp_escape strip enclosing parens; make API const correct

  * 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;




More information about the augeas-devel mailing list