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