From 58d56f91f36b56d83423028e04e9faabd3bad3d2 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 2 Mar 2016 11:23:18 -0800 Subject: Tweak UTF8 decoding interface Previously, when decoding UTF-8, we would first run through the array to compute the correct size, then allocate a buffer of that size, then run through the array again to fill the buffer, and then copy it into a std::wstring. With this fix we can copy it into the string directly, reducing allocations and only requiring a single pass. --- src/utf8.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/utf8.h') diff --git a/src/utf8.h b/src/utf8.h index 1c9923db..33ed6a5e 100644 --- a/src/utf8.h +++ b/src/utf8.h @@ -28,11 +28,10 @@ #define UTF8_SKIP_BOM 0x02 /* Convert a string between UTF8 and UCS-2/4 (depending on size of wchar_t). Returns true if successful, storing the result of the conversion in *result */ -bool utf8_to_wchar_string(const std::string &input, std::wstring *result); bool wchar_to_utf8_string(const std::wstring &input, std::string *result); -/* Variants exposed for testing */ -size_t utf8_to_wchar(const char *in, size_t insize, wchar_t *out, size_t outsize, int flags); +/* Convert a string between UTF8 and UCS-2/4 (depending on size of wchar_t). Returns nonzero if successful, storing the result of the conversion in *out */ +size_t utf8_to_wchar(const char *in, size_t insize, std::wstring *out, int flags); size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, size_t outsize, int flags); bool is_wchar_ucs2(); -- cgit v1.2.3