diff --git a/common/text_utils.cpp b/common/text_utils.cpp index 2d0d635e61..f1015ed8aa 100644 --- a/common/text_utils.cpp +++ b/common/text_utils.cpp @@ -44,7 +44,10 @@ std::pair> ProcessOverbars( const UTF8& aText ) // If it is a double tilda, just process the second one } - text += *chIt; + // remember: *chIt is not necessary a ASCII7 char. + // it is an unsigned ( wchar_t ) giving a multibyte char in UTF8 strings + text += wchar_t( *chIt ); + flags.push_back( overbar ); } diff --git a/common/utf8.cpp b/common/utf8.cpp index 1d4bf1d555..50b61b914b 100644 --- a/common/utf8.cpp +++ b/common/utf8.cpp @@ -218,6 +218,23 @@ UTF8::UTF8( const wchar_t* txt ) : } +UTF8& UTF8::operator+=( wchar_t ch ) +{ + if( ch <= 0x7F ) + m_s.operator+=( char( ch ) ); + else + { + wchar_t wide_chr[2]; // buffer to store wide chars (unicode) read from aText + wide_chr[1] = 0; + wide_chr[0] = ch; + UTF8 substr( wide_chr ); + m_s += substr.m_s; + } + + return (UTF8&) *this; +} + + #if 0 // some unit tests: #include diff --git a/include/utf8.h b/include/utf8.h index e78e8fd09e..cb4b4e3ccf 100644 --- a/include/utf8.h +++ b/include/utf8.h @@ -145,6 +145,10 @@ public: return (UTF8&) *this; } + /// Append a wide (unicode) char to the UTF8 string. + /// if this char is not a ASCII7 char, it will be added as a UTF8 multibyte seqence + UTF8& operator+=( wchar_t ch ); + // std::string::npos is not constexpr, so we can't use it in an // initializer. static constexpr std::string::size_type npos = -1;