int FPID::Parse( const UTF8& aId ) { clear(); const char* buffer = aId.c_str(); const char* rev = EndsWithRev( buffer, buffer+aId.length(), '/' ); size_t revNdx; size_t partNdx; int offset; //=====<revision>========================================= // in a FPID like discret:R3/rev4 if( rev ) { revNdx = rev - buffer; // no need to check revision, EndsWithRev did that. revision = aId.substr( revNdx ); --revNdx; // back up to omit the '/' which precedes the rev } else { revNdx = aId.size(); } //=====<nickname>========================================== if( ( partNdx = aId.find( ':' ) ) != aId.npos ) { offset = SetLibNickname( aId.substr( 0, partNdx ) ); if( offset > -1 ) { return offset; } ++partNdx; // skip ':' } else { partNdx = 0; } //=====<footprint name>==================================== if( partNdx >= revNdx ) return partNdx; // Error: no footprint name. // Be sure the footprint name is valid. // Some chars can be found in board file (in old board files // or converted files from an other EDA tool std::string fpname = aId.substr( partNdx, revNdx-partNdx ); ReplaceIllegalFileNameChars( &fpname, '_' ); SetFootprintName( UTF8( fpname ) ); return -1; }
int FPID::Parse( const UTF8& aId ) { clear(); size_t cnt = aId.length() + 1; char tmp[cnt]; // C string for speed std::strcpy( tmp, aId.c_str() ); const char* rev = EndsWithRev( tmp, tmp+aId.length(), '/' ); size_t revNdx; size_t partNdx; int offset; //=====<revision>========================================= if( rev ) { revNdx = rev - aId.c_str(); // no need to check revision, EndsWithRev did that. revision = aId.substr( revNdx ); --revNdx; // back up to omit the '/' which precedes the rev } else { revNdx = aId.size(); } //=====<nickname>========================================== if( ( partNdx = aId.find( ':' ) ) != aId.npos ) { offset = SetLibNickname( aId.substr( 0, partNdx ) ); if( offset > -1 ) { return offset; } ++partNdx; // skip ':' } else { partNdx = 0; } //=====<footprint name>==================================== if( partNdx >= revNdx ) return partNdx; SetFootprintName( aId.substr( partNdx, revNdx ) ); return -1; }
static int okRevision( const std::string& aField ) { char rev[32]; // C string for speed if( aField.size() >= 4 ) { strcpy( rev, "x/" ); 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. }
int FP_LIB_ID::Parse( const std::string& aId ) { clear(); const char* rev = EndsWithRev( aId ); size_t revNdx; size_t partNdx; int offset; //=====<revision>========================================= if( rev ) { revNdx = rev - aId.c_str(); // no need to check revision, EndsWithRev did that. revision = aId.substr( revNdx ); --revNdx; // back up to omit the '/' which precedes the rev } else { revNdx = aId.size(); } //=====<logical>========================================== if( ( partNdx = aId.find( ':' ) ) != aId.npos ) { offset = SetLogicalLib( aId.substr( 0, partNdx ) ); if( offset > -1 ) { return offset; } ++partNdx; // skip ':' } else { partNdx = 0; } return -1; }