formater: add support for double-quoted fields
Part of #91. * spot/misc/formater.cc, spot/misc/formater.hh: Here. * bin/common_output.cc: Adjust automatic output format. * doc/org/csv.org: Adjust. * tests/core/lbt.test, tests/core/ltlfilt.test: More tests. * NEWS: Mention the changes.
This commit is contained in:
parent
6ed0830f87
commit
0d753048ce
7 changed files with 97 additions and 28 deletions
|
|
@ -19,8 +19,10 @@
|
|||
|
||||
#include "config.h"
|
||||
#include <spot/misc/formater.hh>
|
||||
#include <spot/misc/escape.hh>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -66,8 +68,22 @@ namespace spot
|
|||
|
||||
std::ostream&
|
||||
formater::format(const char* fmt)
|
||||
{
|
||||
for (const char* pos = fmt; *pos; ++pos)
|
||||
{
|
||||
for (const char* pos = fmt; *pos; ++pos)
|
||||
{
|
||||
if (*pos == '"')
|
||||
{
|
||||
*output_ << '"';
|
||||
const char* end = strchr(pos + 1, '"');
|
||||
if (!end)
|
||||
continue;
|
||||
std::string tmp(pos + 1, end - (pos + 1));
|
||||
std::ostringstream os;
|
||||
format(os, tmp);
|
||||
escape_rfc4180(*output_, os.str());
|
||||
pos = end;
|
||||
// the end double-quote will be printed below
|
||||
}
|
||||
if (*pos != '%')
|
||||
{
|
||||
*output_ << *pos;
|
||||
|
|
@ -95,6 +111,7 @@ namespace spot
|
|||
break;
|
||||
pos = next;
|
||||
}
|
||||
return *output_;
|
||||
}
|
||||
}
|
||||
return *output_;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,8 +173,11 @@ namespace spot
|
|||
std::ostream&
|
||||
format(std::ostream& output, const char* fmt)
|
||||
{
|
||||
std::ostream* tmp = output_;
|
||||
set_output(output);
|
||||
return format(fmt);
|
||||
format(fmt);
|
||||
set_output(*tmp);
|
||||
return output;
|
||||
}
|
||||
|
||||
/// Expand the %-sequences in \a fmt, write the result on \a output_.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue