[PATCH 4/8] Make strmatch() return 1 only if the string compared against the prefix does not contain other characters which may belong to an identifier.

Stefano Sabatini stefano.sabatini-lala
Sun Oct 31 01:27:25 CEST 2010


This allows to distinguish for example to have different constants
with the same prefix (e.g. "foo" and "foobar").
---
 libavutil/eval.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/libavutil/eval.c b/libavutil/eval.c
index 98917fa..765492f 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -103,13 +103,19 @@ double av_strtod(const char *numstr, char **tail)
     return d;
 }
 
+#define IS_IDENTIFIER_CHAR(c) (((c) >= '0' && (c) <= '9') || \
+                               ((c) >= 'a' && (c) <= 'z') || \
+                               ((c) >= 'A' && (c) <= 'Z') || \
+                               ((c) == '_'))
+
 static int strmatch(const char *s, const char *prefix)
 {
     int i;
     for (i=0; prefix[i]; i++) {
         if (prefix[i] != s[i]) return 0;
     }
-    return 1;
+    /* return 1 only if the s identifier is terminated */
+    return !IS_IDENTIFIER_CHAR(s[i]);
 }
 
 struct AVExpr {
-- 
1.7.1


--fdj2RfSjLxBAspz7--



More information about the ffmpeg-devel mailing list