Ejemplo n.º 1
0
bool UTF8ToUTF32(const std::string& utf8, std::u32string& outUtf32)
{
	if (utf8.empty())
	{
		outUtf32.clear();
		return true;
	}

	bool ret = false;

	const size_t utf32Bytes = (utf8.length() + 1) * sizeof(char32_t);
	char32_t* utf32 = (char32_t*)malloc(utf32Bytes);
	memset(utf32, 0, utf32Bytes);

	char* utf32ptr = reinterpret_cast<char*>(utf32);
	const UTF8* error = NULL;

	if (llvm::ConvertUTF8toWide(4, utf8, utf32ptr, error))
	{
		outUtf32 = utf32;
		ret = true;
	}

	free(utf32);

	return ret;
}
Ejemplo n.º 2
0
void utf8::decode(const char* str, size_t len, std::u32string& decoded) {
  decoded.clear();

  while (len)
    decoded.push_back(decode(str, len));
}
Ejemplo n.º 3
0
void utf8::decode(const char* str, std::u32string& decoded) {
  decoded.clear();

  for (char32_t chr; (chr = decode(str)); )
    decoded.push_back(chr);
}