15 extern std::ostream
cnull;
18 extern std::wostream
wcnull;
23 bracketed(std::istream& i,
char lbracket,
char rbracket);
26 template <
typename ValueSet,
typename... Args>
28 conv(
const ValueSet& vs,
const std::string& str, Args&&... args)
29 -> decltype(vs.conv(std::declval<std::istream&>(),
30 std::forward<Args>(args)...))
32 std::istringstream i{str};
33 auto res = vs.conv(i, std::forward<Args>(args)...);
35 vs.sname(),
": invalid value: ", str,
45 char eat(std::istream&
is,
char c);
52 const std::string&
eat(std::istream&
is,
const std::string& s);
59 template <
typename... Args>
66 std::getline(is, buf,
'\n');
71 raise(std::forward<Args>(args)...);
73 raise(std::forward<Args>(args)...,
": ",
str_escape(buf));
93 "get_char: unexpected end-of-file"
96 "get_char: invalid escape: \\x",
char(c1));
99 "get_char: unexpected end-of-file"
100 " after: \\x",
char(c1));
102 "get_char: invalid escape: \\x",
104 res = std::stoi(std::string{
char(c1),
char(c2)},
nullptr, 16);
106 else if (std::isalnum(c))
107 raise(
"get_char: invalid escape: \\",
char(c),
" in \\", i);
112 "get_char: unexpected end-of-file");
117 template <
typename ValueSet,
typename Value =
typename ValueSet::value_t,
120 to_string(
const ValueSet& vs,
const Value&
v, Args&&... args)
123 std::ostringstream o;
124 vs.print(
v, o, std::forward<Args>(args)...);
133 std::shared_ptr<std::istream>
open_input_file(
const std::string& file);
std::shared_ptr< std::istream > open_input_file(const std::string &file)
Open file for reading and return its autoclosing stream.
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
char get_char(std::istream &i)
Read a single char, with possible -escape support.
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
std::string to_string(direction d)
Conversion to string.
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
std::shared_ptr< std::ostream > open_output_file(const std::string &file)
Open file for writing and return its autoclosing stream.
char eat(std::istream &is, char c)
Check lookahead character and advance.
std::string bracketed(std::istream &i, char lbracket, char rbracket)
Extract the string which is here between lbracket and rbracket.
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, Args &&...args)
Throw an exception after failing to read from is.
std::string get_file_contents(const std::string &file)
Return the contents of file.
std::istringstream is
The input stream: the specification to translate.
std::ostream cnull
An narrow-char stream that discards the output.
std::wostream wcnull
An wide-char stream that discards the output.
auto conv(const ValueSet &vs, const std::string &str, Args &&...args) -> decltype(vs.conv(std::declval< std::istream & >(), std::forward< Args >(args)...))
Parse str via vs.conv.