Esempio n. 1
0
size_t utf8towide(const char* input, size_t inputSize, wchar_t* target, size_t targetSize, int32_t* errors)
{
#if UTF8_WCHAR_UTF16
	return utf8toutf16(input, inputSize, (utf16_t*)target, targetSize, errors);
#elif UTF8_WCHAR_UTF32
	return utf8toutf32(input, inputSize, (unicode_t*)target, targetSize, errors);
#else
	return SIZE_MAX;
#endif
}
PERF_TEST_F(BigConversion, Utf32)
{
	int32_t e;

	size_t ol = utf8toutf32(m_contents.c_str(), m_contents.length(), nullptr, 0, &e);

	PERF_ASSERT(ol > 0);
	PERF_ASSERT(e == UTF8_ERR_NONE);

	if (ol > 0 &&
		e == UTF8_ERR_NONE)
	{
		unicode_t* o = new unicode_t[(ol / sizeof(unicode_t)) + 1];
		memset(o, 0, ol + sizeof(unicode_t));

		utf8toutf32(m_contents.c_str(), m_contents.length(), o, ol, nullptr);

		delete [] o;
	}
}
Esempio n. 3
0
int wind_utf8ucs4(const char *in, unsigned *out, unsigned *out_len)
{
	const unsigned char *p;
	size_t o = 0;
	int ret;

	for (p = (const unsigned char *)in; *p != '\0'; ++p) {
		uint32_t u;

		ret = utf8toutf32(&p, &u);
		if (ret)
			return ret;

		if (out) {
			if (o >= *out_len)
				return WIND_ERR_OVERRUN;
			out[o] = u;
		}
		o++;
	}
	*out_len = o;
	return 0;
}