diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2016-03-02 11:23:18 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2016-03-02 11:24:23 -0800 |
commit | 58d56f91f36b56d83423028e04e9faabd3bad3d2 (patch) | |
tree | 800dfc53954a820a14455a5547866edc00ef6109 /src/utf8.h | |
parent | 0e8a8a7c8023e05792b8b1d32ddbe7bcf2ea3549 (diff) |
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.
Diffstat (limited to 'src/utf8.h')
-rw-r--r-- | src/utf8.h | 5 |
1 files changed, 2 insertions, 3 deletions
@@ -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(); |