summaryrefslogtreecommitdiff
path: root/imxml.h
diff options
context:
space:
mode:
Diffstat (limited to 'imxml.h')
-rw-r--r--imxml.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/imxml.h b/imxml.h
index 7ed0563..9540b4c 100644
--- a/imxml.h
+++ b/imxml.h
@@ -76,15 +76,15 @@ int main (void) {
// but it doesn't cost much and might catch some dumb bugs
if (!xml_parse_header(&p, NULL)) goto err;
if (!xml_tag_expect(&p, "osm")) goto err;
- if (!xml_has_children(&p)) goto err;
+ if (!xml_has_children(p)) goto err;
if (!xml_tag_expect(&p, "bounds")) goto err;
- if (xml_has_children(&p)) goto err;
+ if (xml_has_children(p)) goto err;
size_t highway_crossing_count = 0;
while (true) {
ImxmlString tag = xml_tag(&p);
if (imxml_streql(tag, imxml_strlit("node"))) {
- if (xml_has_children(&p)) {
+ if (xml_has_children(p)) {
while (true) {
tag = xml_tag(&p);
if (imxml_streql(tag, imxml_strlit("/node"))) break;
@@ -582,7 +582,12 @@ IMXMLAPI ImxmlString xml_attr (XmlParser* p);
* call xml_attribute first. */
IMXMLAPI ImxmlString xml_value (XmlParser* p);
-IMXMLAPI bool xml_has_children (XmlParser* p);
+/* Returns true if inside tag that has children (not self-closing).
+ * Does not modify parser state. */
+IMXMLAPI bool xml_has_children (XmlParser p);
+/* Same as xml_has_children,
+ * but also advances the parser head and manages namespaces */
+IMXMLAPI bool xml_has_children_no_rewind (XmlParser* p);
IMXMLAPI ImxmlString xml_skip_element (XmlParser* p);
typedef ImxmlString (*ImxmlEntityGetFunc)(ImxmlString key);
@@ -1443,7 +1448,7 @@ IMXMLAPI ImxmlString xml_value (XmlParser* const p) {
return res;
}
-IMXMLAPI bool xml_has_children (XmlParser* const p) {
+IMXMLAPI bool xml_has_children_no_rewind (XmlParser* const p) {
bool has_children;
if (!p->in_tag) return false;
if (!imxml_seek_gt_(p)) return false;
@@ -1457,6 +1462,14 @@ IMXMLAPI bool xml_has_children (XmlParser* const p) {
return has_children;
}
+IMXMLAPI bool xml_has_children (XmlParser p) {
+ bool has_children;
+ if (!p.in_tag) return false;
+ if (!imxml_seek_next_char_dense(&p, '>')) return false;
+ has_children = imxml_previous_char_(&p) != '/';
+ return has_children;
+}
+
IMXMLAPI ImxmlString xml_skip_element (XmlParser* const p) {
ImxmlString res = {0};
size_t depth = 0;
@@ -1485,7 +1498,7 @@ IMXMLAPI ImxmlString xml_skip_element (XmlParser* const p) {
depth -= 1;
continue;
}
- if (xml_has_children(p)) {
+ if (xml_has_children_no_rewind(p)) {
depth += 1;
}
}