Add conversion from old `~...~` to new `~{...}` notation

This commit is contained in:
Mikolaj Wielgus 2021-06-11 19:06:13 +02:00 committed by Jeff Young
parent 3d520ebe1e
commit ade38f48bc
6 changed files with 74 additions and 2 deletions

View File

@ -41,6 +41,59 @@
static const char illegalFileNameChars[] = "\\/:\"<>|";
wxString ConvertToNewOverbarNotation( const wxString& aOldStr )
{
wxString newStr;
bool inOverbar = false;
for( wxString::const_iterator chIt = aOldStr.begin(); chIt != aOldStr.end(); ++chIt )
{
if( *chIt == '~' )
{
wxString::const_iterator lookahead = chIt;
if( ++lookahead != aOldStr.end() && *lookahead == '~' )
{
if( ++lookahead != aOldStr.end() && *lookahead == '{' )
{
// This way the subseqent opening curly brace will not start an
// overbar.
newStr << "~~{}";
continue;
}
// Two subsequent tildes mean a tilde.
newStr << "~";
continue;
}
else
{
if( inOverbar )
{
newStr << "}";
inOverbar = false;
}
else
{
newStr << "~{";
inOverbar = true;
}
continue;
}
}
newStr << *chIt;
}
// Explicitly end the overbar even if there was no terminating '~' in the aOldStr.
if( inOverbar )
newStr << "}";
return newStr;
}
bool ConvertSmartQuotesAndDashes( wxString* aString )
{
bool retVal = false;

View File

@ -60,4 +60,5 @@
//#define SEXPR_SCHEMATIC_FILE_VERSION 20210123 // Rename "unconnected" pintype to "no_connect".
//#define SEXPR_SCHEMATIC_FILE_VERSION 20210125 // R/W uuids for pins, labels, wires, etc.
//#define SEXPR_SCHEMATIC_FILE_VERSION 20210126 // Fix bug with writing pin uuids.
#define SEXPR_SCHEMATIC_FILE_VERSION 20210406 // Add schematic level uuids.
//#define SEXPR_SCHEMATIC_FILE_VERSION 20210406 // Add schematic level uuids.
#define SEXPR_SCHEMATIC_FILE_VERSION 20210606 // Change overbar syntax from `~...~` to `~{...}`.

View File

@ -41,6 +41,7 @@
#include <lib_rectangle.h>
#include <lib_text.h>
#include <math/util.h> // KiROUND, Clamp
#include <kicad_string.h>
#include <sch_bitmap.h>
#include <sch_bus_entry.h>
#include <sch_symbol.h>
@ -601,6 +602,11 @@ void SCH_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
wxCHECK_RET( aText && CurTok() == T_effects,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDA_TEXT." ) );
// In version 20210606 the notation for overbars was changed from `~...~` to `~{...}`. We need to convert
// the old syntax to the new one.
if( m_requiredVersion < 20210606 )
aText->SetText( ConvertToNewOverbarNotation( aText->GetText() ) );
T token;
for( token = NextTok(); token != T_RIGHT; token = NextTok() )

View File

@ -38,6 +38,11 @@
#include <wx/filename.h>
/**
* Convert the old `~...~` overbar notation to the new `~{...}` one.
*/
wxString ConvertToNewOverbarNotation( const wxString& aOldStr );
/**
* Convert curly quotes and em/en dashes to straight quotes and dashes.
*

View File

@ -96,7 +96,8 @@ class PCB_TEXT;
//#define SEXPR_BOARD_FILE_VERSION 20210108 // Pad locking moved from footprint to pads
//#define SEXPR_BOARD_FILE_VERSION 20210126 // Store pintype alongside pinfunction (in pads).
//#define SEXPR_BOARD_FILE_VERSION 20210228 // Move global margins back to board file
#define SEXPR_BOARD_FILE_VERSION 20210424 // Correct locked flag syntax (remove parens).
//#define SEXPR_BOARD_FILE_VERSION 20210424 // Correct locked flag syntax (remove parens).
#define SEXPR_BOARD_FILE_VERSION 20210606 // Change overbar syntax from `~...~` to `~{...}`.
#define BOARD_FILE_HOST_VERSION 20200825 ///< Earlier files than this include the host tag

View File

@ -56,6 +56,7 @@
#include <convert_basic_shapes_to_polygon.h> // for RECT_CHAMFER_POSITIONS definition
#include <template_fieldnames.h>
#include <math/util.h> // KiROUND, Clamp
#include <kicad_string.h>
#include <wx/log.h>
using namespace PCB_KEYS_T;
@ -294,6 +295,11 @@ void PCB_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
wxCHECK_RET( CurTok() == T_effects,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDA_TEXT." ) );
// In version 20210606 the notation for overbars was changed from `~...~` to `~{...}`. We need to convert
// the old syntax to the new one.
if( m_requiredVersion < 20210606 )
aText->SetText( ConvertToNewOverbarNotation( aText->GetText() ) );
T token;
// Prior to v5.0 text size was omitted from file format if equal to 60mils