Vcsn  2.3
Be Rational
format.cc
Go to the documentation of this file.
1 #include <cctype>
2 #include <map>
3 
4 #include <vcsn/misc/builtins.hh>
5 #include <vcsn/misc/format.hh>
6 #include <vcsn/misc/getargs.hh>
7 #include <vcsn/misc/map.hh>
8 #include <vcsn/misc/stream.hh>
9 
10 namespace vcsn
11 {
12 
13  format::format(const std::string& f)
14  {
15  static const auto map = getarg<format_t>
16  {
17  "format",
18  {
19  {"auto", "default"},
20  {"default", deflt},
21  {"latex", latex},
22  {"raw", raw},
23  {"sname", sname},
24  {"text", text},
25  {"utf8", utf8},
26  }
27  };
28  format_ = map[f];
29  }
30 
31  std::string to_string(format f)
32  {
33  switch (f.kind())
34  {
35  case format::latex:
36  return "latex";
37  case format::raw:
38  return "raw";
39  case format::sname:
40  return "sname";
41  case format::text:
42  return "text";
43  case format::utf8:
44  return "utf8";
45  }
47  }
48 
49  std::ostream& operator<<(std::ostream& os, format i)
50  {
51  return os << to_string(i);
52  }
53 
54  std::istream& operator>>(std::istream& is, format& fmt)
55  {
56  std::string buf;
57  while (is && isalnum(is.peek()))
58  buf += is.get();
59  fmt = format(buf);
60  return is;
61  }
62 
63 } // namespace vcsn
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
Print as a parsable type string.
Definition: format.hh:26
Definition: a-star.hh:8
format(format_t f=deflt)
Definition: format.hh:35
An input/output format for valuesets.
Definition: format.hh:13
By default, print for text.
Definition: format.hh:32
Request the map implementation.
format_t kind() const
Definition: format.hh:98
Print as is. For instance, don't try to escape labels.
Definition: format.hh:24
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
Print as rich UTF-8 text, escaped.
Definition: format.hh:30
std::istream & operator>>(std::istream &is, direction &d)
Parsing.
Definition: direction.cc:24
Print for LaTeX.
Definition: format.hh:22
A mapping from strings to Values.
Definition: getargs.hh:33
format_t format_
Definition: format.hh:119
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:375
Print as plain (ASCII) text, escaped.
Definition: format.hh:28