void sax_parser<_Handler,_Config>::attribute() { sax::parser_attribute attr; pstring attr_ns_name, attr_name, attr_value; attribute_name(attr.ns, attr.name); #if ORCUS_DEBUG_SAX_PARSER std::ostringstream os; os << "sax_parser::attribute: ns='" << attr.ns << "', name='" << attr.name << "'"; #endif char c = cur_char(); if (c != '=') { std::ostringstream os; os << "Attribute must begin with 'name=..'. (ns='" << attr.ns << "', name='" << attr.name << "')"; throw sax::malformed_xml_error(os.str()); } next_check(); attr.transient = value(attr.value, true); if (attr.transient) // Value is stored in a temporary buffer. Push a new buffer. inc_buffer_pos(); #if ORCUS_DEBUG_SAX_PARSER os << " value='" << attr.value << "'" << endl; cout << os.str(); #endif m_handler.attribute(attr); }
void TestQPrefUpdateManager::test_struct_disk() { // test struct prefs -> disk auto tst = qPrefUpdateManager::instance(); prefs.update_manager.dont_check_for_updates = true; prefs.update_manager.dont_check_exists = true; prefs.update_manager.last_version_used = copy_qstring("last_version"); prefs.update_manager.next_check = QDate::fromString("11/09/1957", "dd/MM/yyyy").toJulianDay(); tst->sync(); prefs.update_manager.dont_check_for_updates = false; prefs.update_manager.dont_check_exists = false; prefs.update_manager.last_version_used = copy_qstring(""); prefs.update_manager.next_check = 1000; tst->load(); QCOMPARE(tst->dont_check_for_updates(), true); QCOMPARE(tst->last_version_used(), QString("last_version")); QCOMPARE(tst->next_check(), QDate::fromString("11/09/1957", "dd/MM/yyyy")); // dont_check_exists is NOT stored on disk QCOMPARE(tst->dont_check_exists(), false); }
void TestQPrefUpdateManager::test_next_check() { auto tst = qPrefUpdateManager::instance(); prefs.update_manager.next_check = QDate::fromString("11/09/1957", "dd/MM/yyyy").toJulianDay(); prefs.update_manager.next_check++; QCOMPARE(tst->next_check(), QDate::fromString("12/09/1957", "dd/MM/yyyy")); }
void parser_base::attribute_name(pstring& attr_ns, pstring& attr_name) { name(attr_name); if (cur_char() == ':') { // Attribute name is namespaced. attr_ns = attr_name; next_check(); name(attr_name); } }
void parser_base::element_name(parser_element& elem, const char* begin_pos) { elem.begin_pos = begin_pos; name(elem.name); if (cur_char() == ':') { elem.ns = elem.name; next_check(); name(elem.name); } }
void TestQPrefUpdateManager::test_oldPreferences() { auto update = qPrefUpdateManager::instance(); QDate date = QDate::currentDate(); update->set_dont_check_for_updates(true); update->set_last_version_used("tomaz-1"); update->set_next_check(date); TEST(update->dont_check_for_updates(), true); TEST(update->last_version_used(), QStringLiteral("tomaz-1")); TEST(update->next_check(), date); date = date.addDays(3); update->set_dont_check_for_updates(false); update->set_last_version_used("tomaz-2"); update->set_next_check(date); TEST(update->dont_check_for_updates(), false); TEST(update->last_version_used(), QStringLiteral("tomaz-2")); TEST(update->next_check(), date); }
void TestQPrefUpdateManager::test_struct_get() { // Test struct pref -> get func. auto tst = qPrefUpdateManager::instance(); prefs.update_manager.dont_check_for_updates = true; prefs.update_manager.dont_check_exists = true; prefs.update_manager.last_version_used = copy_qstring("last_version"); prefs.update_manager.next_check = QDate::fromString("11/09/1957", "dd/MM/yyyy").toJulianDay(); QCOMPARE(tst->dont_check_for_updates(), true); QCOMPARE(tst->dont_check_exists(), true); QCOMPARE(tst->last_version_used(), QString("last_version")); QCOMPARE(tst->next_check(), QDate::fromString("11/09/1957", "dd/MM/yyyy")); }
void sax_parser<_Handler,_Config>::element_close(const char* begin_pos) { assert(cur_char() == '/'); nest_down(); next_check(); sax::parser_element elem; element_name(elem, begin_pos); if (cur_char() != '>') throw sax::malformed_xml_error("expected '>' to close the element."); next(); elem.end_pos = m_char; m_handler.end_element(elem); #if ORCUS_DEBUG_SAX_PARSER cout << "element_close: ns='" << elem.ns << "', name='" << elem.name << "'" << endl; #endif if (!m_nest_level) m_root_elem_open = false; }
void sax_parser<_Handler,_Config>::declaration(const char* name_check) { assert(cur_char() == '?'); next_check(); // Get the declaration name first. pstring decl_name; name(decl_name); #if ORCUS_DEBUG_SAX_PARSER cout << "sax_parser::declaration: start name='" << decl_name << "'" << endl; #endif if (name_check && decl_name != name_check) { std::ostringstream os; os << "declaration name of '" << name_check << "' was expected, but '" << decl_name << "' was found instead."; throw sax::malformed_xml_error(os.str()); } m_handler.start_declaration(decl_name); blank(); // Parse the attributes. while (cur_char_checked() != '?') { attribute(); blank(); } if (next_char_checked() != '>') throw sax::malformed_xml_error("declaration must end with '?>'."); m_handler.end_declaration(decl_name); reset_buffer_pos(); next(); #if ORCUS_DEBUG_SAX_PARSER cout << "sax_parser::declaration: end name='" << decl_name << "'" << endl; #endif }
void sax_parser<_Handler,_Config>::doctype() { // Parse the root element first. sax::doctype_declaration param; name(param.root_element); blank(); // Either PUBLIC or SYSTEM. size_t len = remains(); if (len < 6) sax::malformed_xml_error("DOCTYPE section too short."); param.keyword = sax::doctype_declaration::keyword_private; char c = cur_char(); if (c == 'P') { if (next_char() != 'U' || next_char() != 'B' || next_char() != 'L' || next_char() != 'I' || next_char() != 'C') throw sax::malformed_xml_error("malformed DOCTYPE section."); param.keyword = sax::doctype_declaration::keyword_public; } else if (c == 'S') { if (next_char() != 'Y' || next_char() != 'S' || next_char() != 'T' || next_char() != 'E' || next_char() != 'M') throw sax::malformed_xml_error("malformed DOCTYPE section."); } next_check(); blank(); has_char_throw("DOCTYPE section too short."); // Parse FPI. value(param.fpi, false); has_char_throw("DOCTYPE section too short."); blank(); has_char_throw("DOCTYPE section too short."); if (cur_char() == '>') { // Optional URI not given. Exit. #if ORCUS_DEBUG_SAX_PARSER cout << "sax_parser::doctype: root='" << param.root_element << "', fpi='" << param.fpi << "'" << endl; #endif m_handler.doctype(param); next(); return; } // Parse optional URI. value(param.uri, false); has_char_throw("DOCTYPE section too short."); blank(); has_char_throw("DOCTYPE section too short."); if (cur_char() != '>') throw sax::malformed_xml_error("malformed DOCTYPE section - closing '>' expected but not found."); #if ORCUS_DEBUG_SAX_PARSER cout << "sax_parser::doctype: root='" << param.root_element << "', fpi='" << param.fpi << "' uri='" << param.uri << "'" << endl; #endif m_handler.doctype(param); next(); }