mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +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:
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
|
||||
|
Reference in New Issue
Block a user