void StringUTF8::replace(const std::string& newStr) { _str.clear(); if (!newStr.empty()) { UTF8* sequenceUtf8 = (UTF8*)newStr.c_str(); int lengthString = getUTF8StringLength(sequenceUtf8); if (lengthString == 0) { CCLOG("Bad utf-8 set string: %s", newStr.c_str()); return; } while (*sequenceUtf8) { std::size_t lengthChar = getNumBytesForUTF8(*sequenceUtf8); CharUTF8 charUTF8; charUTF8._char.append((char*)sequenceUtf8, lengthChar); sequenceUtf8 += lengthChar; _str.push_back(charUTF8); } } }
/** * Convert the first UTF8 sequence in the given source buffer to a UTF32 * code point. * * \param [in,out] source A pointer to the source buffer. If the conversion * succeeds, this pointer will be updated to point to the byte just past the * end of the converted sequence. * \param sourceEnd A pointer just past the end of the source buffer. * \param [out] target The converted code * \param flags Whether the conversion is strict or lenient. * * \returns conversionOK on success * * \sa ConvertUTF8toUTF32 */ static inline ConversionResult convertUTF8Sequence(const UTF8 **source, const UTF8 *sourceEnd, UTF32 *target, ConversionFlags flags) { if (*source == sourceEnd) return sourceExhausted; unsigned size = getNumBytesForUTF8(**source); if ((ptrdiff_t)size > sourceEnd - *source) return sourceExhausted; return ConvertUTF8toUTF32(source, *source + size, &target, target + 1, flags); }