summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xml.c22
-rw-r--r--xml.h2
2 files changed, 13 insertions, 11 deletions
diff --git a/xml.c b/xml.c
index 8530916..f7691cb 100644
--- a/xml.c
+++ b/xml.c
@@ -16,21 +16,23 @@ struct xml_context_fd {
size_t offset;
};
-struct xml_context_string {
- const char *str;
+struct xml_context_buf {
+ const char *buf;
+ size_t len;
+ size_t offset;
};
static int
-xml_getnext_string(XMLParser *x)
+xml_getnext_buf(XMLParser *x)
{
- struct xml_context_string *d = (struct xml_context_string *)x->getnext_data;
+ struct xml_context_buf *d = (struct xml_context_buf *)x->getnext_data;
- if (!*(d->str))
+ if (d->offset >= d->len)
return EOF;
- return (int)*(d->str++);
+ return (int)d->buf[d->offset++];
}
-static int /* like getc(), but do some smart buffering */
+static int /* read from fd with some buffering */
xml_getnext_fd(XMLParser *x)
{
struct xml_context_fd *d = (struct xml_context_fd *)x->getnext_data;
@@ -491,11 +493,11 @@ xml_parse(XMLParser *x)
}
void
-xml_parse_string(XMLParser *x, const char *s)
+xml_parse_buf(XMLParser *x, const char *buf, size_t len)
{
- struct xml_context_string ctx = { .str = s };
+ struct xml_context_buf ctx = { .buf = buf, .len = len };
- x->getnext = xml_getnext_string;
+ x->getnext = xml_getnext_buf;
x->getnext_data = (void *)&ctx;
xml_parse(x);
}
diff --git a/xml.h b/xml.h
index df63e23..aa9c59d 100644
--- a/xml.h
+++ b/xml.h
@@ -43,5 +43,5 @@ ssize_t xml_namedentitytostr(const char *, char *, size_t);
ssize_t xml_numericetitytostr(const char *, char *, size_t);
void xml_parse(XMLParser *);
+void xml_parse_buf(XMLParser *, const char *, size_t);
void xml_parse_fd(XMLParser *, int);
-void xml_parse_string(XMLParser *, const char *);