summaryrefslogtreecommitdiff
path: root/xmlregexp.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2004-08-10 14:17:33 +0000
committerDaniel Veillard <veillard@src.gnome.org>2004-08-10 14:17:33 +0000
commitc0826a7709eddbf10ade02f0ce80e5d077ac05f6 (patch)
tree0daee60e24ad2c52c5dd43b624da5dcdbae36bf8 /xmlregexp.c
parent2d908039e42573956891c1ae85ef07a9ee06fb3e (diff)
downloadlibxml2-c0826a7709eddbf10ade02f0ce80e5d077ac05f6.tar.gz
applied Schemas patches from Kasimier Buchcik lot of new tests for things
* configure.in xmlregexp.c xmlschemas.c xmlschemastypes.c include/libxml/schemasInternals.h include/libxml/xmlerror.h include/libxml/xmlschemastypes.h: applied Schemas patches from Kasimier Buchcik * test/ result/ bug141333* annot-err* any[1-4]* bug145246* element-err* element-minmax-err* include1* restrict-CT-attr-ref*: lot of new tests for things fixed by the patch Daniel
Diffstat (limited to 'xmlregexp.c')
-rw-r--r--xmlregexp.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/xmlregexp.c b/xmlregexp.c
index 12ecd83f..0435d674 100644
--- a/xmlregexp.c
+++ b/xmlregexp.c
@@ -35,8 +35,8 @@
#define INT_MAX 123456789 /* easy to flag and big enough for our needs */
#endif
-/* #define DEBUG_REGEXP_GRAPH */
-/* #define DEBUG_REGEXP_EXEC */
+/* #define DEBUG_REGEXP_GRAPH */
+/* #define DEBUG_REGEXP_EXEC */
/* #define DEBUG_PUSH */
/* #define DEBUG_COMPACTION */
@@ -49,6 +49,7 @@
#define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l)
#define NEXTL(l) ctxt->cur += l;
+#define XML_REG_STRING_SEPARATOR '|'
/**
* TODO:
@@ -2577,6 +2578,47 @@ xmlFARegExecSaveInputString(xmlRegExecCtxtPtr exec, const xmlChar *value,
exec->inputStack[exec->inputStackNr].data = NULL;
}
+/**
+ * xmlRegStrEqualWildcard:
+ * @expStr: the string to be evaluated
+ * @valStr: the validation string
+ *
+ * Checks if both strings are equal or have the same content. "*"
+ * can be used as a wildcard in @valStr; "|" is used as a seperator of
+ * substrings in both @expStr and @valStr.
+ *
+ * Returns 1 if the comparison is satisfied and the number of substrings
+ * is equal, 0 otherwise.
+ */
+
+static int
+xmlRegStrEqualWildcard(const xmlChar *expStr, const xmlChar *valStr) {
+ if (expStr == valStr) return(1);
+ if (expStr == NULL) return(0);
+ if (valStr == NULL) return(0);
+ do {
+ /*
+ * Eval if we have a wildcard for the current item.
+ */
+ if (*expStr != *valStr) {
+ if ((*valStr != 0) && (*expStr != 0) && (*expStr++ == '*')) {
+ do {
+ if (*valStr == XML_REG_STRING_SEPARATOR)
+ break;
+ *valStr++;
+ } while (*valStr != 0);
+ continue;
+ } else
+ return(0);
+ }
+ *expStr++;
+ *valStr++;
+ } while (*valStr != 0);
+ if (*expStr != 0)
+ return (0);
+ else
+ return (1);
+}
/**
* xmlRegCompactPushString:
@@ -2621,9 +2663,9 @@ xmlRegCompactPushString(xmlRegExecCtxtPtr exec,
for (i = 0;i < comp->nbstrings;i++) {
target = comp->compact[state * (comp->nbstrings + 1) + i + 1];
if ((target > 0) && (target <= comp->nbstates)) {
- target--; /* to avoid 0 */
- if (xmlStrEqual(comp->stringMap[i], value)) {
- exec->index = target;
+ target--; /* to avoid 0 */
+ if (xmlRegStrEqualWildcard(comp->stringMap[i], value)) {
+ exec->index = target;
if ((exec->callback != NULL) && (comp->transdata != NULL)) {
exec->callback(exec->data, value,
comp->transdata[state * comp->nbstrings + i], data);
@@ -2802,7 +2844,7 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value,
exec->status = -2;
break;
} else if (value != NULL) {
- ret = xmlStrEqual(value, atom->valuep);
+ ret = xmlRegStrEqualWildcard(atom->valuep, value);
if ((ret == 1) && (trans->counter >= 0)) {
xmlRegCounterPtr counter;
int count;
@@ -2999,7 +3041,7 @@ xmlRegExecPushString2(xmlRegExecCtxtPtr exec, const xmlChar *value,
str = buf;
}
memcpy(&str[0], value, lenp);
- str[lenp] = '|';
+ str[lenp] = XML_REG_STRING_SEPARATOR;
memcpy(&str[lenp + 1], value2, lenn);
str[lenn + lenp + 1] = 0;