16#include <boost/spirit/include/karma.hpp>
45 s <<
"oks[" <<
p_level <<
"] ***: " << what_arg << std::ends;
51 std::string text(name);
52 text +=
" is not set";
53 throw std::runtime_error(text.c_str());
57 BadFileData::fill(
const std::string& item,
unsigned long line_no,
unsigned long line_pos)
noexcept
60 s << item <<
" (line " << line_no <<
", char " << line_pos <<
')';
67 return (std::string(
"Failed to read \'") + item +
"\'\n" + reason);
71 FailedSave::fill(
const std::string& item,
const std::string& name,
const std::string& reason)
noexcept
73 return (std::string(
"Failed to save ") + item +
" \'" + name +
"\'\n" + reason);
79 return (std::string(
"Read end-of-stream tag \'") + tag +
'\'');
89 s +=
"Failed to read ";
96 s +=
"\' is expected instead of \'";
119 throw std::runtime_error(
"write to file failed");
152 while(*str)
put(*str++);
192 static const char __end_tag[] =
"/>\n";
193 put_raw(__end_tag,
sizeof(__end_tag)-1);
199 static const char __eol_tag[] =
">\n";
200 put_raw(__eol_tag,
sizeof(__eol_tag)-1);
248 boost::spirit::karma::generate(ptr, boost::spirit::uint_, (
unsigned int)value);
268 std::ostringstream s;
272 s <<
"expected tag \'" << expected <<
'\'';
279 s <<
"unexpected tag \'" << what <<
'\'' ;
281 s <<
" instead of \'" << expected <<
'\'' ;
302 if( __builtin_expect((c !=
'\"'), 0) ) {
309 if( __builtin_expect((c ==
'\"'), 0) ) {
313 else if( __builtin_expect((c ==
'&'), 0) ) {
321 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) ) {
371 if(c2 ==
'<') count++;
372 else if(c2 ==
'>') count--;
379 char buf[3] = {0, 0, 0};
380 unsigned long start_comment_line_no =
line_no;
392 catch(std::exception& failure) {
393 std::ostringstream what;
394 what <<
"Cannot find end of comment started on line " << start_comment_line_no <<
": " << failure.what();
410 if(count != 0) {
throw std::runtime_error(
"unbalanced tags"); }
411 else {
return m_v1->m_buf; }
415 catch(std::exception& ex) {
417 throw oks::BadFileData(std::string(ex.what()) +
" when read xml tag started at", start_line_no, start_line_pos);
444 throw std::runtime_error(
"cannot find closing separator while read token");
451 token.
m_buf[0] = __fs;
452 if(__fs == __s1 || __fs == __s2) { token.
m_buf[1] =
'\0';
return 1; }
466 throw std::runtime_error(
"cannot find closing separator while read token");
486 throw std::runtime_error(
"cannot find closing separator while read token");
496 if( __builtin_expect((c !=
'<'), 0) ) {
504 char buf[3] = {0, 0, 0};
505 unsigned long start_comment_line_no =
line_no;
506 auto tag_len = strlen(
m_v1->m_buf);
518 catch(std::exception& failure) {
519 std::ostringstream what;
520 what <<
"Cannot find end of comment started on line " << start_comment_line_no <<
": " << failure.what();
525 if( __builtin_expect((c !=
'>'), 1) )
return m_v1->m_buf;
528 catch(std::exception& ex) {
538 unsigned long start_line_no = s.line_no;
539 unsigned long start_line_pos = s.line_pos;
542 char c = s.get_first_non_empty();
544 start_line_no = s.line_no;
545 start_line_pos = s.line_pos;
547 size_t pos = s.get_token2(c,
'=',
'>',
p_name);
549 char * m_buf_ptr(
p_name.m_buf);
553 for(
char * str(m_buf_ptr + pos - 1); str >= m_buf_ptr; --str) {
554 if(*str ==
' ' || *str ==
'\n' || *str ==
'\r' || *str ==
'\t') {
562 if(c ==
'>' || c ==
'/' || c ==
'?')
return;
564 c = s.get_first_non_empty();
566 if( __builtin_expect((c !=
'\"'), 0) ) {
572 TLOG_DEBUG(8) <<
"read attribute \'" << m_buf_ptr <<
"\' and value \'" <<
p_value.m_buf <<
'\'';
574 catch(std::exception& ex) {
575 throw oks::BadFileData(std::string(ex.what()) +
" when read xml attribute started at", start_line_no, start_line_pos);
603 std::string text(
"bad symbol \'&");
606 throw std::runtime_error(text.c_str());
621 throw std::runtime_error(
"unexpected end of file");
627 std::ostringstream text;
628 text <<
"function " <<
f <<
"(\'" << what <<
"\') has failed";
629 if(*where) text <<
" on unrecognized characters \'" << where <<
"\'";
630 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)