Eeschema: Tokenize in UTF8
wchar tokenization breaks for wxWidgets on some platfoms. Fixes: lp:1852595 * https://bugs.launchpad.net/kicad/+bug/1852595
This commit is contained in:
parent
544867cf2a
commit
a89dc98e07
|
@ -105,41 +105,68 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( int aType )
|
||||||
|
|
||||||
if( aType != LAYER_NOTES )
|
if( aType != LAYER_NOTES )
|
||||||
{
|
{
|
||||||
wxString delimiters = wxT( " {}[]\t\r\n" );
|
UTF8 text( textItem->GetText() );
|
||||||
wxStringTokenizer tok( textItem->GetText(), delimiters, wxTOKEN_STRTOK );
|
int brace_count = 0;
|
||||||
|
int bracket_count = 0;
|
||||||
|
bool last_space = false;
|
||||||
|
UTF8 token;
|
||||||
|
|
||||||
while( tok.HasMoreTokens() )
|
for( auto chIt = text.ubegin(); chIt != text.uend(); chIt++ )
|
||||||
{
|
{
|
||||||
wxString term = tok.GetNextToken();
|
switch( *chIt )
|
||||||
|
|
||||||
// Consume bus definitions as single terms
|
|
||||||
if( tok.GetLastDelimiter() == L'{' )
|
|
||||||
{
|
{
|
||||||
term << tok.GetLastDelimiter();
|
case '{':
|
||||||
|
brace_count++;
|
||||||
|
last_space = false;
|
||||||
|
break;
|
||||||
|
|
||||||
while( tok.HasMoreTokens() )
|
case '[':
|
||||||
|
bracket_count++;
|
||||||
|
last_space = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '}':
|
||||||
|
brace_count = std::max( 0, brace_count - 1 );
|
||||||
|
last_space = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ']':
|
||||||
|
bracket_count = std::max( 0, bracket_count - 1 );
|
||||||
|
last_space = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ' ':
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
case '\t':
|
||||||
|
if( !token.empty() && bracket_count == 0 && brace_count == 0 )
|
||||||
{
|
{
|
||||||
term << tok.GetNextToken() << tok.GetLastDelimiter();
|
std::unique_ptr<SCH_TEXT> nextitem( static_cast<SCH_TEXT*>( textItem->Clone() ) );
|
||||||
|
nextitem->SetText( token.wx_str() );
|
||||||
if( tok.GetLastDelimiter() == L'}' )
|
s_queuedTexts.push_back( std::move( nextitem ) );
|
||||||
break;
|
token.clear();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if( tok.GetLastDelimiter() == L'[' )
|
|
||||||
{
|
|
||||||
term << tok.GetLastDelimiter();
|
|
||||||
|
|
||||||
while( tok.HasMoreTokens() )
|
// Skip leading whitespace
|
||||||
{
|
if( token.empty() || last_space )
|
||||||
term << tok.GetNextToken() << tok.GetLastDelimiter();
|
continue;
|
||||||
|
|
||||||
if( tok.GetLastDelimiter() == L']' )
|
last_space = true;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
default:
|
||||||
|
last_space = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token += *chIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !token.empty() )
|
||||||
|
{
|
||||||
std::unique_ptr<SCH_TEXT> nextitem( static_cast<SCH_TEXT*>( textItem->Clone() ) );
|
std::unique_ptr<SCH_TEXT> nextitem( static_cast<SCH_TEXT*>( textItem->Clone() ) );
|
||||||
nextitem->SetText( term );
|
nextitem->SetText( token.wx_str() );
|
||||||
s_queuedTexts.push_back( std::move( nextitem ) );
|
s_queuedTexts.push_back( std::move( nextitem ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue