17 bracketed(std::istream& i,
const char lbracket,
const char rbracket)
19 assert(i.peek() == lbracket);
24 while ((c = i.get()) != -1)
28 else if (c == rbracket
33 raise(
"missing ",
str_escape(rbracket),
" after ",
37 char eat(std::istream&
is,
char c)
48 const std::string&
eat(std::istream&
is,
const std::string& expect)
52 size_t cnt = expect.size();
53 while (cnt && is >> c)
69 VCSN_REQUIRE(
in.good(),
"cannot read file: ", file,
": ", strerror(errno));
72 in.seekg(0, std::ios::end);
73 res.resize(
in.tellg());
74 in.seekg(0, std::ios::beg);
75 in.read(&res[0], res.size());
80 std::shared_ptr<std::istream>
83 std::shared_ptr<std::istream> res;
84 if (file.empty() || file ==
"-")
85 res.reset(&std::cin, [](...){});
88 res.reset(
new std::ifstream(file.c_str()));
90 "cannot open ", file,
" for reading: ", strerror(errno));
95 std::shared_ptr<std::ostream>
98 std::shared_ptr<std::ostream> res;
99 if (file.empty() || file ==
"-")
100 res.reset(&std::cout, [](...){});
103 res.reset(
new std::ofstream(file.c_str()));
105 "cannot open ", file,
" for writing: ", strerror(errno));
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.
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 in(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions arriving to state s.