Fix operator+= for UTF8 class
Added operator+=(wchar_t), as operator+=(char) was not sufficient to handle multibyte characters present in UTF8. Fixes: lp:1737143 * https://bugs.launchpad.net/kicad/+bug/1737143
This commit is contained in:
parent
7ca7d9078e
commit
d958ab9460
|
@ -44,7 +44,10 @@ std::pair<UTF8, std::vector<bool>> ProcessOverbars( const UTF8& aText )
|
||||||
// If it is a double tilda, just process the second one
|
// 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 );
|
flags.push_back( overbar );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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:
|
#if 0 // some unit tests:
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
@ -145,6 +145,10 @@ public:
|
||||||
return (UTF8&) *this;
|
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
|
// std::string::npos is not constexpr, so we can't use it in an
|
||||||
// initializer.
|
// initializer.
|
||||||
static constexpr std::string::size_type npos = -1;
|
static constexpr std::string::size_type npos = -1;
|
||||||
|
|
Loading…
Reference in New Issue