- support SEARCH_STRINGSTART and SEARCH_STRINGEND
authorMichael Schroeder <mls@suse.de>
Wed, 15 Jul 2009 13:12:47 +0000 (15:12 +0200)
committerMichael Schroeder <mls@suse.de>
Wed, 15 Jul 2009 13:12:47 +0000 (15:12 +0200)
src/repo.h
src/repodata.c

index 2f7c49a..b66631b 100644 (file)
@@ -153,12 +153,14 @@ typedef struct _KeyValue {
 } KeyValue;
 
 /* search matcher flags */
-#define SEARCH_STRINGMASK      15
-#define SEARCH_STRING          1
-#define SEARCH_SUBSTRING       2
-#define SEARCH_GLOB            3
-#define SEARCH_REGEX           4
-#define SEARCH_ERROR           5
+#define SEARCH_STRINGMASK              15
+#define SEARCH_STRING                  1
+#define SEARCH_STRINGSTART             2
+#define SEARCH_STRINGEND               3
+#define SEARCH_SUBSTRING               4
+#define SEARCH_GLOB                    5
+#define SEARCH_REGEX                   6
+#define SEARCH_ERROR                   15
 #define        SEARCH_NOCASE                   (1<<7)
 
 /* iterator control */
index 61dfe12..5178fe0 100644 (file)
@@ -931,6 +931,7 @@ datamatcher_free(Datamatcher *ma)
 int
 datamatcher_match(Datamatcher *ma, const char *str)
 {
+  int l;
   switch ((ma->flags & SEARCH_STRINGMASK))
     {
     case SEARCH_SUBSTRING:
@@ -957,6 +958,33 @@ datamatcher_match(Datamatcher *ma, const char *str)
            return 0;
        }
       break;
+    case SEARCH_STRINGSTART:
+      if (ma->flags & SEARCH_NOCASE)
+       {
+         if (strncasecmp(ma->match, str, strlen(ma->match)))
+           return 0;
+       }
+      else
+       {
+         if (strncmp(ma->match, str, strlen(ma->match)))
+           return 0;
+       }
+      break;
+    case SEARCH_STRINGEND:
+      l = strlen(str) - strlen(ma->match);
+      if (l < 0)
+       return 0;
+      if (ma->flags & SEARCH_NOCASE)
+       {
+         if (strcasecmp(ma->match, str + l))
+           return 0;
+       }
+      else
+       {
+         if (strcmp(ma->match, str + l))
+           return 0;
+       }
+      break;
     case SEARCH_GLOB:
       if (fnmatch(ma->match, str, (ma->flags & SEARCH_NOCASE) ? FNM_CASEFOLD : 0))
        return 0;