Don't use a magic depth number for attributes.

This commit is contained in:
Brandon Wright 2019-06-02 15:58:04 -05:00
parent cb7602263f
commit abed48e2d0
2 changed files with 10 additions and 5 deletions

View File

@ -7,6 +7,7 @@
bml_node::bml_node() bml_node::bml_node()
{ {
type = CHILD;
depth = -1; depth = -1;
} }
@ -181,7 +182,8 @@ static void bml_parse_attr(bml_node &node, char **data)
n.name = trim(std::string(p, len)); n.name = trim(std::string(p, len));
p += len; p += len;
bml_parse_data(n, &p); bml_parse_data(n, &p);
n.depth = bml_attr_type; n.depth = node.depth + 1;
n.type = bml_node::CHILD;
node.child.push_back(n); node.child.push_back(n);
} }
@ -218,7 +220,7 @@ static void bml_print_node(bml_node &node, int depth)
else else
printf (": %s", node.data.c_str()); printf (": %s", node.data.c_str());
} }
for (i = 0; i < (int) node.child.size () && node.child[i].depth == bml_attr_type; i++) for (i = 0; i < (int) node.child.size () && node.child[i].type == bml_node::CHILD; i++)
{ {
if (!node.child[i].name.empty()) if (!node.child[i].name.empty())
{ {

9
bml.h
View File

@ -3,21 +3,24 @@
#include <vector> #include <vector>
#include <string> #include <string>
const int bml_attr_type = -2;
struct bml_node struct bml_node
{ {
enum node_type {
CHILD,
ATTRIBUTE
};
bml_node(); bml_node();
bool parse_file(const char *filename); bool parse_file(const char *filename);
void parse(char *buffer); void parse(char *buffer);
bml_node *find_subnode(std::string name); bml_node *find_subnode(std::string name);
void print(); void print();
static const int bml_attr_type = -2;
std::string name; std::string name;
std::string data; std::string data;
int depth; int depth;
std::vector<bml_node> child; std::vector<bml_node> child;
node_type type;
}; };
#endif #endif