UTF8 FPID::Format( const UTF8& aLogicalLib, const UTF8& aFootprintName, const UTF8& aRevision ) throw( PARSE_ERROR ) { UTF8 ret; int offset; if( aLogicalLib.size() ) { offset = okLogical( aLogicalLib ); if( offset != -1 ) { THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ), wxString::FromUTF8( aLogicalLib.c_str() ), aLogicalLib.c_str(), 0, offset ); } ret += aLogicalLib; ret += ':'; } 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; }
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; }
UTF8 LIB_TABLE::FormatOptions( const PROPERTIES* aProperties ) { UTF8 ret; if( aProperties ) { for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it ) { const std::string& name = it->first; const UTF8& value = it->second; if( ret.size() ) ret += OPT_SEP; ret += name; // the separation between name and value is '=' if( value.size() ) { ret += '='; for( std::string::const_iterator si = value.begin(); si != value.end(); ++si ) { // escape any separator in the value. if( *si == OPT_SEP ) ret += '\\'; ret += *si; } } } } return ret; }