Skip to content
Snippets Groups Projects
Commit 62886853 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

correct save_y08:

- remove empty line from history
- put "" around more special characters
- save empty string as "" [bug found by Kerstin Kämpf]
parent cbb0f22d
No related branches found
No related tags found
No related merge requests found
...@@ -76,7 +76,7 @@ void NFileOut::Save_y08( FILE *file, POlo f ) ...@@ -76,7 +76,7 @@ void NFileOut::Save_y08( FILE *file, POlo f )
{ {
POld fd = P2D( f ); POld fd = P2D( f );
POlc fc = P2C( f ); POlc fc = P2C( f );
string out;
fprintf( file, "Meta:\n" fprintf( file, "Meta:\n"
" format: frida/y08 for yaml1\n" " format: frida/y08 for yaml1\n"
" type: %s\n", " type: %s\n",
...@@ -85,7 +85,6 @@ void NFileOut::Save_y08( FILE *file, POlo f ) ...@@ -85,7 +85,6 @@ void NFileOut::Save_y08( FILE *file, POlo f )
fprintf( file, "History:\n" ); fprintf( file, "History:\n" );
for ( uint i=0; i<f->lDoc.size(); i++ ) for ( uint i=0; i<f->lDoc.size(); i++ )
fprintf( file, "- %s\n", yaml(f->lDoc[i]).c_str() ); fprintf( file, "- %s\n", yaml(f->lDoc[i]).c_str() );
fprintf( file, "- \%s\n", yaml( out ).c_str() );
fprintf( file, "Coord:\n" ); fprintf( file, "Coord:\n" );
fprintf( file, " x:\n name: %s\n unit: %s\n", fprintf( file, " x:\n name: %s\n unit: %s\n",
......
...@@ -75,21 +75,30 @@ string strg( char val ) ...@@ -75,21 +75,30 @@ string strg( char val )
string yaml( const string s ) string yaml( const string s )
// string -> yaml-output-string // string -> yaml-output-string
{ {
if ( s=="" )
return "\"\"";
string out = s; string out = s;
uint i = 0; uint i = 0;
// escape " // escape "
while( i < out.size() ){ while( i < out.size() ){
if( out[i]=='"' && (i==0 || out[i-1]!='\\') ) if( ( out[i]=='"' || out[i]=='\'' ) && (i==0 || out[i-1]!='\\') )
out.insert( i, "\\" ); out.insert( i, "\\" );
++i; ++i;
} }
// if there are special characters, put "" around // if there are special characters, put "" around
if( s.find( '"' )!=string::npos || if( s.find( '"' )!=string::npos ||
s.find( '\'' )!=string::npos ||
s.find( '\\' )!=string::npos ||
s.find( ':' )!=string::npos || s.find( ':' )!=string::npos ||
s.find( '*' )!=string::npos || s.find( '*' )!=string::npos ||
s.find( '&' )!=string::npos || s.find( '&' )!=string::npos ||
s.find( '#' )!=string::npos ||
s.find( '>' )!=string::npos || s.find( '>' )!=string::npos ||
s.find( '<' )!=string::npos s.find( '<' )!=string::npos ||
s.find( '[' )!=string::npos ||
s.find( ']' )!=string::npos ||
s.find( '{' )!=string::npos ||
s.find( '}' )!=string::npos
) )
out = '"' + out + '"'; out = '"' + out + '"';
return out; return out;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment