Uniformly quote strings which may have user content.
Fixes: lp:1655193 * https://bugs.launchpad.net/kicad/+bug/1655193
This commit is contained in:
parent
684bb62fd8
commit
4a9f82109a
|
@ -432,50 +432,40 @@ int OUTPUTFORMATTER::Print( int nestLevel, const char* fmt, ... )
|
|||
|
||||
std::string OUTPUTFORMATTER::Quotes( const std::string& aWrapee )
|
||||
{
|
||||
static const char quoteThese[] = "\t ()\n\r";
|
||||
std::string ret;
|
||||
|
||||
if( !aWrapee.size() || // quote null string as ""
|
||||
aWrapee[0]=='#' || // quote a potential s-expression comment, so it is not a comment
|
||||
aWrapee[0]=='"' || // NextTok() will travel through DSN_STRING path anyway, then must apply escapes
|
||||
aWrapee.find_first_of( quoteThese ) != std::string::npos )
|
||||
ret.reserve( aWrapee.size()*2 + 2 );
|
||||
|
||||
ret += '"';
|
||||
|
||||
for( std::string::const_iterator it = aWrapee.begin(); it!=aWrapee.end(); ++it )
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
ret.reserve( aWrapee.size()*2 + 2 );
|
||||
|
||||
ret += '"';
|
||||
|
||||
for( std::string::const_iterator it = aWrapee.begin(); it!=aWrapee.end(); ++it )
|
||||
switch( *it )
|
||||
{
|
||||
switch( *it )
|
||||
{
|
||||
case '\n':
|
||||
ret += '\\';
|
||||
ret += 'n';
|
||||
break;
|
||||
case '\r':
|
||||
ret += '\\';
|
||||
ret += 'r';
|
||||
break;
|
||||
case '\\':
|
||||
ret += '\\';
|
||||
ret += '\\';
|
||||
break;
|
||||
case '"':
|
||||
ret += '\\';
|
||||
ret += '"';
|
||||
break;
|
||||
default:
|
||||
ret += *it;
|
||||
}
|
||||
case '\n':
|
||||
ret += '\\';
|
||||
ret += 'n';
|
||||
break;
|
||||
case '\r':
|
||||
ret += '\\';
|
||||
ret += 'r';
|
||||
break;
|
||||
case '\\':
|
||||
ret += '\\';
|
||||
ret += '\\';
|
||||
break;
|
||||
case '"':
|
||||
ret += '\\';
|
||||
ret += '"';
|
||||
break;
|
||||
default:
|
||||
ret += *it;
|
||||
}
|
||||
|
||||
ret += '"';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return aWrapee;
|
||||
ret += '"';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1515,7 +1515,7 @@ void PCB_IO::format( TEXTE_PCB* aText, int aNestLevel ) const
|
|||
|
||||
void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const
|
||||
{
|
||||
wxString type;
|
||||
std::string type;
|
||||
|
||||
switch( aText->GetType() )
|
||||
{
|
||||
|
@ -1524,8 +1524,7 @@ void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const
|
|||
case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
|
||||
}
|
||||
|
||||
m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
|
||||
m_out->Quotew( type ).c_str(),
|
||||
m_out->Print( aNestLevel, "(fp_text %s %s (at %s", type.c_str(),
|
||||
m_out->Quotew( aText->GetText() ).c_str(),
|
||||
FormatInternalUnits( aText->GetPos0() ).c_str() );
|
||||
|
||||
|
|
Loading…
Reference in New Issue