7 #ifndef __pinocchio_utils_file_io_hpp__
8 #define __pinocchio_utils_file_io_hpp__
20 const std::string separator_;
21 const std::string escape_seq_;
22 const std::string special_chars_;
25 CsvStream(
const std::string filename,
const std::string separator =
",")
28 , separator_(separator)
30 , special_chars_(
"\"")
32 fs_.exceptions(std::ios::failbit | std::ios::badbit);
33 fs_.open(filename.c_str());
66 return write(escape(val));
69 CsvStream & operator<<(
const std::string & val)
71 return write(escape(val));
96 std::string escape(
const std::string & val)
98 std::ostringstream result;
100 std::string::size_type to, from = 0u, len = val.length();
101 while (from < len && std::string::npos != (to = val.find_first_of(special_chars_, from)))
103 result << val.substr(from, to - from) << escape_seq_ << val[to];
106 result << val.substr(from) <<
'"';
Main pinocchio namespace.