From f48a248db4416500041e284f43878acbf1a77969 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Tue, 31 Oct 2023 02:17:09 +0300 Subject: [PATCH] EasyEDA Std: Handle HTML escape characters in text. --- common/string_utils.cpp | 32 ++++++++++++++++++- .../easyeda/sch_easyeda_parser.cpp | 6 ++++ pcbnew/plugins/easyeda/pcb_easyeda_parser.cpp | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/common/string_utils.cpp b/common/string_utils.cpp index 3ea2dad4cc..c2206d617e 100644 --- a/common/string_utils.cpp +++ b/common/string_utils.cpp @@ -545,7 +545,37 @@ wxString UnescapeHTML( const wxString& aString ) converted.Replace( wxS( "<" ), wxS( "<" ) ); converted.Replace( wxS( ">" ), wxS( ">" ) ); - return converted; + // Yes, &#123; is going to give unexpected results. + + wxString result; + + wxRegEx regex( "&#(\\d*);" ); + + size_t start = 0; + size_t len = 0; + + wxString str = aString; + + while( regex.Matches( str ) ) + { + std::vector matches; + regex.GetMatch( &start, &len ); + + result << str.Left( start ); + + unsigned long codeVal = 0; + wxString code = regex.GetMatch( str, 1 ); + code.ToCULong( &codeVal ); + + if( codeVal != 0 ) + result << wxUniChar( codeVal ); + + str = str.Mid( start + len ); + } + + result << str; + + return result; } diff --git a/eeschema/sch_plugins/easyeda/sch_easyeda_parser.cpp b/eeschema/sch_plugins/easyeda/sch_easyeda_parser.cpp index 363587a45e..1fc15a74f4 100644 --- a/eeschema/sch_plugins/easyeda/sch_easyeda_parser.cpp +++ b/eeschema/sch_plugins/easyeda/sch_easyeda_parser.cpp @@ -810,7 +810,10 @@ void SCH_EASYEDA_PARSER::ParseSymbolShapes( LIB_SYMBOL* aSymbol wxString fontSize = arr[7]; wxString baselineAlign = arr[10]; wxString textStr = arr[12]; + textStr.Replace( wxS( "\\n" ), wxS( "\n" ) ); + textStr = UnescapeHTML( textStr ); + wxString halignStr = arr[14]; // Empty, start, middle, end, inherit bool added = false; @@ -1311,7 +1314,10 @@ void SCH_EASYEDA_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aRoot wxString fontSize = arr[7]; wxString baselineAlign = arr[10]; wxString textStr = arr[12]; + textStr.Replace( wxS( "\\n" ), wxS( "\n" ) ); + textStr = UnescapeHTML( textStr ); + wxString halignStr = arr[14]; // Empty, start, middle, end, inherit std::unique_ptr textItem = diff --git a/pcbnew/plugins/easyeda/pcb_easyeda_parser.cpp b/pcbnew/plugins/easyeda/pcb_easyeda_parser.cpp index 77885366b8..6842a45fe7 100644 --- a/pcbnew/plugins/easyeda/pcb_easyeda_parser.cpp +++ b/pcbnew/plugins/easyeda/pcb_easyeda_parser.cpp @@ -778,7 +778,7 @@ void PCB_EASYEDA_PARSER::ParseToBoardItemContainer( double height = ConvertSize( arr[9] ) * 0.8; text->SetTextSize( VECTOR2I( height, height ) ); - text->SetText( arr[10] ); + text->SetText( UnescapeHTML( arr[10] ) ); //arr[11] // Geometry data