diff --git a/common/lib_id.cpp b/common/lib_id.cpp index 4cb33efdc3..f73999242d 100644 --- a/common/lib_id.cpp +++ b/common/lib_id.cpp @@ -29,58 +29,6 @@ #include // TO_UTF8() #include -#include - - -static inline bool isDigit( char c ) -{ - return c >= '0' && c <= '9'; -} - - -const char* EndsWithRev( const char* start, const char* tail, char separator ) -{ - bool sawDigit = false; - - while( tail > start && isDigit( *--tail ) ) - { - sawDigit = true; - } - - // if sawDigit, tail points to the 'v' here. - - if( sawDigit && tail-3 >= start ) - { - tail -= 3; - - if( tail[0]==separator && tail[1]=='r' && tail[2]=='e' && tail[3]=='v' ) - { - return tail+1; // omit separator, return "revN[N..]" - } - } - - return nullptr; -} - - -#if 0 // Not used -int RevCmp( const char* s1, const char* s2 ) -{ - int r = strncmp( s1, s2, 3 ); - - if( r || strlen(s1)<4 || strlen(s2)<4 ) - { - return r; - } - - int rnum1 = atoi( s1+3 ); - int rnum2 = atoi( s2+3 ); - - return -(rnum1 - rnum2); // swap the sign, higher revs first -} -#endif - -//----------------------------------------- static inline int okLogical( const UTF8& aField ) @@ -91,31 +39,10 @@ static inline int okLogical( const UTF8& aField ) } -static int okRevision( const UTF8& aField ) -{ - char rev[32]; // C string for speed - - if( aField.size() >= 4 ) - { - strncpy( rev, "x/", sizeof( rev ) ); - strncat( rev, aField.c_str(), sizeof(rev)-strlen(rev)-1 ); - - if( EndsWithRev( rev, rev + strlen(rev), '/' ) == rev+2 ) - return -1; // success - } - - return 0; // first character position "is in error", is best we can do. -} - - -//----------------------------------------- - - void LIB_ID::clear() { m_libraryName.clear(); m_itemName.clear(); - m_revision.clear(); } @@ -123,28 +50,10 @@ int LIB_ID::Parse( const UTF8& aId, bool aFix ) { clear(); - const char* buffer = aId.c_str(); - const char* rev = EndsWithRev( buffer, buffer+aId.length(), '/' ); - size_t revNdx; - size_t partNdx; - int offset = -1; + size_t partNdx; + int offset = -1; - //========================================== - // in a LIB_ID like discret:R3/rev4 - if( rev ) - { - revNdx = rev - buffer; - - // no need to check revision, EndsWithRev did that. - m_revision = aId.substr( revNdx ); - --revNdx; // back up to omit the '/' which precedes the rev - } - else - { - revNdx = aId.size(); - } - - //============================================== + //================================== if( ( partNdx = aId.find( ':' ) ) != aId.npos ) { offset = SetLibNickname( aId.substr( 0, partNdx ) ); @@ -160,10 +69,7 @@ int LIB_ID::Parse( const UTF8& aId, bool aFix ) } //========================================= - if( partNdx >= revNdx ) - return partNdx; // Error: no library item name. - - UTF8 fpname = aId.substr( partNdx, revNdx-partNdx ); + UTF8 fpname = aId.substr( partNdx ); // Be sure the item name is valid. // Some chars can be found in legacy files converted files from other EDA tools. @@ -181,11 +87,9 @@ int LIB_ID::Parse( const UTF8& aId, bool aFix ) } -LIB_ID::LIB_ID( const wxString& aLibraryName, const wxString& aItemName, - const wxString& aRevision ) : +LIB_ID::LIB_ID( const wxString& aLibraryName, const wxString& aItemName ) : m_libraryName( aLibraryName ), - m_itemName( aItemName ), - m_revision( aRevision ) + m_itemName( aItemName ) { } @@ -201,35 +105,14 @@ int LIB_ID::SetLibNickname( const UTF8& aLogical ) } -int LIB_ID::SetLibItemName( const UTF8& aLibItemName, bool aTestForRev ) +int LIB_ID::SetLibItemName( const UTF8& aLibItemName ) { - int separation = int( aLibItemName.find_first_of( "/" ) ); - - if( aTestForRev && separation != -1 ) - { - m_itemName = aLibItemName.substr( 0, separation-1 ); - return separation; - } - else - { - m_itemName = aLibItemName; - } + m_itemName = aLibItemName; return -1; } -int LIB_ID::SetRevision( const UTF8& aRevision ) -{ - int offset = okRevision( aRevision ); - - if( offset == -1 ) - m_revision = aRevision; - - return offset; -} - - UTF8 LIB_ID::Format() const { UTF8 ret; @@ -242,31 +125,11 @@ UTF8 LIB_ID::Format() const ret += m_itemName; - if( m_revision.size() ) - { - ret += '/'; - ret += m_revision; - } - return ret; } -UTF8 LIB_ID::GetLibItemNameAndRev() const -{ - UTF8 ret = m_itemName; - - if( m_revision.size() ) - { - ret += '/'; - ret += m_revision; - } - - return ret; -} - - -UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName, const UTF8& aRevision ) +UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName ) { UTF8 ret; int offset; @@ -278,7 +141,8 @@ UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName, const U if( offset != -1 ) { THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ), - wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(), 0, offset ); + wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(), + 0, offset ); } ret += aLibraryName; @@ -287,23 +151,6 @@ UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName, const U ret += aLibItemName; // TODO: Add validity test. - if( aRevision.size() ) - { - offset = okRevision( aRevision ); - - if( offset != -1 ) - { - THROW_PARSE_ERROR( _( "Illegal character found in revision" ), - wxString::FromUTF8( aRevision.c_str() ), - aRevision.c_str(), - 0, - offset ); - } - - ret += '/'; - ret += aRevision; - } - return ret; } @@ -319,12 +166,7 @@ int LIB_ID::compare( const LIB_ID& aLibId ) const if( retv != 0 ) return retv; - retv = m_itemName.compare( aLibId.m_itemName ); - - if( retv != 0 ) - return retv; - - return m_revision.compare( aLibId.m_revision ); + return m_itemName.compare( aLibId.m_itemName ); } @@ -374,12 +216,12 @@ bool LIB_ID::isLegalChar( unsigned aUniChar ) switch( aUniChar ) { case ':': - case '/': case '\t': case '\n': case '\r': return false; + case '/': case '\\': case '<': case '>': @@ -428,33 +270,3 @@ bool LIB_ID::isLegalLibraryNameChar( unsigned aUniChar ) } } - -#if 0 - -// @todo Move this test into the unit test framework. - -void LIB_ID::Test() -{ - static const char* lpids[] = { - "smt:R_0805/rev0", - "mysmt:R_0805/rev2", - "device:AXIAL-0500", - }; - - for( unsigned i=0; iGetLibNickname() ); - m_LibId.SetLibItemName( aItem->GetName () ); + m_LibId.SetLibItemName( aItem->GetName() ); m_Name = aItem->GetName(); m_Desc = aItem->GetDescription(); diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index 999fc916df..3e306679e7 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -314,7 +314,7 @@ wxString LIB_SYMBOL::GetUnitReference( int aUnit ) void LIB_SYMBOL::SetName( const wxString& aName ) { m_name = aName; - m_libId.SetLibItemName( aName, false ); + m_libId.SetLibItemName( aName ); GetValueField().SetText( aName ); } diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index 31d556f84f..eca25b866c 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -205,7 +205,7 @@ bool RESCUE_CASE_CANDIDATE::PerformAction( RESCUER* aRescuer ) LIB_ID libId; - libId.SetLibItemName( m_new_name, false ); + libId.SetLibItemName( m_new_name ); eachSymbol->SetLibId( libId ); eachSymbol->ClearFlags(); aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name ); @@ -329,7 +329,7 @@ bool RESCUE_CACHE_CANDIDATE::PerformAction( RESCUER* aRescuer ) LIB_ID libId; - libId.SetLibItemName( m_new_name, false ); + libId.SetLibItemName( m_new_name ); eachSymbol->SetLibId( libId ); eachSymbol->ClearFlags(); aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name ); @@ -550,7 +550,7 @@ void RESCUER::UndoRescues() { LIB_ID libId; - libId.SetLibItemName( each_logitem.old_name, false ); + libId.SetLibItemName( each_logitem.old_name ); each_logitem.symbol->SetLibId( libId ); each_logitem.symbol->ClearFlags(); } diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index d226376a7e..b9ddd6276a 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -1575,7 +1575,7 @@ SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader ) if( m_version > 3 ) libId.Parse( libName, true ); else - libId.SetLibItemName( libName, false ); + libId.SetLibItemName( libName ); symbol->SetLibId( libId ); diff --git a/include/lib_id.h b/include/lib_id.h index 09c7a4924b..187cfa0e4d 100644 --- a/include/lib_id.h +++ b/include/lib_id.h @@ -65,10 +65,8 @@ public: * @param aLibraryName is the library name used to look up the library item in the #LIB_TABLE. * @param aItemName is the name of the library item which is not parsed by the standard * LIB_ID::Parse() function. - * @param aRevision is the revision of the library item. */ - LIB_ID( const wxString& aLibraryName, const wxString& aItemName, - const wxString& aRevision = wxEmptyString ); + LIB_ID( const wxString& aLibraryName, const wxString& aItemName ); /** * Parse LIB_ID with the information from @a aId. @@ -122,13 +120,7 @@ public: * into the parameter at which an error was detected, usually because it * contained '/'. */ - int SetLibItemName( const UTF8& aLibItemName, bool aTestForRev = true ); - - int SetRevision( const UTF8& aRevision ); - - const UTF8& GetRevision() const { return m_revision; } - - UTF8 GetLibItemNameAndRev() const; + int SetLibItemName( const UTF8& aLibItemName ); /** * @return the fully formatted text of the LIB_ID in a UTF8 string. @@ -150,8 +142,7 @@ public: * * @throw PARSE_ERROR if any of the pieces are illegal. */ - static UTF8 Format( const UTF8& aLibraryName, const UTF8& aLibItemName, - const UTF8& aRevision = "" ); + static UTF8 Format( const UTF8& aLibraryName, const UTF8& aLibItemName ); /** * Check if this LID_ID is valid. @@ -175,7 +166,7 @@ public: */ bool IsLegacy() const { - return m_libraryName.empty() && !m_itemName.empty() && m_revision.empty(); + return m_libraryName.empty() && !m_itemName.empty(); } /** @@ -188,7 +179,7 @@ public: */ bool empty() const { - return m_libraryName.empty() && m_itemName.empty() && m_revision.empty(); + return m_libraryName.empty() && m_itemName.empty(); } /** @@ -266,7 +257,6 @@ protected: UTF8 m_libraryName; ///< The nickname of the library or empty. UTF8 m_itemName; ///< The name of the entry in the logical library. - UTF8 m_revision; ///< The revision of the entry. }; diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index 3cdf2a4d5f..0bc9729c79 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -609,7 +609,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow() commit.Modify( m_footprint ); LIB_ID fpID = m_footprint->GetFPID(); - fpID.SetLibItemName( m_FootprintNameCtrl->GetValue(), false ); + fpID.SetLibItemName( m_FootprintNameCtrl->GetValue() ); m_footprint->SetFPID( fpID ); m_footprint->SetDescription( m_DocCtrl->GetValue() ); diff --git a/pcbnew/plugins/kicad/kicad_plugin.cpp b/pcbnew/plugins/kicad/kicad_plugin.cpp index a2fec1c3df..3df578c347 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.cpp +++ b/pcbnew/plugins/kicad/kicad_plugin.cpp @@ -1038,7 +1038,7 @@ void PCB_IO::format( const FOOTPRINT* aFootprint, int aNestLevel ) const if( m_ctl & CTL_OMIT_LIBNAME ) m_out->Print( aNestLevel, "(footprint %s", - m_out->Quotes( aFootprint->GetFPID().GetLibItemNameAndRev() ).c_str() ); + m_out->Quotes( aFootprint->GetFPID().GetLibItemName() ).c_str() ); else m_out->Print( aNestLevel, "(footprint %s", m_out->Quotes( aFootprint->GetFPID().Format() ).c_str() );