#include <xmlstorage.h>
Public Member Functions | |
ParseContext (XMLReaderBase &reader) | |
void | read_bom () |
bool | proceed () |
int | process_next (int c) |
Public Attributes | |
XMLReaderBase & | _reader |
ReadBuffer | _buffer |
int | _next |
bool | _in_comment |
bool | _utf8 |
Definition at line 2727 of file xmlstorage.h.
XMLStorage::ParseContext::ParseContext | ( | XMLReaderBase & | reader ) |
Definition at line 223 of file xs-native.cpp.
References _in_comment, _next, XMLStorage::XMLReaderBase::get(), and read_bom().
: _reader(reader), _buffer(reader._errors, reader._location), _utf8(false) { _next = reader.get(); _in_comment = false; // check for UTF-8 signature read_bom(); }
bool XMLStorage::ParseContext::proceed | ( | ) |
Definition at line 253 of file xs-native.cpp.
References _next, and process_next().
Referenced by XMLStorage::XMLReaderBase::parse().
{ if (_next != EOF) _next = process_next(_next); return _next != EOF; }
int XMLStorage::ParseContext::process_next | ( | int | c ) |
Definition at line 261 of file xs-native.cpp.
References _buffer, XMLStorage::StyleSheet::_charset, XMLStorage::XMLFormat::_doctype, XMLStorage::XMLFormat::_endl, XMLStorage::XMLReaderBase::_endl_defined, XMLStorage::XMLReaderBase::_format, _in_comment, XMLStorage::StyleSheet::_media, _reader, _stricmp, XMLStorage::XMLFormat::_stylesheets, XMLStorage::StyleSheet::_title, _utf8, XMLStorage::XMLFormat::_utf8_bom, XMLStorage::ReadBuffer::append(), XMLStorage::XMLReaderBase::DefaultHandler(), XMLStorage::XMLReaderBase::eat_endl(), XMLStorage::ReadBuffer::empty(), XMLStorage::XS_StringMap::end(), XMLStorage::XMLReaderBase::EndElementHandler(), XMLStorage::XMLNode::AttributeMap::get(), XMLStorage::XMLReaderBase::get(), XMLStorage::ReadBuffer::get_attributes(), XMLStorage::ReadBuffer::get_tag(), XMLStorage::ReadBuffer::has_CDEnd(), XMLStorage::DocType::parse(), XMLStorage::ReadBuffer::reset(), XMLStorage::XMLReaderBase::StartElementHandler(), XMLStorage::ReadBuffer::str(), XMLStorage::XMLReaderBase::XmlDeclHandler(), XS_icmp, and XS_TEXT.
Referenced by proceed().
{ if (_in_comment || c=='<') { if (!_buffer.empty()) _buffer.reset(); _buffer.append(c); // read start or end tag for(;;) { c = _reader.get(); if (c == EOF) break; _buffer.append(c); if (c == '>') break; } const std::string& b = _buffer.str(_utf8); const char* str = b.c_str(); if (_in_comment || !strncmp(str+1, "!--", 3)) { // XML comment _reader.DefaultHandler(b); if (strcmp(str+b.length()-3, "-->")) _in_comment = true; else _in_comment = false; c = _reader.get(); } else if (str[1] == '/') { // end tag /*@TODO error handling const XS_String& tag = buffer.get_tag(); if (tag != last_opened_tag) { ERROR } */ _reader.EndElementHandler(); c = _reader.get(); } else if (str[1] == '?') { // XML declaration const XS_String& tag = _buffer.get_tag(); if (tag == "?xml") { XMLNode::AttributeMap attributes; _buffer.get_attributes(attributes); const std::string& version = attributes.get("version"); const std::string& encoding = attributes.get("encoding"); int standalone; XMLNode::AttributeMap::const_iterator found = // const_cast for ISO C++ compatibility error of GCC const_cast<const XMLNode::AttributeMap&>(attributes).find("standalone"); if (found != attributes.end()) standalone = !XS_icmp(found->second.c_str(), XS_TEXT("yes")); else standalone = -1; _reader.XmlDeclHandler(version.empty()?NULL:version.c_str(), encoding.empty()?NULL:encoding.c_str(), standalone); if (!encoding.empty()) { if (!_stricmp(encoding.c_str(), "utf-8")) _utf8 = true; else assert(!_reader._format._utf8_bom); // mismatch between BOM and xml header } c = _reader.eat_endl(); } else if (tag == "?xml-stylesheet") { XMLNode::AttributeMap attributes; _buffer.get_attributes(attributes); StyleSheet stylesheet(attributes.get("href"), attributes.get("type"), !XS_icmp(attributes.get("alternate"), XS_TEXT("yes"))); stylesheet._title = attributes.get("title"); stylesheet._media = attributes.get("media"); stylesheet._charset = attributes.get("charset"); _reader._format._stylesheets.push_back(stylesheet); c = _reader.eat_endl(); } else { _reader.DefaultHandler(b); c = _reader.get(); } } else if (str[1] == '!') { if (!strncmp(str+2, "DOCTYPE ", 8)) { _reader._format._doctype.parse(str+10); c = _reader.eat_endl(); } else if (!strncmp(str+2, "[CDATA[", 7)) { // see CDATA_START // parse <![CDATA[ ... ]]> strings while(!_buffer.has_CDEnd()) { c = _reader.get(); if (c == EOF) break; _buffer.append(c); } _reader.DefaultHandler(_buffer.str(_utf8)); c = _reader.get(); } } else { // start tag const XS_String& tag = _buffer.get_tag(); if (!tag.empty()) { XMLNode::AttributeMap attributes; _buffer.get_attributes(attributes); _reader.StartElementHandler(tag, attributes); if (str[b.length()-2] == '/') _reader.EndElementHandler(); } c = _reader.get(); } } else { // in_comment || c=='<' _buffer.append(c); // read white space for(;;) { // check for the encoding of the first line end if (!_reader._endl_defined) { if (c == '\n') { _reader._format._endl = "\n"; _reader._endl_defined = true; } else if (c == '\r') { _reader._format._endl = "\r\n"; _reader._endl_defined = true; } } c = _reader.get(); if (c == EOF) break; if (c == '<') break; _buffer.append(c); } _reader.DefaultHandler(_buffer.str(_utf8)); } _buffer.reset(); return c; }
void XMLStorage::ParseContext::read_bom | ( | ) |
Definition at line 235 of file xs-native.cpp.
References XMLStorage::XMLReaderBase::_format, _next, _reader, _utf8, XMLStorage::XMLFormat::_utf8_bom, and XMLStorage::XMLReaderBase::get().
Referenced by ParseContext().
{ if (_next == 0xEF) { _next = _reader.get(); if (_next == 0xBB) { _next = _reader.get(); if (_next == 0xBF) { _utf8 = true; _reader._format._utf8_bom = true; _next = _reader.get(); } } } }
Definition at line 2736 of file xmlstorage.h.
Referenced by process_next().
Definition at line 2738 of file xmlstorage.h.
Referenced by ParseContext(), and process_next().
Definition at line 2737 of file xmlstorage.h.
Referenced by ParseContext(), proceed(), and read_bom().
Definition at line 2735 of file xmlstorage.h.
Referenced by process_next(), read_bom(), and XMLStorage::XMLStreamReader::XMLStreamReader().
Definition at line 2739 of file xmlstorage.h.
Referenced by process_next(), and read_bom().
ROS Explorer Source Code Documentation
generated on 02.01.2013 by ![]() |