* xmlUTF8Strloc: * @utf: the input UTF8 * * @utfchar: the UTF8 character to be found * * a function to provide the relative location of a UTF8 char * * Returns the relative character position of the desired char * or -1 if not found */
| 1073 | * or -1 if not found |
| 1074 | */ |
| 1075 | int |
| 1076 | xmlUTF8Strloc(const xmlChar *utf, const xmlChar *utfchar) { |
| 1077 | size_t i; |
| 1078 | int size; |
| 1079 | int ch; |
| 1080 | |
| 1081 | if (utf==NULL || utfchar==NULL) return -1; |
| 1082 | size = xmlUTF8Strsize(utfchar, 1); |
| 1083 | for(i=0; (ch=*utf) != 0; i++) { |
| 1084 | if (xmlStrncmp(utf, utfchar, size)==0) |
| 1085 | return(i > INT_MAX ? 0 : i); |
| 1086 | utf++; |
| 1087 | if ( ch & 0x80 ) { |
| 1088 | /* if not simple ascii, verify proper format */ |
| 1089 | if ( (ch & 0xc0) != 0xc0 ) |
| 1090 | return(-1); |
| 1091 | /* then skip over remaining bytes for this char */ |
| 1092 | while ( (ch <<= 1) & 0x80 ) |
| 1093 | if ( (*utf++ & 0xc0) != 0x80 ) |
| 1094 | return(-1); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | return(-1); |
| 1099 | } |
| 1100 | /** |
| 1101 | * xmlUTF8Strsub: |
| 1102 | * @utf: a sequence of UTF-8 encoded bytes |
no test coverage detected