From be436ec9774a969fd60fb4879d2a7bede47e0260 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Fri, 21 May 2021 18:50:46 +0100 Subject: [PATCH] Remove whitespace from page numbers on load and use # if page is empty Fixes https://gitlab.com/kicad/code/kicad/-/issues/8350 --- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 7565f2e53e..ea6e01c6f2 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -1886,22 +1886,34 @@ void SCH_SEXPR_PARSER::parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN token = NextTok(); + std::vector whitespaces = { wxT( "\r" ), wxT( "\n" ), wxT( "\t" ), + wxT( " " ) }; + + size_t numReplacements = 0; + switch( token ) { case T_page: NeedSYMBOL(); 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 if( instance.m_PageNumber.IsEmpty() ) { - // Use space character instead - instance.m_PageNumber = wxT( " " ); - - // Set the file as modified so the user can be warned. - aScreen->SetModify(); + // Use hash character instead + instance.m_PageNumber = wxT( "#" ); + numReplacements++; } + // Set the file as modified so the user can be warned. + if( numReplacements > 0 ) + aScreen->SetModify(); + NeedRIGHT(); break;