MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlUTF8Strlen

Function xmlUTF8Strlen

ThirdParty/libxml2/vtklibxml2/xmlstring.c:813–843  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

811 * Returns the number of characters in the string or -1 in case of error
812 */
813int
814xmlUTF8Strlen(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:

Calls

no outgoing calls

Tested by

no test coverage detected