File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -428,7 +428,7 @@ namespace minsky
428428 }
429429 of<<quoted (" RavelHypercube=[" +os.str ()+" ]" )<<endl;
430430 for (const auto & i: hypercube ().xvectors )
431- of<<" \" " << i.name << " \ " ," ;
431+ of<<CSVQuote ( i.name , ' , ' )<< " ," ;
432432 of<<" value$\n " ;
433433
434434 auto idxv=index ();
Original file line number Diff line number Diff line change @@ -90,14 +90,14 @@ namespace minsky
9090 redrawAllGodleyTables ();
9191 return m_multipleEquities;
9292 }
93-
93+
9494 void Minsky::openLogFile (const string& name)
9595 {
9696 outputDataFile.reset (new ofstream (name));
9797 *outputDataFile<< " #time" ;
9898 for (auto & v: variableValues)
9999 if (logVarList.contains (v.first ))
100- *outputDataFile<<" " <<v.second ->name ;
100+ *outputDataFile<<" " <<CSVQuote ( v.second ->name , ' ' ) ;
101101 *outputDataFile<<endl;
102102 }
103103
Original file line number Diff line number Diff line change @@ -152,6 +152,20 @@ namespace minsky
152152 s.seekg (0 ); // rewind input stream
153153 }
154154
155+ // / quotes a string if it contains a separator character, and double quotes quotes
156+ inline std::string CSVQuote (const std::string& x, char sep)
157+ {
158+ std::string r;
159+ bool needsQuoting=false ;
160+ for (auto c: x)
161+ {
162+ r+=c;
163+ if (c==' "' ) {r+=' "' ; needsQuoting=true ;}
164+ if (c==sep) needsQuoting=true ;
165+ }
166+ if (needsQuoting) return " \" " +r+" \" " ;
167+ return r;
168+ }
155169
156170}
157171#endif
You can’t perform that action at this time.
0 commit comments