mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-27 03:21:26 +03:00
- 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
This commit is contained in:
parent
a3bfca59bf
commit
e043ee17c2
@ -1,3 +1,10 @@
|
||||
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
|
||||
|
41
encoding.c
41
encoding.c
@ -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) &&
|
||||
|
2
tree.c
2
tree.c
@ -106,7 +106,7 @@ xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) {
|
||||
*/
|
||||
xmlBufferAllocationScheme
|
||||
xmlGetBufferAllocationScheme(void) {
|
||||
return xmlBufferAllocScheme;
|
||||
return(xmlBufferAllocScheme);
|
||||
}
|
||||
|
||||
/**
|
||||
|
84
xpath.c
84
xpath.c
@ -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);
|
||||
@ -4672,42 +4672,44 @@ xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
|
||||
*/
|
||||
void
|
||||
xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
|
||||
xmlXPathObjectPtr str;
|
||||
xmlXPathObjectPtr from;
|
||||
xmlXPathObjectPtr to;
|
||||
xmlBufferPtr target;
|
||||
int i, offset, max;
|
||||
xmlChar ch;
|
||||
const xmlChar *point;
|
||||
xmlXPathObjectPtr str;
|
||||
xmlXPathObjectPtr from;
|
||||
xmlXPathObjectPtr to;
|
||||
xmlBufferPtr target;
|
||||
int i, offset, max;
|
||||
xmlChar ch;
|
||||
const xmlChar *point;
|
||||
|
||||
CHECK_ARITY(3);
|
||||
/*
|
||||
* TODO: need to be converted to UTF8 strings
|
||||
*/
|
||||
CHECK_ARITY(3);
|
||||
|
||||
CAST_TO_STRING;
|
||||
to = valuePop(ctxt);
|
||||
CAST_TO_STRING;
|
||||
from = valuePop(ctxt);
|
||||
CAST_TO_STRING;
|
||||
str = valuePop(ctxt);
|
||||
CAST_TO_STRING;
|
||||
to = valuePop(ctxt);
|
||||
CAST_TO_STRING;
|
||||
from = valuePop(ctxt);
|
||||
CAST_TO_STRING;
|
||||
str = valuePop(ctxt);
|
||||
|
||||
target = xmlBufferCreate();
|
||||
if (target) {
|
||||
max = xmlStrlen(to->stringval);
|
||||
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);
|
||||
} else
|
||||
xmlBufferAdd(target, &ch, 1);
|
||||
target = xmlBufferCreate();
|
||||
if (target) {
|
||||
max = xmlStrlen(to->stringval);
|
||||
for (i = 0; (ch = str->stringval[i]); i++) {
|
||||
point = xmlStrchr(from->stringval, ch);
|
||||
if (point) {
|
||||
offset = (int)(point - from->stringval);
|
||||
if (offset < max)
|
||||
xmlBufferAdd(target, &to->stringval[offset], 1);
|
||||
} else
|
||||
xmlBufferAdd(target, &ch, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
valuePush(ctxt, xmlXPathNewString(xmlBufferContent(target)));
|
||||
xmlBufferFree(target);
|
||||
xmlXPathFreeObject(str);
|
||||
xmlXPathFreeObject(from);
|
||||
xmlXPathFreeObject(to);
|
||||
valuePush(ctxt, xmlXPathNewString(xmlBufferContent(target)));
|
||||
xmlBufferFree(target);
|
||||
xmlXPathFreeObject(str);
|
||||
xmlXPathFreeObject(from);
|
||||
xmlXPathFreeObject(to);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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++;
|
||||
|
Loading…
Reference in New Issue
Block a user