From 31a735c8ec0a4f7c62b162cd1c173bfef76737c5 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 20 Mar 2019 19:18:57 +1100 Subject: Backport: Implement WStringFromUTF8 to simplify code that creates wstring objects for regular expressions and calling the Win32 API. Backport of changeset 7325:6148329fb2f3, but replaced std::string_view usage with const char* and size_t components. Also used #ifdef instead of C++17 `if constexpr` at suggestion of Neil. --- src/UniConversion.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/UniConversion.h') diff --git a/src/UniConversion.h b/src/UniConversion.h index 4bb8875d0..9f405e1ed 100644 --- a/src/UniConversion.h +++ b/src/UniConversion.h @@ -19,7 +19,11 @@ void UTF8FromUTF16(const wchar_t *uptr, size_t tlen, char *putf, size_t len); void UTF8FromUTF32Character(int uch, char *putf); size_t UTF16Length(const char *s, size_t len); size_t UTF16FromUTF8(const char *s, size_t len, wchar_t *tbuf, size_t tlen); +size_t UTF32Length(const char *s, size_t len) noexcept; size_t UTF32FromUTF8(const char *s, size_t len, unsigned int *tbuf, size_t tlen); +// WStringFromUTF8 does the right thing when wchar_t is 2 or 4 bytes so +// works on both Windows and Unix. +std::wstring WStringFromUTF8(const char *s, size_t len); unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept; bool UTF8IsValid(const char *s, size_t len) noexcept; std::string FixInvalidUTF8(const std::string &text); -- cgit v1.2.3