summaryrefslogtreecommitdiff
path: root/source/fitz/xml.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-24 11:48:24 +0100
committerTor Andersson <tor@ccxvii.net>2014-12-03 01:33:00 +0100
commitd8ea0243dddb28bcc802e230a8de8e66513a7dbb (patch)
tree5249a1ed4a88393ee32fe8dee3757358d3b80dbd /source/fitz/xml.c
parentfa04ab8e0c40cfc6b248c60e1ec9db028c97988a (diff)
downloadmupdf-d8ea0243dddb28bcc802e230a8de8e66513a7dbb.tar.xz
xml: Make accessors NULL-resistant. Add fz_xml_find functions.
Find the first sibling, next sibling or first child matching tag name.
Diffstat (limited to 'source/fitz/xml.c')
-rw-r--r--source/fitz/xml.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/source/fitz/xml.c b/source/fitz/xml.c
index 5cdaa673..0d370331 100644
--- a/source/fitz/xml.c
+++ b/source/fitz/xml.c
@@ -123,50 +123,77 @@ void fz_debug_xml(fz_xml *item, int level)
fz_xml *fz_xml_prev(fz_xml *item)
{
- return item->prev;
+ return item ? item->prev : NULL;
}
fz_xml *fz_xml_next(fz_xml *item)
{
- return item->next;
+ return item ? item->next : NULL;
}
fz_xml *fz_xml_up(fz_xml *item)
{
- return item->up;
+ return item ? item->up : NULL;
}
fz_xml *fz_xml_down(fz_xml *item)
{
- return item->down;
+ return item ? item->down : NULL;
}
char *fz_xml_text(fz_xml *item)
{
- return item->text;
+ return item ? item->text : NULL;
}
char *fz_xml_tag(fz_xml *item)
{
- if (item->name[0])
- return item->name;
- return NULL;
+ return item && item->name[0] ? item->name : NULL;
}
int fz_xml_is_tag(fz_xml *item, const char *name)
{
- return item->name && !strcmp(item->name, name);
+ if (!item)
+ return 0;
+ return !strcmp(item->name, name);
}
char *fz_xml_att(fz_xml *item, const char *name)
{
struct attribute *att;
+ if (!item)
+ return NULL;
for (att = item->atts; att; att = att->next)
if (!strcmp(att->name, name))
return att->value;
return NULL;
}
+fz_xml *fz_xml_find(fz_xml *item, const char *tag)
+{
+ while (item)
+ {
+ if (!strcmp(item->name, tag))
+ return item;
+ item = item->next;
+ }
+ return NULL;
+}
+
+fz_xml *fz_xml_find_next(fz_xml *item, const char *tag)
+{
+ if (item)
+ item = item->next;
+ return fz_xml_find(item, tag);
+}
+
+fz_xml *fz_xml_find_down(fz_xml *item, const char *tag)
+{
+ if (item)
+ item = item->down;
+ return fz_xml_find(item, tag);
+}
+
static void xml_free_attribute(fz_context *ctx, struct attribute *att)
{
while (att) {