summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2001-04-28 12:24:34 +0000
committerDaniel Veillard <veillard@src.gnome.org>2001-04-28 12:24:34 +0000
commit2156a56bcbf5d83fb3d694123be01beebf84d273 (patch)
treea5ddbb0b17047ef63d4b7309fbe300f39d73f466
parent61d80a2822b2678dee885ac2850295cc96277c63 (diff)
downloadlibxml2-2156a56bcbf5d83fb3d694123be01beebf84d273.tar.gz
- xpath.c: more cleanup work on XPath name parsing routines
Daniel
-rw-r--r--ChangeLog4
-rw-r--r--xpath.c99
2 files changed, 65 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 13d2db48..8f470ccf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Apr 28 14:23:30 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+ * xpath.c: more cleanup work on XPath name parsing routines
+
Fri Apr 27 19:06:13 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* parserInternals.c xpath.[ch]: some UTF8 cleanup on
diff --git a/xpath.c b/xpath.c
index ba069c65..a579ff0a 100644
--- a/xpath.c
+++ b/xpath.c
@@ -5055,6 +5055,8 @@ static void xmlXPathCompRelLocationPath(xmlXPathParserContextPtr ctxt);
#else
static void xmlXPathCompRelativeLocationPath(xmlXPathParserContextPtr ctxt);
#endif
+static xmlChar * xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt,
+ int qualified);
/**
* xmlXPathCurrentChar:
@@ -5158,24 +5160,38 @@ encoding_error:
xmlChar *
xmlXPathParseNCName(xmlXPathParserContextPtr ctxt) {
- const xmlChar *q;
- xmlChar *ret = NULL;
-
- if (!IS_LETTER(CUR) && (CUR != '_')) return(NULL);
- q = NEXT;
-
- while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) ||
- (CUR == '.') || (CUR == '-') ||
- (CUR == '_') ||
- (IS_COMBINING(CUR)) ||
- (IS_EXTENDER(CUR)))
- NEXT;
-
- ret = xmlStrndup(q, CUR_PTR - q);
+ const xmlChar *in;
+ xmlChar *ret;
+ int count = 0;
- return(ret);
+ /*
+ * Accelerator for simple ASCII names
+ */
+ in = ctxt->cur;
+ if (((*in >= 0x61) && (*in <= 0x7A)) ||
+ ((*in >= 0x41) && (*in <= 0x5A)) ||
+ (*in == '_')) {
+ in++;
+ while (((*in >= 0x61) && (*in <= 0x7A)) ||
+ ((*in >= 0x41) && (*in <= 0x5A)) ||
+ ((*in >= 0x30) && (*in <= 0x39)) ||
+ (*in == '_'))
+ in++;
+ if ((*in == ' ') || (*in == '>') || (*in == '/') ||
+ (*in == '[') || (*in == ']') || (*in == ':') ||
+ (*in == '@') || (*in == '*')) {
+ count = in - ctxt->cur;
+ if (count == 0)
+ return(NULL);
+ ret = xmlStrndup(ctxt->cur, count);
+ ctxt->cur = in;
+ return(ret);
+ }
+ }
+ return(xmlXPathParseNameComplex(ctxt, 0));
}
+
/**
* xmlXPathParseQName:
* @ctxt: the XPath Parser context
@@ -5207,7 +5223,6 @@ xmlXPathParseQName(xmlXPathParserContextPtr ctxt, xmlChar **prefix) {
return(ret);
}
-static xmlChar * xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt);
/**
* xmlXPathParseName:
* @ctxt: the XPath Parser context
@@ -5248,11 +5263,11 @@ xmlXPathParseName(xmlXPathParserContextPtr ctxt) {
return(ret);
}
}
- return(xmlXPathParseNameComplex(ctxt));
+ return(xmlXPathParseNameComplex(ctxt, 1));
}
static xmlChar *
-xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt) {
+xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) {
xmlChar buf[XML_MAX_NAMELEN + 5];
int len = 0, l;
int c;
@@ -5262,15 +5277,17 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt) {
*/
c = CUR_CHAR(l);
if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
+ (c == '[') || (c == ']') || (c == '@') || /* accelerators */
+ (c == '*') || /* accelerators */
(!IS_LETTER(c) && (c != '_') &&
- (c != ':'))) {
+ ((qualified) && (c != ':')))) {
return(NULL);
}
while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
((IS_LETTER(c)) || (IS_DIGIT(c)) ||
(c == '.') || (c == '-') ||
- (c == '_') || (c == ':') ||
+ (c == '_') || ((qualified) && (c == ':')) ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c)))) {
COPY_BUF(l,buf,len,c);
@@ -5291,7 +5308,7 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt) {
memcpy(buffer, buf, len);
while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigname.xml */
(c == '.') || (c == '-') ||
- (c == '_') || (c == ':') ||
+ (c == '_') || ((qualified) && (c == ':')) ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c))) {
if (len + 10 > max) {
@@ -5311,6 +5328,8 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt) {
return(buffer);
}
}
+ if (len == 0)
+ return(NULL);
return(xmlStrndup(buf, len));
}
/**
@@ -6527,28 +6546,32 @@ xmlXPathCompStep(xmlXPathParserContextPtr ctxt) {
}
}
#endif
- if (name == NULL)
- name = xmlXPathParseNCName(ctxt);
- if (name != NULL) {
- axis = xmlXPathIsAxisName(name);
- if (axis != 0) {
- SKIP_BLANKS;
- if ((CUR == ':') && (NXT(1) == ':')) {
- SKIP(2);
- xmlFree(name);
- name = NULL;
+ if (CUR == '*') {
+ axis = AXIS_CHILD;
+ } else {
+ if (name == NULL)
+ name = xmlXPathParseNCName(ctxt);
+ if (name != NULL) {
+ axis = xmlXPathIsAxisName(name);
+ if (axis != 0) {
+ SKIP_BLANKS;
+ if ((CUR == ':') && (NXT(1) == ':')) {
+ SKIP(2);
+ xmlFree(name);
+ name = NULL;
+ } else {
+ /* an element name can conflict with an axis one :-\ */
+ axis = AXIS_CHILD;
+ }
} else {
- /* an element name can conflict with an axis one :-\ */
axis = AXIS_CHILD;
}
+ } else if (CUR == '@') {
+ NEXT;
+ axis = AXIS_ATTRIBUTE;
} else {
- axis = AXIS_CHILD;
+ axis = AXIS_CHILD;
}
- } else if (CUR == '@') {
- NEXT;
- axis = AXIS_ATTRIBUTE;
- } else {
- axis = AXIS_CHILD;
}
CHECK_ERROR;