* xmlSwitchEncoding: * @ctxt: the parser context * @enc: the encoding value (number) * * Use encoding specified by enum to decode input data. This overrides * the encoding found in the XML declaration. * * This function can also be used to override the encoding of chunks * passed to xmlParseChunk. * * Returns 0 in case of success, -1 otherwise */
| 1057 | * Returns 0 in case of success, -1 otherwise |
| 1058 | */ |
| 1059 | int |
| 1060 | xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) |
| 1061 | { |
| 1062 | xmlCharEncodingHandlerPtr handler = NULL; |
| 1063 | int ret; |
| 1064 | int res; |
| 1065 | |
| 1066 | if ((ctxt == NULL) || (ctxt->input == NULL)) |
| 1067 | return(-1); |
| 1068 | |
| 1069 | switch (enc) { |
| 1070 | case XML_CHAR_ENCODING_NONE: |
| 1071 | case XML_CHAR_ENCODING_UTF8: |
| 1072 | case XML_CHAR_ENCODING_ASCII: |
| 1073 | res = 0; |
| 1074 | break; |
| 1075 | case XML_CHAR_ENCODING_EBCDIC: |
| 1076 | res = xmlDetectEBCDIC(ctxt->input, &handler); |
| 1077 | break; |
| 1078 | default: |
| 1079 | res = xmlLookupCharEncodingHandler(enc, &handler); |
| 1080 | break; |
| 1081 | } |
| 1082 | |
| 1083 | if (res != 0) { |
| 1084 | const char *name = xmlGetCharEncodingName(enc); |
| 1085 | |
| 1086 | xmlFatalErr(ctxt, res, (name ? name : "<null>")); |
| 1087 | return(-1); |
| 1088 | } |
| 1089 | |
| 1090 | ret = xmlSwitchInputEncoding(ctxt, ctxt->input, handler); |
| 1091 | |
| 1092 | if ((ret >= 0) && (enc == XML_CHAR_ENCODING_NONE)) { |
| 1093 | ctxt->input->flags &= ~XML_INPUT_HAS_ENCODING; |
| 1094 | } |
| 1095 | |
| 1096 | return(ret); |
| 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * xmlSwitchEncodingName: |
no test coverage detected