Vcsn  2.8
Be Rational
escape.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iosfwd>
4 #include <iostream>
5 #include <sstream>
6 #include <string>
7 #include <vector>
8 
9 #include <vcsn/misc/export.hh>
10 
11 namespace vcsn LIBVCSN_API
12 {
14  std::ostream& str_escape(std::ostream& os, const std::string& str,
15  const char* special = nullptr);
16 
18  template <typename T>
19  std::ostream& str_escape(std::ostream& os,
20  const std::vector<T>& s,
21  const char* special = nullptr)
22  {
23  for (auto c: s)
24  str_escape(os, c, special);
25  return os;
26  }
27 
30  std::ostream& str_escape(std::ostream& os, int c,
31  const char* special = nullptr);
32 
34  std::ostream& str_escape(std::ostream& os, char c,
35  const char* special = nullptr);
36 
38  template <typename T>
39  std::string str_escape(T&& s,
40  const char* special = nullptr)
41  {
42  std::ostringstream o;
43  str_escape(o, std::forward<T>(s), special);
44  return o.str();
45  }
46 
48  template <typename... Args>
49  std::string str_quote(Args&&... args)
50  {
51  std::ostringstream o;
52  o << '"';
53  using swallow = int[];
54  (void) swallow
55  {
56  (str_escape(o, std::forward<Args>(args), "\""), 0)...
57  };
58  o << '"';
59  return o.str();
60  }
61 }
#define LIBVCSN_API
Definition: export.hh:8
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
Definition: escape.cc:51
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:404
Definition: a-star.hh:8
return o str()
std::string str_quote(Args &&... args)
Convert to a string, in quotes.
Definition: escape.hh:49