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

Function xmlSwitchInputEncoding

ThirdParty/libxml2/vtklibxml2/parserInternals.c:1166–1245  ·  view source on GitHub ↗

* xmlSwitchInputEncoding: * @ctxt: the parser context, only for error reporting * @input: the input stream * @handler: the encoding handler * * DEPRECATED: Internal function, don't use. * * Use encoding handler to decode input data. * * Returns 0 in case of success, -1 otherwise */

Source from the content-addressed store, hash-verified

1164 * Returns 0 in case of success, -1 otherwise
1165 */
1166int
1167xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
1168 xmlCharEncodingHandlerPtr handler)
1169{
1170 int nbchars;
1171 xmlParserInputBufferPtr in;
1172
1173 if ((input == NULL) || (input->buf == NULL)) {
1174 xmlCharEncCloseFunc(handler);
1175 return (-1);
1176 }
1177 in = input->buf;
1178
1179 input->flags |= XML_INPUT_HAS_ENCODING;
1180
1181 /*
1182 * UTF-8 requires no encoding handler.
1183 */
1184 if ((handler != NULL) &&
1185 (xmlStrcasecmp(BAD_CAST handler->name, BAD_CAST "UTF-8") == 0)) {
1186 xmlCharEncCloseFunc(handler);
1187 handler = NULL;
1188 }
1189
1190 if (in->encoder == handler)
1191 return (0);
1192
1193 if (in->encoder != NULL) {
1194 /*
1195 * Switching encodings during parsing is a really bad idea,
1196 * but Chromium can switch between ISO-8859-1 and UTF-16 before
1197 * separate calls to xmlParseChunk.
1198 *
1199 * TODO: We should check whether the "raw" input buffer is empty and
1200 * convert the old content using the old encoder.
1201 */
1202
1203 xmlCharEncCloseFunc(in->encoder);
1204 in->encoder = handler;
1205 return (0);
1206 }
1207
1208 in->encoder = handler;
1209
1210 /*
1211 * Is there already some content down the pipe to convert ?
1212 */
1213 if (xmlBufIsEmpty(in->buffer) == 0) {
1214 xmlBufPtr buf;
1215 size_t processed;
1216
1217 buf = xmlBufCreate();
1218 if (buf == NULL) {
1219 xmlCtxtErrMemory(ctxt);
1220 return(-1);
1221 }
1222
1223 /*

Callers 4

xmlSwitchEncodingFunction · 0.85
xmlSwitchToEncodingFunction · 0.85
xmlSetDeclaredEncodingFunction · 0.85

Calls 9

xmlCharEncCloseFuncFunction · 0.85
xmlBufIsEmptyFunction · 0.85
xmlBufCreateFunction · 0.85
xmlCtxtErrMemoryFunction · 0.85
xmlBufShrinkFunction · 0.85
xmlCharEncInputFunction · 0.85
xmlBufResetInputFunction · 0.85
xmlCtxtErrIOFunction · 0.85
xmlHaltParserFunction · 0.85

Tested by

no test coverage detected