1#if defined(HAVE_CONFIG_H)
12#define RESIPROCATE_SUBSYSTEM Subsystem::CONTENTS
76 const char* anchor = start;
85 lPb.
data(temp, anchor);
91 lPb.
data(temp, anchor);
103 mCursor = mRoot.get();
105 if (mRoot->extractTag())
107 InfoLog(<<
"XML: empty element no a legal root");
108 mRoot->mPb.fail(__FILE__, __LINE__);
112 decodeName(mRoot->mTag);
129 if (strncmp(mRoot->mTag.data(), pbtemp.
position(), mRoot->mTag.size()) == 0)
132 mRoot->mPb.reset(mRoot->mPb.end());
161XMLCursor::decode(
Data& text)
166XMLCursor::decodeName(
Data& name)
171XMLCursor::parseNextRootChild()
174 if (mRoot->mPb.eof())
180 if (mRoot->mNext != mRoot->mChildren.end())
186 if (mRoot->mPb.position() == mRoot->mPb.start())
189 mRoot->mPb.skipChar();
194 mRoot->mPb.skipWhitespace();
198 if (*mRoot->mPb.position() ==
LA_QUOTE[0])
201 mRoot->mPb.end() - mRoot->mPb.position());
210 if ( (
const char*)pb.
end() < end + mTag.
size() )
212 InfoLog(<<
"XML: unexpected end");
213 pb.
fail(__FILE__, __LINE__);
216 if (strncmp(mTag.
data(), pb.
position(), mRoot->mTag.size()) == 0)
218 mRoot->mPb.skipToEnd();
225 if (*mRoot->mPb.position() !=
LA_QUOTE[0])
227 const char* anchor = mRoot->mPb.position();
230 leaf->mIsLeaf =
true;
231 mRoot->addChild(leaf);
238 std::unique_ptr<Node> child(
new Node(mRoot->mPb));
239 child->skipToEndTag(1);
242 mRoot->mPb.reset(child->mPb.end());
244 mRoot->addChild(child.release());
248 mRoot->mNext = mRoot->mChildren.end();
257 StackLog(<<
"XMLCursor::nextSibling" << *this->mCursor <<
" <<root>>");
261 StackLog(<<
"XMLCursor::nextSibling" << *this->mCursor <<
" " << *this->mCursor->
mParent);
262 if (mCursor->
mParent == mRoot.get())
264 parseNextRootChild();
270 mAttributesSet =
false;
283 mRoot->mChildren.empty())
285 parseNextRootChild();
298 mAttributesSet =
false;
312 mAttributesSet =
false;
319 mCursor = mRoot.get();
320 mAttributesSet =
false;
326 return mCursor == mRoot.get();
338 return mCursor->
mTag;
375 pb.
data(attribute, anchor);
376 XMLCursor::decodeName(attribute);
378 StackLog(<<
"attribute: " << attribute);
388 StackLog(<<
"quote is <" << quote <<
">");
393 InfoLog(<<
"XML: badly quoted attribute value");
394 pb.
fail(__FILE__, __LINE__);
398 pb.
data(value, anchor);
399 XMLCursor::decode(value);
403 InfoLog(<<
"XML: too many attributes on element " <<
getTag());
404 pb.
fail(__FILE__, __LINE__,
"Too many XML attributes");
406 mAttributes[attribute] = value;
411 mAttributesSet =
true;
425 XMLCursor::decode(mValue);
438 i != attrs.
end(); ++i)
440 if (i != attrs.
begin())
445 str << i->first <<
"=\"" << i->second <<
"\"";
452 : mPb(pb.position(), pb.end() - pb.position()),
455 mNext(mChildren.begin()),
459 StackLog(<<
"XMLCursor::Node::Node" << *
this);
464 for (vector<Node*>::iterator i = mChildren.begin();
465 i != mChildren.end(); ++i)
489 pb.
data(mTag, anchor);
497 mChildren.push_back(child);
522 InfoLog(<<
"XML: nesting too deep");
523 mPb.fail(__FILE__, __LINE__,
"XML nesting too deep");
527 StackLog(<<
"XMLCursor::Node::skipToEndTag(" << mTag <<
")");
532 if (*(mPb.position()-1) ==
SLASH[0])
535 mPb =
ParseBuffer(mPb.start(), mPb.position() - mPb.start());
548 mPb.skipWhitespace();
555 const char* anchor = mPb.position();
570 if (*mPb.position() ==
SLASH[0])
576 const char* end = mPb.position();
577 if ( (
const char*)mPb.end() < end + mTag.
size() )
579 InfoLog(<<
"XML: unexpected end");
580 mPb.fail(__FILE__, __LINE__);
583 if (strncmp(mTag.
data(), mPb.position(), mTag.
size()) == 0)
587 mPb =
ParseBuffer(mPb.start(), mPb.position() - mPb.start());
592 InfoLog(<<
"Badly formed XML: unexpected endtag");
593 mPb.fail(__FILE__, __LINE__);
599 if (mPb.position() == mPb.start())
601 InfoLog(<<
"XML: badly formed element");
602 mPb.fail(__FILE__, __LINE__);
605 mPb.reset(mPb.position()-1);
611 mPb.reset(child->
mPb.
end());
612 XMLCursor::decodeName(child->
mTag);
648 <<
"]" << (size ?
"" :
"...");
656 str <<
"XMLCursor " << *cursor.mCursor;
static char SINGLE_QUOTE[]
static const Data COMMENT_START("<!--")
static const Data RA_QUOTE_SLASH(">/")
static const Data COMMENT_END("-->")
static const Data QUESTION_RA_QUOTE("?>")
static char BANG[]
Whitespace handling: Are the following XML fragments equivalent?
static Data SLASH_RA_QUOTE("/>")
static char DOUBLE_QUOTE[]
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
size_type size() const noexcept
Returns the number of bytes in this Data.
Data & clear()
Clears the contents of this Data.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
void reserve(size_type capacity)
Guarantees that the underlying buffer used by the Data is at least the number of bytes specified.
size_type count(const Key &key) const
List::const_iterator const_iterator
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToEnd()
CurrentPosition skipWhitespace()
CurrentPosition skipToChars(const char *cs)
CurrentPosition skipToChar(char c)
CurrentPosition position() const
void reset(const char *pos)
CurrentPosition skipChars(const char *cs)
void assertNotEof() const
CurrentPosition skipToOneOf(const char *cs)
CurrentPosition skipN(size_t count)
CurrentPosition skipChar()
void fail(const char *file, unsigned int line, const Data &errmsg=Data::Empty) const
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
static const char * Whitespace
void skipToEndTag(unsigned int depth)
std::vector< Node * > mChildren
static const char * skipComments(ParseBuffer &pb)
std::vector< Node * >::const_iterator mNext
Node(const ParseBuffer &pb)
const Data & getValue() const
static constexpr size_t MaxAttributes
getAttributes() fails (ParseException) an element with more attributes than this
XMLCursor(const ParseBuffer &pb)
const Data & getTag() const
const AttributeMap & getAttributes() const
static EncodeStream & encode(EncodeStream &strm, const AttributeMap &attrs)
static constexpr unsigned int MaxNestingDepth
Parsing fails (ParseException) a document with elements nested more than this many levels below the r...
dcm! – add UnusedChecking(_enum) below;
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)