| 2632 | */ |
| 2633 | |
| 2634 | void |
| 2635 | xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr, |
| 2636 | int * doc_txt_len, const char * txt_encoding, |
| 2637 | int format) { |
| 2638 | xmlSaveCtxt ctxt; |
| 2639 | int dummy = 0; |
| 2640 | xmlOutputBufferPtr out_buff = NULL; |
| 2641 | xmlCharEncodingHandlerPtr conv_hdlr = NULL; |
| 2642 | |
| 2643 | if (doc_txt_len == NULL) { |
| 2644 | doc_txt_len = &dummy; /* Continue, caller just won't get length */ |
| 2645 | } |
| 2646 | |
| 2647 | if (doc_txt_ptr == NULL) { |
| 2648 | *doc_txt_len = 0; |
| 2649 | return; |
| 2650 | } |
| 2651 | |
| 2652 | *doc_txt_ptr = NULL; |
| 2653 | *doc_txt_len = 0; |
| 2654 | |
| 2655 | if (out_doc == NULL) { |
| 2656 | /* No document, no output */ |
| 2657 | return; |
| 2658 | } |
| 2659 | |
| 2660 | /* |
| 2661 | * Validate the encoding value, if provided. |
| 2662 | * This logic is copied from xmlSaveFileEnc. |
| 2663 | */ |
| 2664 | |
| 2665 | if (txt_encoding == NULL) |
| 2666 | txt_encoding = (const char *) out_doc->encoding; |
| 2667 | if (txt_encoding != NULL) { |
| 2668 | int res; |
| 2669 | |
| 2670 | res = xmlOpenCharEncodingHandler(txt_encoding, /* output */ 1, |
| 2671 | &conv_hdlr); |
| 2672 | if (res != XML_ERR_OK) { |
| 2673 | xmlSaveErr(NULL, res, NULL, txt_encoding); |
| 2674 | return; |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) { |
| 2679 | xmlSaveErrMemory(NULL); |
| 2680 | xmlCharEncCloseFunc(conv_hdlr); |
| 2681 | return; |
| 2682 | } |
| 2683 | |
| 2684 | memset(&ctxt, 0, sizeof(ctxt)); |
| 2685 | ctxt.buf = out_buff; |
| 2686 | ctxt.level = 0; |
| 2687 | ctxt.format = format ? 1 : 0; |
| 2688 | ctxt.encoding = (const xmlChar *) txt_encoding; |
| 2689 | xmlSaveCtxtInit(&ctxt); |
| 2690 | ctxt.options |= XML_SAVE_AS_XML; |
| 2691 | xmlDocContentDumpOutput(&ctxt, out_doc); |
no test coverage detected