altium: allow text in special strings

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/6256#note_529783269
This commit is contained in:
Thomas Pointhuber 2021-03-20 19:25:15 +01:00
parent 9c19c2306e
commit cd26db24f9
2 changed files with 58 additions and 12 deletions

View File

@ -54,10 +54,27 @@ wxString AltiumSpecialStringsToKiCadVariables( const wxString&
size_t start = 1; size_t start = 1;
size_t delemiter = 0; size_t delemiter = 0;
size_t escaping_start = 0;
do do
{ {
delemiter = aString.find( "+", start ); delemiter = aString.find( "+", start );
escaping_start = aString.find( "'", start );
if( escaping_start < delemiter )
{
size_t text_start = escaping_start + 1;
size_t escaping_end = aString.find( "'", text_start );
if( escaping_end == wxString::npos )
{
escaping_end = aString.size();
}
result += aString.substr( text_start, escaping_end - text_start );
start = escaping_end + 1;
}
else
{
wxString specialString = aString.substr( start, delemiter - start ).Trim( true ); wxString specialString = aString.substr( start, delemiter - start ).Trim( true );
if( !specialString.IsEmpty() ) if( !specialString.IsEmpty() )
@ -72,8 +89,8 @@ wxString AltiumSpecialStringsToKiCadVariables( const wxString&
result += variableOverride->second; result += variableOverride->second;
} }
} }
start = delemiter + 1; start = delemiter + 1;
}
} while( delemiter != wxString::npos ); } while( delemiter != wxString::npos );
return result; return result;

View File

@ -65,8 +65,17 @@ static const std::vector<SPECIAL_STRINGS_TO_KICAD> special_string_to_kicad_prope
{ "A\tB", "A\tB", {} }, { "A\tB", "A\tB", {} },
{ "This is a long text with spaces", "This is a long text with spaces", {} }, { "This is a long text with spaces", "This is a long text with spaces", {} },
// Text format (underscore,...), TODO: add // Text format (underscore,...), TODO: add
// TODO: variable replacement is in fact case insensitive
// Escaping, TODO: add // Escaping, TODO: add
{ "+", "+", {} },
{ "'", "'", {} },
{ "'A'", "'A'", {} },
{ "A+B", "A+B", {} },
{ "A=B", "A=B", {} }, { "A=B", "A=B", {} },
{ "$", "$", {} },
{ "{", "{", {} },
{ "}", "}", {} },
{ "${A}", "${A}", {} }, // TODO: correct substitution
// Simple special strings // Simple special strings
{ "=A", "${A}", {} }, { "=A", "${A}", {} },
{ "=A", "C", { { "A", "C" } } }, { "=A", "C", { { "A", "C" } } },
@ -77,6 +86,22 @@ static const std::vector<SPECIAL_STRINGS_TO_KICAD> special_string_to_kicad_prope
{ "=A+B", "${A}${B}", {} }, { "=A+B", "${A}${B}", {} },
{ "=A+B", "C${B}", { { "A", "C" } } }, { "=A+B", "C${B}", { { "A", "C" } } },
{ "=A+B", "CD", { { "A", "C" }, { "B", "D" } } }, { "=A+B", "CD", { { "A", "C" }, { "B", "D" } } },
// Special strings with text
{ "='A'", "A", {} },
{ "='This is a long text with spaces'", "This is a long text with spaces", {} },
{ "='='", "=", {} },
{ "='+'", "+", {} },
{ "='$'", "$", {} },
{ "='{'", "{", {} },
{ "='}'", "}", {} },
{ "='${A}'", "${A}", {} }, // TODO: correct substitution
{ "='A'+'B'", "AB", {} },
{ "='A'+' '", "A ", {} },
{ "=' '+'B'", " B", {} },
{ "='A'+B", "A${B}", {} },
{ "=A+'B'", "${A}B", {} },
{ "=A+' '+B", "${A} ${B}", {} },
{ "='A'+B+'C'+D", "A${B}C${D}", {} },
// Some special cases we do not know yet how to handle correctly. But we should not crash ;) // Some special cases we do not know yet how to handle correctly. But we should not crash ;)
{ "=+", "", {} }, { "=+", "", {} },
{ "=++", "", {} }, { "=++", "", {} },
@ -90,6 +115,10 @@ static const std::vector<SPECIAL_STRINGS_TO_KICAD> special_string_to_kicad_prope
{ "= ", "", {} }, { "= ", "", {} },
{ "= A", "${ A}", {} }, { "= A", "${ A}", {} },
{ "=A ", "${A}", {} }, { "=A ", "${A}", {} },
{ "='A'B", "A", {} },
{ "=A'B'", "B", {} },
{ "=A'B", "B", {} },
{ "=A+ 'B'", "${A}B", {} },
}; };