@@ -3,11 +3,8 @@
3#include <stdlib.h>
3#include <stdlib.h>
4#include <string.h>
4#include <string.h>
5#include <assert.h>
5#include <assert.h>
7#include <stdio.h>
6#include <stdio.h>
11/////////////////////////////////////////////////////////////////////
8/////////////////////////////////////////////////////////////////////
@@ -53,20 +50,13 @@ typedef struct
53struct document
50struct document
55 const char* body; // pointer to initial argument, not owned by us
52 const char* body; // pointer to initial argument, not owned by us
56−
53+ int body_len; // length of the body
57− // things only used while parsing
58− const char* cursor; // pointer to where we are in body
59− const char* end; // pointer to one past the last char
60− // if cursor is > end we have gone past the end
62 char* error_message;
55 char* error_message;
63 node_buffer nodes;
56 node_buffer nodes;
64 attr_buffer attrs;
57 attr_buffer attrs;
67−static inline int doc_length(const document* d) { return (int) (d->end - d->body); }
68−static inline int doc_position(const document* d) { return (int) (d->cursor - d->body); }
71/////////////////////////////////////////////////////////////////////
61/////////////////////////////////////////////////////////////////////
72// RENDER CODE
62// RENDER CODE
@@ -100,7 +90,7 @@ static inline void bound_str(str s, int mn, int mx)
101static void render_str(render* r, str s)
91static void render_str(render* r, str s)
103− bound_str(s, 0, doc_length(r->d));
93+ bound_str(s, 0, r->d->body_len);
104 for (int i = 0; i < s.length; i++)
94 for (int i = 0; i < s.length; i++)
105 render_char(r, r->d->body[s.start + i]);
95 render_char(r, r->d->body[s.start + i]);
@@ -109,7 +99,7 @@ static void render_tag(render* r, const node* n);
110static void render_content(render* r, const node* n)
100static void render_content(render* r, const node* n)
112− bound_str(n->inner, 0, doc_length(r->d));
102+ bound_str(n->inner, 0, r->d->body_len);
113 bound_str(n->nodes, 0, r->d->nodes.used_front);
103 bound_str(n->nodes, 0, r->d->nodes.used_front);
114 bound_str(n->attrs, 0, r->d->attrs.used);
104 bound_str(n->attrs, 0, r->d->attrs.used);
@@ -308,8 +298,7 @@ document* hexml_document_parse(const char* s, int slen)
308 assert(buf);
298 assert(buf);
309 document* d = &buf->document;
299 document* d = &buf->document;
310 d->body = s;
300 d->body = s;
311− d->cursor = s;
301+ d->body_len = slen;
313 d->error_message = NULL;
302 d->error_message = NULL;
314 d->attrs.size = 1000;
303 d->attrs.size = 1000;
315 d->attrs.used = 0;
304 d->attrs.used = 0;