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

Function xmlByteConsumed

ThirdParty/libxml2/vtklibxml2/encoding.c:2727–2765  ·  view source on GitHub ↗

* xmlByteConsumed: * @ctxt: an XML parser context * * This function provides the current index of the parser relative * to the start of the current entity. This function is computed in * bytes from the beginning starting at zero and finishing at the * size in byte of the file if parsing a file. The function is * of constant cost if the input is UTF-8 but can be costly if run * on non-UTF-8

Source from the content-addressed store, hash-verified

2725 * in case the index could not be computed.
2726 */
2727long
2728xmlByteConsumed(xmlParserCtxtPtr ctxt) {
2729 xmlParserInputPtr in;
2730
2731 if (ctxt == NULL) return(-1);
2732 in = ctxt->input;
2733 if (in == NULL) return(-1);
2734 if ((in->buf != NULL) && (in->buf->encoder != NULL)) {
2735 unsigned int unused = 0;
2736 xmlCharEncodingHandler * handler = in->buf->encoder;
2737 /*
2738 * Encoding conversion, compute the number of unused original
2739 * bytes from the input not consumed and subtract that from
2740 * the raw consumed value, this is not a cheap operation
2741 */
2742 if (in->end - in->cur > 0) {
2743 unsigned char convbuf[32000];
2744 const unsigned char *cur = (const unsigned char *)in->cur;
2745 int toconv = in->end - in->cur, written = 32000;
2746
2747 int ret;
2748
2749 do {
2750 toconv = in->end - cur;
2751 written = 32000;
2752 ret = xmlEncOutputChunk(handler, &convbuf[0], &written,
2753 cur, &toconv);
2754 if ((ret != XML_ENC_ERR_SUCCESS) && (ret != XML_ENC_ERR_SPACE))
2755 return(-1);
2756 unused += written;
2757 cur += toconv;
2758 } while (ret == XML_ENC_ERR_SPACE);
2759 }
2760 if (in->buf->rawconsumed < unused)
2761 return(-1);
2762 return(in->buf->rawconsumed - unused);
2763 }
2764 return(in->consumed + (in->cur - in->base));
2765}
2766
2767#if !defined(LIBXML_ICONV_ENABLED) && !defined(LIBXML_ICU_ENABLED)
2768#ifdef LIBXML_ISO8859X_ENABLED

Callers 1

Calls 1

xmlEncOutputChunkFunction · 0.85

Tested by

no test coverage detected