11#include <boost/spirit/include/karma.hpp>
40 s <<
"oks[" << p_level <<
"] ***: " << what_arg << std::ends;
46 std::string text(name);
47 text +=
" is not set";
48 throw std::runtime_error(text.c_str());
52 BadFileData::fill(
const std::string& item,
unsigned long line_no,
unsigned long line_pos)
noexcept
55 s << item <<
" (line " << line_no <<
", char " << line_pos <<
')';
62 return (std::string(
"Failed to read \'") + item +
"\'\n" + reason);
66 FailedSave::fill(
const std::string& item,
const std::string& name,
const std::string& reason)
noexcept
68 return (std::string(
"Failed to save ") + item +
" \'" + name +
"\'\n" + reason);
74 return (std::string(
"Read end-of-stream tag \'") + tag +
'\'');
84 s +=
"Failed to read ";
91 s +=
"\' is expected instead of \'";
114 throw std::runtime_error(
"write to file failed");
147 while(*str)
put(*str++);
187 static const char __end_tag[] =
"/>\n";
188 put_raw(__end_tag,
sizeof(__end_tag)-1);
194 static const char __eol_tag[] =
">\n";
195 put_raw(__eol_tag,
sizeof(__eol_tag)-1);
243 boost::spirit::karma::generate(ptr, boost::spirit::uint_, (
unsigned int)value);
263 std::ostringstream s;
267 s <<
"expected tag \'" << expected <<
'\'';
274 s <<
"unexpected tag \'" << what <<
'\'' ;
276 s <<
" instead of \'" << expected <<
'\'' ;
297 if( __builtin_expect((c !=
'\"'), 0) ) {
304 if( __builtin_expect((c ==
'\"'), 0) ) {
308 else if( __builtin_expect((c ==
'&'), 0) ) {
316 throw std::runtime_error(
"cannot find closing quote character");
318 catch (std::exception & ex) {
342 unsigned long start_line_no =
line_no;
343 unsigned long start_line_pos =
line_pos;
351 if( __builtin_expect((c !=
'<'), 0) ) {
366 if(c2 ==
'<') count++;
367 else if(c2 ==
'>') count--;
374 char buf[3] = {0, 0, 0};
375 unsigned long start_comment_line_no =
line_no;
387 catch(std::exception& failure) {
388 std::ostringstream what;
389 what <<
"Cannot find end of comment started on line " << start_comment_line_no <<
": " << failure.what();
405 if(count != 0) {
throw std::runtime_error(
"unbalanced tags"); }
410 catch(std::exception& ex) {
412 throw oks::BadFileData(std::string(ex.what()) +
" when read xml tag started at", start_line_no, start_line_pos);
439 throw std::runtime_error(
"cannot find closing separator while read token");
446 token.
m_buf[0] = __fs;
447 if(__fs == __s1 || __fs == __s2) { token.
m_buf[1] =
'\0';
return 1; }
461 throw std::runtime_error(
"cannot find closing separator while read token");
481 throw std::runtime_error(
"cannot find closing separator while read token");
491 if( __builtin_expect((c !=
'<'), 0) ) {
499 char buf[3] = {0, 0, 0};
500 unsigned long start_comment_line_no =
line_no;
513 catch(std::exception& failure) {
514 std::ostringstream what;
515 what <<
"Cannot find end of comment started on line " << start_comment_line_no <<
": " << failure.what();
520 if( __builtin_expect((c !=
'>'), 1) )
return m_v1->
m_buf;
523 catch(std::exception& ex) {
533 unsigned long start_line_no = s.line_no;
534 unsigned long start_line_pos = s.line_pos;
537 char c = s.get_first_non_empty();
539 start_line_no = s.line_no;
540 start_line_pos = s.line_pos;
542 size_t pos = s.get_token2(c,
'=',
'>',
p_name);
548 for(
char * str(m_buf_ptr + pos - 1); str >= m_buf_ptr; --str) {
549 if(*str ==
' ' || *str ==
'\n' || *str ==
'\r' || *str ==
'\t') {
557 if(c ==
'>' || c ==
'/' || c ==
'?')
return;
559 c = s.get_first_non_empty();
561 if( __builtin_expect((c !=
'\"'), 0) ) {
569 catch(std::exception& ex) {
570 throw oks::BadFileData(std::string(ex.what()) +
" when read xml attribute started at", start_line_no, start_line_pos);
598 std::string text(
"bad symbol \'&");
601 throw std::runtime_error(text.c_str());
616 throw std::runtime_error(
"unexpected end of file");
622 std::ostringstream text;
623 text <<
"function " <<
f <<
"(\'" << what <<
"\') has failed";
624 if(*where) text <<
" on unrecognized characters \'" << where <<
"\'";
625 if(errno) 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])
the structure to pass common parameters to various read() methods of OksData and OksObject class
void WriteTo(OksXmlOutputStream &, bool) const
OksXmlAttribute(OksXmlInputStream &s)
void realloc(unsigned long pos)