* htmlDocDumpMemoryFormat: * @cur: the document * @mem: OUT: the memory pointer * @size: OUT: the memory length * @format: should formatting spaces been added * * Dump an HTML document in memory and return the xmlChar * and it's size. * It's up to the caller to free the memory. */
| 544 | * It's up to the caller to free the memory. |
| 545 | */ |
| 546 | void |
| 547 | htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) { |
| 548 | xmlOutputBufferPtr buf; |
| 549 | xmlCharEncodingHandlerPtr handler = NULL; |
| 550 | const char *encoding; |
| 551 | |
| 552 | xmlInitParser(); |
| 553 | |
| 554 | if ((mem == NULL) || (size == NULL)) |
| 555 | return; |
| 556 | *mem = NULL; |
| 557 | *size = 0; |
| 558 | if (cur == NULL) |
| 559 | return; |
| 560 | |
| 561 | encoding = (const char *) htmlGetMetaEncoding(cur); |
| 562 | handler = htmlFindOutputEncoder(encoding); |
| 563 | buf = xmlAllocOutputBufferInternal(handler); |
| 564 | if (buf == NULL) { |
| 565 | xmlCharEncCloseFunc(handler); |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | htmlDocContentDumpFormatOutput(buf, cur, NULL, format); |
| 570 | |
| 571 | xmlOutputBufferFlush(buf); |
| 572 | |
| 573 | if (!buf->error) { |
| 574 | if (buf->conv != NULL) { |
| 575 | *size = xmlBufUse(buf->conv); |
| 576 | *mem = xmlStrndup(xmlBufContent(buf->conv), *size); |
| 577 | } else { |
| 578 | *size = xmlBufUse(buf->buffer); |
| 579 | *mem = xmlStrndup(xmlBufContent(buf->buffer), *size); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | xmlOutputBufferClose(buf); |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * htmlDocDumpMemory: |
no test coverage detected