Skip to content

Commit c326701

Browse files
committed
fix(xml): fix XMLNode ctor and remove bogus XMLNode::Init function
1 parent 70c2316 commit c326701

4 files changed

Lines changed: 23 additions & 29 deletions

File tree

common/xml/XMLNode.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
#include "common/xml/XMLNode.hpp"
22
#include <storm/String.hpp>
33

4-
XMLNode::XMLNode() {
5-
// TODO
4+
XMLNode::XMLNode(XMLNode* parent, const char* name) {
5+
this->m_parent = parent;
6+
this->m_name.Copy(name);
7+
8+
if (this->m_parent && this->m_parent->m_body) {
9+
this->m_next = nullptr;
10+
this->m_userData = nullptr;
11+
this->m_offset = this->m_parent->m_bodyLen;
12+
} else {
13+
this->m_offset = 0;
14+
this->m_next = nullptr;
15+
this->m_userData = nullptr;
16+
}
617
}
718

819
XMLNode::~XMLNode() {
@@ -55,26 +66,6 @@ const XMLNode* XMLNode::GetSibling() const {
5566
return this->m_next;
5667
}
5768

58-
void XMLNode::Init(XMLNode* parent, const char* name) {
59-
RCString(this->m_name);
60-
TSGrowableArray<XMLAttribute>(this->m_attributes);
61-
this->m_parent = parent;
62-
this->m_child = nullptr;
63-
this->m_name.Copy(name);
64-
this->m_body = nullptr;
65-
this->m_bodyLen = 0;
66-
67-
if (this->m_parent && this->m_parent->m_body) {
68-
this->m_next = nullptr;
69-
this->m_userData = nullptr;
70-
this->m_offset = this->m_parent->m_bodyLen;
71-
} else {
72-
this->m_offset = 0;
73-
this->m_next = nullptr;
74-
this->m_userData = nullptr;
75-
}
76-
}
77-
7869
void XMLNode::SetAttribute(const char* name, const char* value) {
7970
auto attributeCount = this->m_attributes.Count();
8071

common/xml/XMLNode.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@ class XMLNode {
1111
// Member variables
1212
void* m_userData;
1313
XMLNode* m_parent;
14-
XMLNode* m_child;
14+
XMLNode* m_child = nullptr;
1515
RCString m_name;
16-
char* m_body;
17-
uint32_t m_bodyLen;
16+
char* m_body = nullptr;
17+
uint32_t m_bodyLen = 0;
1818
TSGrowableArray<XMLAttribute> m_attributes;
1919
uint32_t m_offset;
2020
XMLNode* m_next;
2121

2222
// Member functions
23-
XMLNode();
23+
XMLNode(XMLNode* parent, const char* name);
2424
~XMLNode();
2525
const char* GetAttributeByName(const char* name) const;
2626
const char* GetBody() const;
2727
const XMLNode* GetChild() const;
2828
const XMLNode* GetChildByName(const char* name) const;
2929
const char* GetName() const;
3030
const XMLNode* GetSibling() const;
31-
void Init(XMLNode* parent, const char* name);
3231
void SetAttribute(const char* name, const char* value);
3332
};
3433

common/xml/XMLTree.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ void begin_element(void* userData, const XML_Char* name, const XML_Char** atts)
1515
// TODO allocate node off of node heap
1616
// XMLNode* node = XMLNode::s_XMLNodeHeap->GetData(0, __FILE__, __LINE__);
1717

18-
node = new XMLNode;
19-
node->Init(tree->leaf, name);
18+
node = new XMLNode(tree->leaf, name);
2019
}
2120

2221
auto leaf = tree->leaf;

test/XML.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ TEST_CASE("XMLTree_Load", "[xml]") {
66
SECTION("loads new tree") {
77
auto xml = "<Root><Child1></Child1><Child2></Child2></Root>";
88
auto tree = XMLTree_Load(xml, SStrLen(xml));
9+
910
REQUIRE(tree);
11+
REQUIRE(tree->root);
12+
REQUIRE(!SStrCmpI(tree->root->GetName(), "Root"));
13+
REQUIRE(tree->root->GetChild());
14+
REQUIRE(!SStrCmpI(tree->root->GetChild()->GetName(), "Child1"));
1015
}
1116
}

0 commit comments

Comments
 (0)