| 794 | ************************************************************************/ |
| 795 | |
| 796 | static int xmlSaveSwitchEncoding(xmlSaveCtxtPtr ctxt, const char *encoding) { |
| 797 | xmlOutputBufferPtr buf = ctxt->buf; |
| 798 | |
| 799 | if ((encoding != NULL) && (buf->encoder == NULL) && (buf->conv == NULL)) { |
| 800 | xmlCharEncodingHandler *handler; |
| 801 | int res; |
| 802 | |
| 803 | res = xmlOpenCharEncodingHandler(encoding, /* output */ 1, &handler); |
| 804 | if (res != XML_ERR_OK) { |
| 805 | xmlSaveErr(buf, res, NULL, encoding); |
| 806 | return(-1); |
| 807 | } |
| 808 | buf->conv = xmlBufCreate(); |
| 809 | if (buf->conv == NULL) { |
| 810 | xmlCharEncCloseFunc(handler); |
| 811 | xmlSaveErrMemory(buf); |
| 812 | return(-1); |
| 813 | } |
| 814 | buf->encoder = handler; |
| 815 | /* |
| 816 | * initialize the state, e.g. if outputting a BOM |
| 817 | */ |
| 818 | xmlCharEncOutput(buf, 1); |
| 819 | } |
| 820 | return(0); |
| 821 | } |
| 822 | |
| 823 | static int xmlSaveClearEncoding(xmlSaveCtxtPtr ctxt) { |
| 824 | xmlOutputBufferPtr buf = ctxt->buf; |
no test coverage detected