Commit e043ee17 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

- xpath.c: fixed xmlXPathNodeCollectAndTest() to do proper

  prefix lookup.
- parserInternals.c: fixed the bug reported by Morus Walter
  due to an off by one typo in xmlStringCurrentChar()
Daniel
parent a3bfca59
Tue Apr 17 10:08:19 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* xpath.c: fixed xmlXPathNodeCollectAndTest() to do proper
prefix lookup.
* parserInternals.c: fixed the bug reported by Morus Walter
due to an off by one typo in xmlStringCurrentChar()
Thu Apr 12 17:41:09 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* HTMLparser.c result/HTML/*: revamped the way the HTML
......
......@@ -81,6 +81,47 @@ static int xmlLittleEndian = 1;
* I hope we won't use values > 0xFFFF anytime soon !
*/
/**
* xmlUTF8Strlen:
* @utf: a sequence of UTF-8 encoded bytes
*
* compute the lenght of an UTF8 string, it doesn't do a full UTF8
* checking of the content of the string.
*
* Returns the number of characters in the string or -1 in case of error
*/
int
xmlUTF8Strlen(const unsigned char *utf) {
int ret = 0;
if (utf == NULL)
return(-1);
while (*utf != 0) {
if (utf[0] & 0x80) {
if ((utf[1] & 0xc0) != 0x80)
return(-1);
if ((utf[0] & 0xe0) == 0xe0) {
if ((utf[2] & 0xc0) != 0x80)
return(-1);
if ((utf[0] & 0xf0) == 0xf0) {
if ((utf[0] & 0xf8) != 0xf0 || (utf[3] & 0xc0) != 0x80)
return(-1);
utf += 4;
} else {
utf += 3;
}
} else {
utf += 2;
}
} else {
utf++;
}
ret++;
}
return(ret);
}
/**
* xmlGetUTF8Char:
* @utf: a sequence of UTF-8 encoded bytes
......
......@@ -166,8 +166,6 @@ xmlCharEncoding
xmlDetectCharEncoding (const unsigned char* in,
int len);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
xmlBufferPtr out,
xmlBufferPtr in);
......@@ -191,6 +189,9 @@ int isolat1ToUTF8 (unsigned char* out,
int *outlen,
const unsigned char* in,
int *inlen);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlUTF8Strlen (const unsigned char *utf);
#ifdef __cplusplus
}
#endif
......
......@@ -166,8 +166,6 @@ xmlCharEncoding
xmlDetectCharEncoding (const unsigned char* in,
int len);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
xmlBufferPtr out,
xmlBufferPtr in);
......@@ -191,6 +189,9 @@ int isolat1ToUTF8 (unsigned char* out,
int *outlen,
const unsigned char* in,
int *inlen);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlUTF8Strlen (const unsigned char *utf);
#ifdef __cplusplus
}
#endif
......
......@@ -1435,7 +1435,7 @@ xmlStringCurrentChar(xmlParserCtxtPtr ctxt, const xmlChar *cur, int *len) {
/* 2-byte code */
*len = 2;
val = (cur[0] & 0x1f) << 6;
val |= cur[2] & 0x3f;
val |= cur[1] & 0x3f;
}
if (!IS_CHAR(val)) {
if ((ctxt->sax != NULL) &&
......
......@@ -106,7 +106,7 @@ xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) {
*/
xmlBufferAllocationScheme
xmlGetBufferAllocationScheme(void) {
return xmlBufferAllocScheme;
return(xmlBufferAllocScheme);
}
/**
......
......@@ -4280,7 +4280,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlChar *content;
content = xmlNodeGetContent(ctxt->context->node);
valuePush(ctxt, xmlXPathNewFloat(xmlStrlen(content)));
valuePush(ctxt, xmlXPathNewFloat(xmlUTF8Strlen(content)));
xmlFree(content);
}
return;
......@@ -4289,7 +4289,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) {
CAST_TO_STRING;
CHECK_TYPE(XPATH_STRING);
cur = valuePop(ctxt);
valuePush(ctxt, xmlXPathNewFloat(xmlStrlen(cur->stringval)));
valuePush(ctxt, xmlXPathNewFloat(xmlUTF8Strlen(cur->stringval)));
xmlXPathFreeObject(cur);
}
......@@ -4441,7 +4441,7 @@ xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlChar *ret;
/*
* Conformance needs to be checked !!!!!
* TODO: need to be converted to UTF8 strings
*/
if (nargs < 2) {
CHECK_ARITY(2);
......@@ -4680,6 +4680,9 @@ xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlChar ch;
const xmlChar *point;
/*
* TODO: need to be converted to UTF8 strings
*/
CHECK_ARITY(3);
CAST_TO_STRING;
......@@ -4695,7 +4698,6 @@ xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
for (i = 0; (ch = str->stringval[i]); i++) {
point = xmlStrchr(from->stringval, ch);
if (point) {
/* Warning: This may not work with UTF-8 */
offset = (int)(point - from->stringval);
if (offset < max)
xmlBufferAdd(target, &to->stringval[offset], 1);
......@@ -6542,6 +6544,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
xmlXPathTypeVal type = op->value3;
const xmlChar *prefix = op->value4;
const xmlChar *name = op->value5;
const xmlChar *URI = NULL;
#ifdef DEBUG_STEP
int n = 0, t = 0;
......@@ -6558,6 +6561,11 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
CHECK_TYPE(XPATH_NODESET);
obj = valuePop(ctxt);
addNode = xmlXPathNodeSetAdd;
if (prefix != NULL) {
URI = xmlXPathNsLookup(ctxt->context, prefix);
if (URI == NULL)
XP_ERROR(XPATH_UNDEF_PREFIX_ERROR);
}
#ifdef DEBUG_STEP
xmlGenericError(xmlGenericErrorContext,
......@@ -6777,7 +6785,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
#endif
addNode(list, cur);
} else if ((cur->ns != NULL) &&
(xmlStrEqual(prefix,
(xmlStrEqual(URI,
cur->ns->href))) {
#ifdef DEBUG_STEP
n++;
......@@ -6805,7 +6813,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
}
} else {
if ((cur->ns != NULL) &&
(xmlStrEqual(prefix,
(xmlStrEqual(URI,
cur->ns->href))) {
#ifdef DEBUG_STEP
n++;
......@@ -6828,7 +6836,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
}
} else {
if ((attr->ns != NULL) &&
(xmlStrEqual(prefix,
(xmlStrEqual(URI,
attr->ns->href))) {
#ifdef DEBUG_STEP
n++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment