* xmlUTF8Strlen: * @utf: a sequence of UTF-8 encoded bytes * * compute the length 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 */
| 811 | * Returns the number of characters in the string or -1 in case of error |
| 812 | */ |
| 813 | int |
| 814 | xmlUTF8Strlen(const xmlChar *utf) { |
| 815 | size_t ret = 0; |
| 816 | |
| 817 | if (utf == NULL) |
| 818 | return(-1); |
| 819 | |
| 820 | while (*utf != 0) { |
| 821 | if (utf[0] & 0x80) { |
| 822 | if ((utf[1] & 0xc0) != 0x80) |
| 823 | return(-1); |
| 824 | if ((utf[0] & 0xe0) == 0xe0) { |
| 825 | if ((utf[2] & 0xc0) != 0x80) |
| 826 | return(-1); |
| 827 | if ((utf[0] & 0xf0) == 0xf0) { |
| 828 | if ((utf[0] & 0xf8) != 0xf0 || (utf[3] & 0xc0) != 0x80) |
| 829 | return(-1); |
| 830 | utf += 4; |
| 831 | } else { |
| 832 | utf += 3; |
| 833 | } |
| 834 | } else { |
| 835 | utf += 2; |
| 836 | } |
| 837 | } else { |
| 838 | utf++; |
| 839 | } |
| 840 | ret++; |
| 841 | } |
| 842 | return(ret > INT_MAX ? 0 : ret); |
| 843 | } |
| 844 | |
| 845 | /** |
| 846 | * xmlGetUTF8Char: |
no outgoing calls
no test coverage detected