16#include <boost/spirit/include/karma.hpp>
45 s <<
"oks[" <<
p_level <<
"] ***: " << what_arg << std::ends;
52 std::string text(name);
53 text +=
" is not set";
54 throw std::runtime_error(text.c_str());
58BadFileData::fill(
const std::string& item,
unsigned long line_no,
unsigned long line_pos)
noexcept
61 s << item <<
" (line " << line_no <<
", char " << line_pos <<
')';
68 return (std::string(
"Failed to read \'") + item +
"\'\n" + reason);
72FailedSave::fill(
const std::string& item,
const std::string& name,
const std::string& reason)
noexcept
74 return (std::string(
"Failed to save ") + item +
" \'" + name +
"\'\n" + reason);
80 return (std::string(
"Read end-of-stream tag \'") + tag +
'\'');
89 s +=
"Failed to read ";
96 s +=
"\' is expected instead of \'";
122 throw std::runtime_error(
"write to file failed");
198 static const char __end_tag[] =
"/>\n";
199 put_raw(__end_tag,
sizeof(__end_tag) - 1);
205 static const char __eol_tag[] =
">\n";
206 put_raw(__eol_tag,
sizeof(__eol_tag) - 1);
252 boost::spirit::karma::generate(ptr, boost::spirit::uint_, (
unsigned int)value);
272 std::ostringstream s;
276 s <<
"expected tag \'" << expected <<
'\'';
281 s <<
"unexpected tag \'" << what <<
'\'';
283 s <<
" instead of \'" << expected <<
'\'';
304 if (__builtin_expect((c !=
'\"'), 0)) {
311 if (__builtin_expect((c ==
'\"'), 0)) {
314 }
else if (__builtin_expect((c ==
'&'), 0)) {
322 throw std::runtime_error(
"cannot find closing quote character");
323 }
catch (std::exception& ex) {
347 unsigned long start_line_no =
line_no;
348 unsigned long start_line_pos =
line_pos;
356 if (__builtin_expect((c !=
'<'), 0)) {
381 char buf[3] = { 0, 0, 0 };
382 unsigned long start_comment_line_no =
line_no;
393 }
catch (std::exception& failure) {
394 std::ostringstream what;
395 what <<
"Cannot find end of comment started on line " << start_comment_line_no <<
": " << failure.what();
412 throw std::runtime_error(
"unbalanced tags");
418 }
catch (std::exception& ex) {
420 throw oks::BadFileData(std::string(ex.what()) +
" when read xml tag started at", start_line_no, start_line_pos);
440 }
else if (__builtin_expect((
last_read_c ==
'&'), 0))
449 throw std::runtime_error(
"cannot find closing separator while read token");
456 token.
m_buf[0] = __fs;
457 if (__fs == __s1 || __fs == __s2) {
458 token.
m_buf[1] =
'\0';
468 }
else if (__builtin_expect((
last_read_c ==
'&'), 0))
477 throw std::runtime_error(
"cannot find closing separator while read token");
497 }
else if (__builtin_expect((
last_read_c ==
'&'), 0))
506 throw std::runtime_error(
"cannot find closing separator while read token");
516 if (__builtin_expect((c !=
'<'), 0)) {
524 char buf[3] = { 0, 0, 0 };
525 unsigned long start_comment_line_no =
line_no;
538 }
catch (std::exception& failure) {
539 std::ostringstream what;
540 what <<
"Cannot find end of comment started on line " << start_comment_line_no <<
": " << failure.what();
545 if (__builtin_expect((c !=
'>'), 1))
548 }
catch (std::exception& ex) {
559 unsigned long start_line_no = s.line_no;
560 unsigned long start_line_pos = s.line_pos;
563 char c = s.get_first_non_empty();
565 start_line_no = s.line_no;
566 start_line_pos = s.line_pos;
568 size_t pos = s.get_token2(c,
'=',
'>',
p_name);
574 for (
char* str(m_buf_ptr + pos - 1); str >= m_buf_ptr; --str) {
575 if (*str ==
' ' || *str ==
'\n' || *str ==
'\r' || *str ==
'\t') {
582 if (c ==
'>' || c ==
'/' || c ==
'?')
585 c = s.get_first_non_empty();
587 if (__builtin_expect((c !=
'\"'), 0)) {
594 }
catch (std::exception& ex) {
596 std::string(ex.what()) +
" when read xml attribute started at", start_line_no, start_line_pos);
631 std::string text(
"bad symbol \'&");
634 throw std::runtime_error(text.c_str());
647 throw std::runtime_error(
"unexpected end of file");
657 std::ostringstream text;
658 text <<
"function " <<
f <<
"(\'" << what <<
"\') has failed";
660 text <<
" on unrecognized characters \'" << where <<
"\'";
662 text <<
" with code " << errno <<
", reason = \'" <<
oks::strerror(errno) <<
'\'';
static std::string fill(const std::string &what, unsigned long line_no, unsigned long line_pos) noexcept
static std::string fill(const std::string &tag)
static std::string fill(const std::string &what, const std::string &reason) noexcept
static std::string fill(const std::string &what, const std::string &name, const std::string &reason) noexcept
void put_last_tag(const char *, size_t len)
void put_attribute(const char *, size_t len, const char *)
void put_start_tag(const char *, size_t len)
static void __throw_write_failed()
void put_quoted(const char *)
static std::ostream & error_msg(const char *)
exception(const std::string &what_arg, int level_arg) noexcept
#define TLOG_DEBUG(lvl,...)
const char left_angle_bracket[]
const char single_quote[]
const char right_angle_bracket[]
const char carriage_return[]
const char double_quote[]
bool cmp_str2n(const char *s1, const char s2[2])
const std::string strerror(int error)
Convert C error number to string.
static void __throw_bad_file_data_unexpected_symbol(const char *what, const char expected, const char read, unsigned long l, unsigned long p)
bool __is_comment(const char *s)
bool cmp_str3n(const char *s1, const char s2[3])
static std::string report_unexpected(const char *what, const char expected, const char read)
void throw_validate_not_empty(const char *name)
static void __throw_runtime_error_unexpected_symbol(const char expected, const char read)
bool cmp_str4n(const char *s1, const char s2[4])
void WriteTo(OksXmlOutputStream &, bool) const
OksXmlAttribute(OksXmlInputStream &s)
void realloc(unsigned long pos)