From abed48e2d05078919839af2254db9137724b9fb4 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sun, 2 Jun 2019 15:58:04 -0500 Subject: [PATCH] Don't use a magic depth number for attributes. --- bml.cpp | 6 ++++-- bml.h | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bml.cpp b/bml.cpp index 9bfe8002..2d0ac122 100644 --- a/bml.cpp +++ b/bml.cpp @@ -7,6 +7,7 @@ bml_node::bml_node() { + type = CHILD; depth = -1; } @@ -181,7 +182,8 @@ static void bml_parse_attr(bml_node &node, char **data) n.name = trim(std::string(p, len)); p += len; 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); } @@ -218,7 +220,7 @@ static void bml_print_node(bml_node &node, int depth) else 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()) { diff --git a/bml.h b/bml.h index d1dd5c3d..48407728 100644 --- a/bml.h +++ b/bml.h @@ -3,21 +3,24 @@ #include #include -const int bml_attr_type = -2; - struct bml_node { + enum node_type { + CHILD, + ATTRIBUTE + }; + bml_node(); bool parse_file(const char *filename); void parse(char *buffer); bml_node *find_subnode(std::string name); void print(); - static const int bml_attr_type = -2; std::string name; std::string data; int depth; std::vector child; + node_type type; }; #endif