ltlcross: follow RFC 4180 for CSV output.

* src/misc/escape.cc, src/misc/escape.hh (escape_rfc4180): New
function.
* src/bin/ltlcross.cc: Do not output space after ',', use
"\r\n" for end of line, and use escape_rfc4180().
* NEWS: Mention it.
This commit is contained in:
Alexandre Duret-Lutz 2013-10-16 10:31:31 +02:00
parent 925a807f4f
commit 1c5536ea9c
4 changed files with 81 additions and 53 deletions

View file

@ -31,6 +31,22 @@
namespace spot
{
std::ostream&
escape_rfc4180(std::ostream& os, const std::string& str)
{
for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
switch (*i)
{
case '"':
os << "\"\"";
break;
default:
os << *i;
break;
}
return os;
}
std::ostream&
escape_str(std::ostream& os, const std::string& str)
{

View file

@ -32,16 +32,26 @@ namespace spot
/// \addtogroup misc_tools
/// @{
/// \brief Escape characters <code>"</code>, <code>\\</code>, and
/// <code>\\n</code> in \a str.
SPOT_API std::ostream& escape_str(std::ostream& os, const std::string& str);
/// \brief Double characters <code>"</code> in strings.
///
/// In CSV files, as defined by RFC4180, double-quoted string that
/// contain double-quotes should simply duplicate those quotes.
SPOT_API std::ostream&
escape_rfc4180(std::ostream& os, const std::string& str);
/// \brief Escape characters <code>"</code>, <code>\\</code>, and
/// <code>\\n</code> in \a str.
SPOT_API std::string escape_str(const std::string& str);
SPOT_API std::ostream&
escape_str(std::ostream& os, const std::string& str);
/// \brief Escape characters <code>"</code>, <code>\\</code>, and
/// <code>\\n</code> in \a str.
SPOT_API std::string
escape_str(const std::string& str);
/// \brief Remove spaces at the front and back of \a str.
SPOT_API void trim(std::string& str);
SPOT_API void
trim(std::string& str);
/// @}
}