32 #ifndef _QORE_ENCODINGCONVERTOR_H
33 #define _QORE_ENCODINGCONVERTOR_H
35 #include "qore/Transform.h"
38 class EncodingConvertor :
public Transform {
42 : conv(dstEncoding, srcEncoding, xsink), inCount(0), outCount(0) {
47 const char *srcPtr =
static_cast<const char *
>(src);
48 char *dstPtr =
static_cast<char *
>(dst);
50 size_t r =
QORE_MIN(
static_cast<size_t>(srcLen), BUFSIZE - inCount);
52 memcpy(inBuf + inCount, srcPtr, r);
59 size_t inavail = inCount;
60 char *outbuf = outBuf + outCount;
61 size_t outavail = BUFSIZE - outCount;
62 if (conv.iconv(&inbuf, &inavail, &outbuf, &outavail) == (
size_t) -1) {
66 conv.reportIllegalSequence(inbuf - inBuf, xsink);
67 return std::make_pair(0, 0);
73 conv.reportIllegalSequence(inbuf - inBuf, xsink);
74 return std::make_pair(0, 0);
76 conv.reportUnknownError(xsink);
77 return std::make_pair(0, 0);
80 size_t rc = inCount - inavail;
83 memmove(inBuf, inBuf + rc, inCount);
86 size_t wc = BUFSIZE - outCount - outavail;
89 size_t w =
QORE_MIN(
static_cast<size_t>(dstLen), outCount);
91 memcpy(dstPtr, outBuf, w);
95 memmove(outBuf, outBuf + w, outCount);
98 if (r == 0 && w == 0) {
99 return std::make_pair(srcPtr -
static_cast<const char *
>(src), dstPtr -
static_cast<char *
>(dst));
105 static constexpr
size_t BUFSIZE = 4096;
109 char outBuf[BUFSIZE];
Defines a helper class wrapping libiconv.
#define QORE_MIN(a, b)
macro to return the minimum of 2 numbers
Definition: QoreLib.h:550
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260