From 4dd77dabe8fe7e968458da2d6d23c6c257150f42 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 16 Jul 2021 11:21:41 +0200 Subject: [PATCH] Check for WXREGEX_CONVERT_TO_MB when calling regcomp() too Make code more consistent by using the same approach as in the other places where conversion is necessary in some builds and define temporary variables for clarity. Also use wx_str() when the conversion is not necessary rather than c_str() as this is more efficient and allows to address an existing FIXME comment. --- src/common/regex.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/regex.cpp b/src/common/regex.cpp index 96daab4dab..2b784a7314 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -549,12 +549,18 @@ bool wxRegExImpl::Compile(const wxString& expr, int flags) if ( flags & wxRE_NEWLINE ) flagsRE |= REG_NEWLINE; +#ifndef WXREGEX_CONVERT_TO_MB + const wxChar *exprstr = expr.wx_str(); +#else + const wxScopedCharBuffer exprbuf = expr.utf8_str(); + const char* const exprstr = exprbuf.data(); +#endif + // compile it #ifdef WXREGEX_USING_BUILTIN - // FIXME-UTF8: use wc_str() after removing ANSI build - int errorcode = wx_re_comp(&m_RegEx, expr.c_str(), expr.length(), flagsRE); + int errorcode = wx_re_comp(&m_RegEx, exprstr, expr.length(), flagsRE); #else - int errorcode = wx_regcomp(&m_RegEx, expr.utf8_str(), flagsRE); + int errorcode = wx_regcomp(&m_RegEx, exprstr, flagsRE); #endif if ( errorcode )