Be more explicit about string/character conversions.

This *may* fix the bug where a layer name isn't displayed correctly
in the error dialog.  But probably not.
This commit is contained in:
Jeff Young 2020-07-28 20:31:48 +01:00
parent 9f6098321f
commit 0fecb5f277
5 changed files with 19 additions and 22 deletions

View File

@ -309,13 +309,12 @@ public:
VALUE* Run( CONTEXT* ctx );
std::string Dump() const;
virtual VAR_REF* createVarRef( COMPILER* aCompiler, const std::string& var,
const std::string& field )
virtual VAR_REF* createVarRef( COMPILER* aCompiler, const char* var, const char* field )
{
return nullptr;
};
virtual FUNC_PTR createFuncCall( COMPILER* aCompiler, const std::string& name )
virtual FUNC_PTR createFuncCall( COMPILER* aCompiler, const char* name )
{
return nullptr;
};

View File

@ -140,7 +140,7 @@ bool DRC_RULE_CONDITION::Compile()
PCB_EXPR_CONTEXT preflightContext;
bool ok = compiler.Compile( (const char*) m_Expression.c_str(), m_ucode, &preflightContext );
bool ok = compiler.Compile( m_Expression.ToUTF8().data(), m_ucode, &preflightContext );
if( ok )
return true;

View File

@ -139,28 +139,28 @@ LIBEVAL::VALUE PCB_EXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
LIBEVAL::UCODE::FUNC_PTR PCB_EXPR_UCODE::createFuncCall( LIBEVAL::COMPILER* aCompiler,
const std::string& name )
const char* aName )
{
PCB_EXPR_BUILTIN_FUNCTIONS& registry = PCB_EXPR_BUILTIN_FUNCTIONS::Instance();
auto f = registry.Get( boost::to_lower_copy( name ) );
std::string lowerName( aName );
boost::to_lower( lowerName );
return f;
return registry.Get( lowerName );
}
LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler,
const std::string& aVar,
const std::string& aField )
LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler, const char* aVar,
const char* aField )
{
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
PCB_EXPR_VAR_REF* vref = nullptr;
if( aVar == "A" )
if( *aVar == 'A' )
{
vref = new PCB_EXPR_VAR_REF( 0 );
}
else if( aVar == "B" )
else if( *aVar == 'B' )
{
vref = new PCB_EXPR_VAR_REF( 1 );
}
@ -170,11 +170,11 @@ LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler,
return vref;
}
if( aField.empty() ) // return reference to base object
if( strlen( aField ) == 0 ) // return reference to base object
return vref;
std::string field( aField );
std::replace( field.begin(), field.end(), '_', ' ');
wxString field = wxString::FromUTF8( aField );
field.Replace( "_", " " );
for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
{
@ -267,7 +267,7 @@ bool PCB_EXPR_EVALUATOR::Evaluate( const wxString& aExpr )
PCB_EXPR_UCODE ucode;
LIBEVAL::CONTEXT preflightContext;
if( !m_compiler.Compile( (const char*) aExpr.c_str(), &ucode, &preflightContext ) )
if( !m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext ) )
{
m_errorStatus = m_compiler.GetErrorStatus();
return false;

View File

@ -40,12 +40,10 @@ class PCB_EXPR_VAR_REF;
class PCB_EXPR_UCODE final : public LIBEVAL::UCODE
{
public:
virtual LIBEVAL::VAR_REF* createVarRef( LIBEVAL::COMPILER *aCompiler,
const std::string& aVar,
const std::string& aField ) override;
virtual LIBEVAL::VAR_REF* createVarRef( LIBEVAL::COMPILER *aCompiler, const char* aVar,
const char* aField ) override;
virtual FUNC_PTR createFuncCall( LIBEVAL::COMPILER* aCompiler,
const std::string& name ) override;
virtual FUNC_PTR createFuncCall( LIBEVAL::COMPILER* aCompiler, const char* aName ) override;
};

View File

@ -70,7 +70,7 @@ bool test::DRC_RULE_CONDITION::Compile()
if (!m_ucode)
m_ucode = new PCB_EXPR_UCODE;
bool ok = compiler.Compile( (const char*) m_Expression.c_str(), m_ucode );
bool ok = compiler.Compile( m_Expression.ToUTF8().data(), m_ucode );
if( ok )
return true;