perf probe: Add lazy line matching support
[safe/jmp/linux-2.6] / tools / perf / util / string.c
index c397d4f..a175949 100644 (file)
@@ -265,21 +265,21 @@ error:
        return false;
 }
 
-/**
- * strglobmatch - glob expression pattern matching
- * @str: the target string to match
- * @pat: the pattern string to match
- *
- * This returns true if the @str matches @pat. @pat can includes wildcards
- * ('*','?') and character classes ([CHARS], complementation and ranges are
- * also supported). Also, this supports escape character ('\') to use special
- * characters as normal character.
- *
- * Note: if @pat syntax is broken, this always returns false.
- */
-bool strglobmatch(const char *str, const char *pat)
+/* Glob/lazy pattern matching */
+static bool __match_glob(const char *str, const char *pat, bool ignore_space)
 {
        while (*str && *pat && *pat != '*') {
+               if (ignore_space) {
+                       /* Ignore spaces for lazy matching */
+                       if (isspace(*str)) {
+                               str++;
+                               continue;
+                       }
+                       if (isspace(*pat)) {
+                               pat++;
+                               continue;
+                       }
+               }
                if (*pat == '?') {      /* Matches any single character */
                        str++;
                        pat++;
@@ -308,3 +308,32 @@ bool strglobmatch(const char *str, const char *pat)
        return !*str && !*pat;
 }
 
+/**
+ * strglobmatch - glob expression pattern matching
+ * @str: the target string to match
+ * @pat: the pattern string to match
+ *
+ * This returns true if the @str matches @pat. @pat can includes wildcards
+ * ('*','?') and character classes ([CHARS], complementation and ranges are
+ * also supported). Also, this supports escape character ('\') to use special
+ * characters as normal character.
+ *
+ * Note: if @pat syntax is broken, this always returns false.
+ */
+bool strglobmatch(const char *str, const char *pat)
+{
+       return __match_glob(str, pat, false);
+}
+
+/**
+ * strlazymatch - matching pattern strings lazily with glob pattern
+ * @str: the target string to match
+ * @pat: the pattern string to match
+ *
+ * This is similar to strglobmatch, except this ignores spaces in
+ * the target string.
+ */
+bool strlazymatch(const char *str, const char *pat)
+{
+       return __match_glob(str, pat, true);
+}