-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_node.cpp
More file actions
33 lines (31 loc) · 885 Bytes
/
Copy pathparse_node.cpp
File metadata and controls
33 lines (31 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "parse_node.h"
void ParseNode::Parse(std::stringstream& input) {
std::string buffer;
while (std::getline(input, buffer)) {
if ("" == buffer) { continue; }
size_t pos1 = buffer.find('(');
size_t pos2 = buffer.find(')');
if (pos1 != std::string::npos) {
std::string tmp = buffer.substr(0, pos1);
tmp = RemoveChar(' ', tmp);
ParseNode* children = new ParseNode(RemoveChar('\t', tmp));
if (std::string::npos == pos2) { //No ')' to find the next node to read
children->Parse(input);
}
else {
tmp = buffer.substr(pos1 + 1, pos2 - pos1 - 1);
children->context = RemoveChar('"', tmp);
}
childrens.push_back(children);
}
else {
return;
}
}
}
void ParseNode::PrintNode(int level) {
std::cout << std::string(level, '\t') << type << ":" << context << std::endl;
for (auto child : childrens) {
child->PrintNode(level + 1);
}
}