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

Function xmlCharEncOutput

ThirdParty/libxml2/vtklibxml2/encoding.c:2432–2539  ·  view source on GitHub ↗

* xmlCharEncOutput: * @output: a parser output buffer * @init: is this an initialization call without data * * Generic front-end for the encoding handler on parser output * a first call with @init == 1 has to be made first to initiate the * output in case of non-stateless encoding needing to initiate their * state or the output (like the BOM in UTF16). * In case of UTF8 sequence conversion

Source from the content-addressed store, hash-verified

2430 * Returns the number of bytes written or an XML_ENC_ERR code.
2431 */
2432int
2433xmlCharEncOutput(xmlOutputBufferPtr output, int init)
2434{
2435 int ret;
2436 size_t written;
2437 int writtentot = 0;
2438 size_t toconv;
2439 int c_in;
2440 int c_out;
2441 xmlBufPtr in;
2442 xmlBufPtr out;
2443
2444 if ((output == NULL) || (output->encoder == NULL) ||
2445 (output->buffer == NULL) || (output->conv == NULL))
2446 return(XML_ENC_ERR_INTERNAL);
2447 out = output->conv;
2448 in = output->buffer;
2449
2450retry:
2451
2452 written = xmlBufAvail(out);
2453
2454 /*
2455 * First specific handling of the initialization call
2456 */
2457 if (init) {
2458 c_in = 0;
2459 c_out = written;
2460 /* TODO: Check return value. */
2461 xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
2462 NULL, &c_in);
2463 xmlBufAddLen(out, c_out);
2464 return(c_out);
2465 }
2466
2467 /*
2468 * Conversion itself.
2469 */
2470 toconv = xmlBufUse(in);
2471 if (toconv > 64 * 1024)
2472 toconv = 64 * 1024;
2473 if (toconv * 4 >= written) {
2474 if (xmlBufGrow(out, toconv * 4) < 0) {
2475 ret = XML_ENC_ERR_MEMORY;
2476 goto error;
2477 }
2478 written = xmlBufAvail(out);
2479 }
2480 if (written > 256 * 1024)
2481 written = 256 * 1024;
2482
2483 c_in = toconv;
2484 c_out = written;
2485 ret = xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
2486 xmlBufContent(in), &c_in);
2487 xmlBufShrink(in, c_in);
2488 xmlBufAddLen(out, c_out);
2489 writtentot += c_out;

Callers 7

xmlSaveSwitchEncodingFunction · 0.85
xmlAllocOutputBufferFunction · 0.85
xmlOutputBufferWriteFunction · 0.85
xmlOutputBufferFlushFunction · 0.85

Calls 10

xmlBufAvailFunction · 0.85
xmlEncOutputChunkFunction · 0.85
xmlBufEndFunction · 0.85
xmlBufAddLenFunction · 0.85
xmlBufUseFunction · 0.85
xmlBufGrowFunction · 0.85
xmlBufContentFunction · 0.85
xmlBufShrinkFunction · 0.85
xmlGetUTF8CharFunction · 0.85
xmlEncConvertErrorFunction · 0.85

Tested by

no test coverage detected