예제 #1
0
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;
}
예제 #2
0
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;
}
예제 #3
0
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;
}
예제 #4
0
int main()
{
    std::string str = "input";

    UTF8        u0 = L"wide string";
    UTF8        u1 = "initial";
    wxString    wx = wxT( "input2" );

    printf( "u0:'%s'\n", u0.c_str() );
    printf( "u1:'%s'\n", u1.c_str() );

    u1 = str;

    wxString    wx2 = u1;

    // force a std::string into a UTF8, then into a wxString, then copy construct:
    wxString    wx3 = (UTF8&) u1;

    UTF8        u2 = wx2;

    u2 += 'X';

    printf( "u2:'%s'\n", u2.c_str() );

    // key accomplishments here:
    // 1) passing a UTF8 to a function which normally takes a wxString.
    // 2) return a wxString back into a UTF8.
    UTF8    result = wxFunctionTaking_wxString( u2 );

    printf( "result:'%s'\n", result.c_str() );

    // test the unicode iterator:
    for( UTF8::uni_iter it = u2.ubegin();  it < u2.uend();  )
    {
        // test post-increment:
        printf( " _%02x_", *it++ );
    }

    printf( "\n" );

    UTF8::uni_iter it = u2.ubegin();

    UTF8::uni_iter it2 = it++;

    printf( "post_inc:'%c' should be 'i'\n", *it2 );

    it2 = ++it;

    printf( "pre_inc:'%c' should be 'p'\n", *it2 );

    printf( "u[1]:'%c' should be 'n'\n", u2[1] );

    return 0;
}
예제 #5
0
FPID::FPID( const wxString& aId ) throw( PARSE_ERROR )
{
    UTF8 id = aId;

    int offset = Parse( id );

    if( offset != -1 )
    {
        THROW_PARSE_ERROR( _( "Illegal character found in FPID string" ),
                           aId,
                           id.c_str(),
                           0,
                           offset );
    }
}
예제 #6
0
void callee( const wxString& aString )
{
    UTF8 arg = aString;

    printf( "%s: '%s'\n", __func__, arg.c_str() );
}