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

Function xmlCopyCharMultiByte

ThirdParty/libxml2/vtklibxml2/parserInternals.c:909–940  ·  view source on GitHub ↗

* xmlCopyCharMultiByte: * @out: pointer to an array of xmlChar * @val: the char value * * append the char value in the array * * Returns the number of xmlChar written */

Source from the content-addressed store, hash-verified

907 * Returns the number of xmlChar written
908 */
909int
910xmlCopyCharMultiByte(xmlChar *out, int val) {
911 if ((out == NULL) || (val < 0)) return(0);
912 /*
913 * We are supposed to handle UTF8, check it's valid
914 * From rfc2044: encoding of the Unicode values on UTF-8:
915 *
916 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
917 * 0000 0000-0000 007F 0xxxxxxx
918 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
919 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
920 */
921 if (val >= 0x80) {
922 xmlChar *savedout = out;
923 int bits;
924 if (val < 0x800) { *out++= (val >> 6) | 0xC0; bits= 0; }
925 else if (val < 0x10000) { *out++= (val >> 12) | 0xE0; bits= 6;}
926 else if (val < 0x110000) { *out++= (val >> 18) | 0xF0; bits= 12; }
927 else {
928#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
929 fprintf(stderr, "xmlCopyCharMultiByte: codepoint out of range\n");
930 abort();
931#endif
932 return(0);
933 }
934 for ( ; bits >= 0; bits-= 6)
935 *out++= ((val >> bits) & 0x3F) | 0x80 ;
936 return (out - savedout);
937 }
938 *out = val;
939 return 1;
940}
941
942/**
943 * xmlCopyChar:

Callers 3

xmlCopyCharFunction · 0.85
xmlSBufAddCharFunction · 0.85

Calls 1

fprintfFunction · 0.85

Tested by

no test coverage detected