From 4ac2aa675a353057f2ab532b558b844d17f0917f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 23 Aug 2021 17:59:36 +0200 Subject: [PATCH] lib symbols: make fp filter tolerant to spaces in names. For historical reasons they are stored in a string using spaces as separators. So each fp filter is now escaped to remove spaces (replaced by {space}) Fixes #9009 https://gitlab.com/kicad/code/kicad/issues/9009 --- common/string_utils.cpp | 9 +++++++++ eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp | 5 ++++- eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp | 7 +++++-- include/string_utils.h | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/common/string_utils.cpp b/common/string_utils.cpp index 016b6ed8df..646f9b4734 100644 --- a/common/string_utils.cpp +++ b/common/string_utils.cpp @@ -211,6 +211,15 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext ) else converted += c; } + else if( aContext == CTX_NO_SPACE ) + { + if( c == ' ' ) + converted += "{space}"; + else if( c == '{' ) + converted += "{brace}"; + else + converted += c; + } else converted += c; } diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 569d768d9f..4dd6f7a68c 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -851,7 +851,10 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr& aSymbol wxStringTokenizer tokenizer( value ); while( tokenizer.HasMoreTokens() ) - filters.Add( tokenizer.GetNextToken() ); + { + wxString curr_token = UnescapeString( tokenizer.GetNextToken() ); + filters.Add( curr_token ); + } aSymbol->SetFPFilters( filters ); return nullptr; diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index fcf9dd6ca3..2a8d9ef3ec 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -1750,10 +1750,13 @@ void SCH_SEXPR_PLUGIN_CACHE::saveDcmInfoAsFields( LIB_SYMBOL* aSymbol, OUTPUTFOR for( auto filter : fpFilters ) { + // Spaces are not handled in fp filter names so escape spaces if any + wxString curr_filter = EscapeString( filter, ESCAPE_CONTEXT::CTX_NO_SPACE ); + if( tmp.IsEmpty() ) - tmp = filter; + tmp = curr_filter; else - tmp += " " + filter; + tmp += " " + curr_filter; } LIB_FIELD description( -1, wxString( "ki_fp_filters" ) ); diff --git a/include/string_utils.h b/include/string_utils.h index 3f55c18291..dfdc20c831 100644 --- a/include/string_utils.h +++ b/include/string_utils.h @@ -55,7 +55,8 @@ enum ESCAPE_CONTEXT CTX_LIBID, CTX_QUOTED_STR, CTX_LINE, - CTX_FILENAME + CTX_FILENAME, + CTX_NO_SPACE // to replace spaces in names that do not accept spaces }; /**