Ejemplo n.º 1
0
inline void out_quote(std::basic_ostream<Ch, Tr> &out, const C& data, IsSpecial is_special = IsSpecial(), char quote_char='"', char escape_char='\\') {
  std::basic_stringstream<Ch, Tr> s;
  s << data;
  or_true_for_chars<IsSpecial> needs_quote(quote_char, escape_char, is_special);
  typedef std::istreambuf_iterator<Ch, Tr> i_iter;
  typedef std::ostream_iterator<Ch, Tr> o_iter;
  i_iter i(s), end;
  bool quote = (std::find_if (i, end, needs_quote) != end);
  rewind(s);
  if (quote) {
    out << quote_char;
    for (i_iter i(s); i!=end; ++i) {
      Ch c=*i;
      if (c == quote_char || c== escape_char)
        out.put(escape_char);
      out.put(c);
    }
    out << quote_char;
  } else {
    //        std::copy(i_iter(s),end,o_iter(out));
    /*
      for (i_iter i(s);i!=end;++i)
      out.put(*i);
    */
    Ch c;
    while (s.get(c))
      out.put(c);
  }
}
Ejemplo n.º 2
0
inline void out_string_always_quote(std::basic_ostream<Ch, Tr> &out, S const& s)
{
  out << '"';
  for (typename S::const_iterator i = s.begin(), e = s.end(); i!=e; ++i) {
    char c=*i;
    if (c == '"' || c== '\\')
      out.put('\\');
    out.put(c);
  }
  out << '"';
}
Ejemplo n.º 3
0
inline void out_always_quote(std::basic_ostream<Ch, Tr> &out, const C& data) {
  std::basic_stringstream<Ch, Tr> s;
  s << data;
  char c;
  out << '"';
  while (s.get(c)) {
    if (c == '"' || c== '\\')
      out.put('\\');
    out.put(c);
  }
  out << '"';
}