Remove whitespace from page numbers on load and use # if page is empty

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8350
This commit is contained in:
Roberto Fernandez Bautista 2021-05-21 18:50:46 +01:00
parent 6b764f893a
commit be436ec977
1 changed files with 17 additions and 5 deletions

View File

@ -1886,22 +1886,34 @@ void SCH_SEXPR_PARSER::parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN
token = NextTok(); token = NextTok();
std::vector<wxString> whitespaces = { wxT( "\r" ), wxT( "\n" ), wxT( "\t" ),
wxT( " " ) };
size_t numReplacements = 0;
switch( token ) switch( token )
{ {
case T_page: case T_page:
NeedSYMBOL(); NeedSYMBOL();
instance.m_PageNumber = FromUTF8(); instance.m_PageNumber = FromUTF8();
// Whitespaces are not permitted
for( wxString ch : whitespaces )
numReplacements += instance.m_PageNumber.Replace( ch, wxEmptyString );
// Empty page numbers are not permitted // Empty page numbers are not permitted
if( instance.m_PageNumber.IsEmpty() ) if( instance.m_PageNumber.IsEmpty() )
{ {
// Use space character instead // Use hash character instead
instance.m_PageNumber = wxT( " " ); instance.m_PageNumber = wxT( "#" );
numReplacements++;
// Set the file as modified so the user can be warned.
aScreen->SetModify();
} }
// Set the file as modified so the user can be warned.
if( numReplacements > 0 )
aScreen->SetModify();
NeedRIGHT(); NeedRIGHT();
break; break;