bool convert(int srcCodepage, int dstCodepage, const unsigned char * src, size_t * srcbytes, unsigned char * dest, size_t * destbytes) { bool bsucceeded; #ifdef POCO_ARCH_BIG_ENDIAN if (srcCodepage == ucr::CP_UCS2BE) #else if (srcCodepage == ucr::CP_UCS2LE) #endif { size_t srcwchars = *srcbytes / sizeof(wchar_t); bsucceeded = convertFromUnicode(dstCodepage, (const wchar_t *)src, &srcwchars, (char *)dest, destbytes); *srcbytes = srcwchars * sizeof(wchar_t); } else { size_t wsize = *srcbytes * 2 + 6; std::unique_ptr<wchar_t[]> pbuf(new wchar_t[wsize]); bsucceeded = convertToUnicode(srcCodepage, (const char *)src, srcbytes, pbuf.get(), &wsize); if (!bsucceeded) { *destbytes = 0; return false; } bsucceeded = convertFromUnicode(dstCodepage, pbuf.get(), &wsize, (char *)dest, destbytes); } return bsucceeded; }
/*! \overload \a s contains the string being tested for encode-ability. */ bool QTextCodec::canEncode(const QString& s) const { ConverterState state; state.flags = ConvertInvalidToNull; convertFromUnicode(s.constData(), s.length(), &state); return (state.invalidChars == 0); }
/*! Returns true if the Unicode character \a ch can be fully encoded with this codec; otherwise returns false. */ bool QTextCodec::canEncode(QChar ch) const { ConverterState state; state.flags = ConvertInvalidToNull; convertFromUnicode(&ch, 1, &state); return (state.invalidChars == 0); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Get data element as a string // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// std::string dataHandlerString::getString(const imbxUint32 index) const { PUNTOEXE_FUNCTION_START(L"dataHandlerString::getString"); charsetsList::tCharsetsList localCharsetsList(m_charsetsList); return convertFromUnicode(getUnicodeString(index), &localCharsetsList); PUNTOEXE_FUNCTION_END(); }
QByteArray QTextCodec::fromUnicode(const QString& uc, int& lenInOut) const { QByteArray result = convertFromUnicode(uc.constData(), lenInOut, 0); lenInOut = result.length(); return result; }
/*! Converts \a str from Unicode to the encoding of this codec, and returns the result in a QByteArray. */ QByteArray QTextCodec::fromUnicode(const QString& str) const { return convertFromUnicode(str.constData(), str.length(), 0); }