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/Document.cxx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/Document.cxx') diff --git a/src/Document.cxx b/src/Document.cxx index f1079398d..4aad2e370 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -3061,16 +3061,9 @@ Sci::Position Cxx11RegexFindText(const Document *doc, Sci::Position minPos, Sci: bool matched = false; if (SC_CP_UTF8 == doc->dbcsCodePage) { - const size_t lenS = strlen(s); - std::vector ws(lenS + 1); -#if WCHAR_T_IS_16 - const size_t outLen = UTF16FromUTF8(s, lenS, &ws[0], lenS); -#else - const size_t outLen = UTF32FromUTF8(s, lenS, reinterpret_cast(&ws[0]), lenS); -#endif - ws[outLen] = 0; + const std::wstring ws = WStringFromUTF8(s, strlen(s)); std::wregex regexp; - regexp.assign(&ws[0], flagsRe); + regexp.assign(ws, flagsRe); matched = MatchOnLines(doc, regexp, resr, search); } else { -- cgit v1.2.3