diff options
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r-- | apps/tagcache.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index cf0d73f0fb..5a80885819 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -56,7 +56,7 @@ | |||
56 | */ | 56 | */ |
57 | 57 | ||
58 | /*#define LOGF_ENABLE*/ | 58 | /*#define LOGF_ENABLE*/ |
59 | /*#define LOGF_CLAUSES define to enable logf clause matching (LOGF_ENABLE req'd) */ | 59 | /*#define LOGF_CLAUSES define to enable logf clause matching (LOGF_ENABLE req'd) */ |
60 | 60 | ||
61 | #include <stdio.h> | 61 | #include <stdio.h> |
62 | #include <stdlib.h> | 62 | #include <stdlib.h> |
@@ -162,6 +162,8 @@ static const char *tag_type_str[] = { | |||
162 | [clause_ends_with] = "clause_ends_with", | 162 | [clause_ends_with] = "clause_ends_with", |
163 | [clause_not_ends_with] = "clause_not_ends_with", | 163 | [clause_not_ends_with] = "clause_not_ends_with", |
164 | [clause_oneof] = "clause_oneof", | 164 | [clause_oneof] = "clause_oneof", |
165 | [clause_begins_oneof] = "clause_begins_oneof", | ||
166 | [clause_ends_oneof] = "clause_ends_oneof", | ||
165 | [clause_logical_or] = "clause_logical_or" | 167 | [clause_logical_or] = "clause_logical_or" |
166 | }; | 168 | }; |
167 | #define logf_clauses logf | 169 | #define logf_clauses logf |
@@ -1052,6 +1054,25 @@ inline static bool str_oneof(const char *str, const char *list) | |||
1052 | return false; | 1054 | return false; |
1053 | } | 1055 | } |
1054 | 1056 | ||
1057 | inline static bool str_begins_ends_oneof(const char *str, const char *list, bool begins) | ||
1058 | { | ||
1059 | logf_clauses("%s %s (%s) %s", str, __func__, begins ? "begins" : "ends", list); | ||
1060 | const char *sep; | ||
1061 | int l, p, len = strlen(str); | ||
1062 | |||
1063 | while (*list) | ||
1064 | { | ||
1065 | sep = strchr(list, '|'); | ||
1066 | l = sep ? (intptr_t)sep - (intptr_t)list : (int)strlen(list); | ||
1067 | p = begins ? 0 : len - l; | ||
1068 | if (l <= len && !strncasecmp(&str[p], list, l)) | ||
1069 | return true; | ||
1070 | list += sep ? l + 1 : l; | ||
1071 | } | ||
1072 | |||
1073 | return false; | ||
1074 | } | ||
1075 | |||
1055 | static bool check_against_clause(long numeric, const char *str, | 1076 | static bool check_against_clause(long numeric, const char *str, |
1056 | const struct tagcache_search_clause *clause) | 1077 | const struct tagcache_search_clause *clause) |
1057 | { | 1078 | { |
@@ -1105,6 +1126,10 @@ static bool check_against_clause(long numeric, const char *str, | |||
1105 | return !str_ends_with(str, clause->str); | 1126 | return !str_ends_with(str, clause->str); |
1106 | case clause_oneof: | 1127 | case clause_oneof: |
1107 | return str_oneof(str, clause->str); | 1128 | return str_oneof(str, clause->str); |
1129 | case clause_begins_oneof: | ||
1130 | return str_begins_ends_oneof(str, clause->str, true); | ||
1131 | case clause_ends_oneof: | ||
1132 | return str_begins_ends_oneof(str, clause->str, false); | ||
1108 | default: | 1133 | default: |
1109 | logf("Incorrect tag: %d", clause->type); | 1134 | logf("Incorrect tag: %d", clause->type); |
1110 | } | 1135 | } |