spectrum2/include/Swiften/Parser/PayloadParsers/XHTMLIMParser.cpp
Vladimir Matena 6d2f8c1927 Switch from boost shared pointers to stl shared pointers (#162)
* Swiften 4 support
* using standard shared pointers when compiling with Swiften 4
2016-09-12 19:20:58 +03:00

59 lines
1.5 KiB
C++

/*
* Copyright (c) 2011 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <cassert>
#include <Swiften/Parser/PayloadParsers/XHTMLIMParser.h>
#include <Swiften/Parser/SerializingParser.h>
#include "Swiften/SwiftenCompat.h"
namespace Swift {
XHTMLIMParser::XHTMLIMParser() : level_(TopLevel), bodyParser_(0) {
}
void XHTMLIMParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
++level_;
if (level_ == BodyLevel) {
if (element == "body") {
assert(!bodyParser_);
bodyParser_ = new SerializingParser();
}
}
else if (level_ >= InsideBodyLevel && bodyParser_) {
bodyParser_->handleStartElement(element, "", attributes);
}
}
void XHTMLIMParser::handleEndElement(const std::string& element, const std::string& ns) {
if (level_ == BodyLevel) {
if (bodyParser_) {
if (element == "body") {
getPayloadInternal()->setBody(bodyParser_->getResult());
}
delete bodyParser_;
bodyParser_ = 0;
}
}
else if (bodyParser_ && level_ >= InsideBodyLevel) {
bodyParser_->handleEndElement(element, ns);
}
--level_;
}
void XHTMLIMParser::handleCharacterData(const std::string& data) {
if (bodyParser_) {
bodyParser_->handleCharacterData(data);
}
else {
currentText_ += data;
}
}
SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<XHTMLIMPayload> XHTMLIMParser::getLabelPayload() const {
return getPayloadInternal();
}
}