From b43b7abf33f5b2ab480a85584df0e3ce8c76a8ca Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 10 Nov 2014 17:19:12 +0000 Subject: much less crazy imlementaion of xml reader git-svn-id: http://svn.miranda-ng.org/main/trunk@10945 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp | 54 +++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp') diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp index a44fa27812..5ca7bd7f0e 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp @@ -8,6 +8,8 @@ #include "WAException.h" #include "ProtocolTreeNode.h" +static std::string nilstr; + ProtocolTreeNode::ProtocolTreeNode(const string& tag, map *attributes, vector* data, vector *children) { this->tag = tag; this->data = data; @@ -46,13 +48,10 @@ string ProtocolTreeNode::toString() { out += "" + ii->first + "=\"" + ii->second + "\""; } out += ">\n"; - std::string* data = getDataAsString(); - out += (this->data != NULL? *data:""); - delete data; + out += getDataAsString(); if (this->children != NULL) { vector::iterator ii; - for (ii = children->begin(); ii != children->end(); ii++) out += (*ii)->toString(); } @@ -83,51 +82,52 @@ ProtocolTreeNode* ProtocolTreeNode::getChild(size_t id) { return NULL; } -string* ProtocolTreeNode::getAttributeValue(const string& attribute) { +const string& ProtocolTreeNode::getAttributeValue(const string& attribute) +{ if (this->attributes == NULL) - return NULL; + return nilstr; map::iterator it = attributes->find(attribute); if (it == attributes->end()) - return NULL; + return nilstr; - return &it->second; + return it->second; } -vector* ProtocolTreeNode::getAllChildren() { - vector* ret = new vector(); - +vector ProtocolTreeNode::getAllChildren() +{ if (this->children == NULL) - return ret; + return vector(); - return this->children; + return *this->children; } -std::string* ProtocolTreeNode::getDataAsString() { +std::string ProtocolTreeNode::getDataAsString() +{ if (this->data == NULL) - return NULL; - return new std::string(this->data->begin(), this->data->end()); + return nilstr; + return std::string(this->data->begin(), this->data->end()); } -vector* ProtocolTreeNode::getAllChildren(const string& tag) { - vector* ret = new vector(); - - if (this->children == NULL) - return ret; +vector ProtocolTreeNode::getAllChildren(const string &tag) +{ + vector ret; - for (size_t i = 0; i < this->children->size(); i++) - if (tag.compare((*children)[i]->tag) == 0) - ret->push_back((*children)[i]); + if (this->children != NULL) + for (size_t i = 0; i < this->children->size(); i++) + if (tag.compare((*children)[i]->tag) == 0) + ret.push_back((*children)[i]); return ret; } - -bool ProtocolTreeNode::tagEquals(ProtocolTreeNode *node, const string& tag) { +bool ProtocolTreeNode::tagEquals(ProtocolTreeNode *node, const string& tag) +{ return (node != NULL && node->tag.compare(tag) == 0); } -void ProtocolTreeNode::require(ProtocolTreeNode *node, const string& tag) { +void ProtocolTreeNode::require(ProtocolTreeNode *node, const string& tag) +{ if (!tagEquals(node, tag)) throw WAException("failed require. node:" + node->toString() + "tag: " + tag, WAException::CORRUPT_STREAM_EX, 0); } -- cgit v1.2.3