@@ -10,7 +10,7 @@ typedef int bool;
10/////////////////////////////////////////////////////////////////////
10/////////////////////////////////////////////////////////////////////
13−int static inline end(str s){return s.start + s.length;}
13+int static inline end(str s) { return s.start + s.length; }
15str static inline start_length(int32_t start, int32_t length)
15str static inline start_length(int32_t start, int32_t length)
@@ -193,6 +193,7 @@ attr* node_attributes(document* d, node* n, int* res)
193attr* node_attributeBy(document* d, node* n, char* s, int slen)
193attr* node_attributeBy(document* d, node* n, char* s, int slen)
195 assert(0);
195 assert(0);
198// Search for given strings within a node
199// Search for given strings within a node
@@ -213,6 +214,7 @@ node* node_firstChildBy(document* d, node* n, char* s, int slen)
213node* node_nextChildBy(document* d, node* parent, node* prev, char* s, int slen)
214node* node_nextChildBy(document* d, node* parent, node* prev, char* s, int slen)
215 assert(0);
216 assert(0);
@@ -299,7 +301,6 @@ str parse_name(document* d)
299str parse_attrval(document* d)
301str parse_attrval(document* d)
303 if (peek(d) != '=') return start_length(0,0);
304 if (peek(d) != '=') return start_length(0,0);
305 return parse_name(d);
306 return parse_name(d);
@@ -323,13 +324,14 @@ str parse_content(document* d);
323// Add a new entry into tag, am at a '<'
324// Add a new entry into tag, am at a '<'
324void parse_tag(document* d)
325void parse_tag(document* d)
329 node_alloc(&d->nodes, 1);
327 node_alloc(&d->nodes, 1);
330− int me = d->nodes.used_back;
331 d->nodes.used_back++;
328 d->nodes.used_back++;
329+ int me = d->nodes.size - d->nodes.used_back;
334+ d->nodes.nodes[me].outer.start = d->cursor;
333 d->nodes.nodes[me].name = parse_name(d);
335 d->nodes.nodes[me].name = parse_name(d);
334 d->nodes.nodes[me].attrs = parse_attributes(d);
336 d->nodes.nodes[me].attrs = parse_attributes(d);
@@ -338,9 +340,13 @@ void parse_tag(document* d)
339 skip(d, 2);
341 skip(d, 2);
340 d->nodes.nodes[me].nodes = start_length(0, 0);
342 d->nodes.nodes[me].nodes = start_length(0, 0);
343+ d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, d->cursor).length;
344+ d->nodes.nodes[me].inner = start_length(d->cursor, 0);
347+ d->nodes.nodes[me].inner.start = d->cursor;
343 d->nodes.nodes[me].nodes = parse_content(d);
348 d->nodes.nodes[me].nodes = parse_content(d);
349+ d->nodes.nodes[me].inner.length = start_end(d->nodes.nodes[me].inner.start, d->cursor).length;
345 if (d->error_message != NULL) return;
351 if (d->error_message != NULL) return;
346 if (peek(d) == '<' && peekAt(d, 1) == '/')
352 if (peek(d) == '<' && peekAt(d, 1) == '/')
@@ -350,13 +356,14 @@ void parse_tag(document* d)
350 lexeme("openning tag", d, d->nodes.nodes[me].name);
356 lexeme("openning tag", d, d->nodes.nodes[me].name);
351 lexeme("closing tag", d, close);
357 lexeme("closing tag", d, close);
359+ d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, d->cursor).length;
353 if (close.length == d->nodes.nodes[me].name.length &&
360 if (close.length == d->nodes.nodes[me].name.length &&
354 memcmp(&d->body[close.start], &d->body[d->nodes.nodes[me].name.start], close.length) == 0)
361 memcmp(&d->body[close.start], &d->body[d->nodes.nodes[me].name.start], close.length) == 0)
356− d->error_message = strdup("Mismatch in closing tags");
363+ d->error_message = _strdup("Mismatch in closing tags");
359− d->error_message = strdup("Weirdness when trying to close tags");
366+ d->error_message = _strdup("Weirdness when trying to close tags");
362// Parser until </, return the index of your node children
369// Parser until </, return the index of your node children
@@ -427,7 +434,7 @@ document* document_parse(char* s, int slen)
427 if (d->cursor < d->length && d->error_message == NULL)
434 if (d->cursor < d->length && d->error_message == NULL)
429 printf("%i vs %i\n", d->cursor, d->length);
436 printf("%i vs %i\n", d->cursor, d->length);
430− d->error_message = strdup("Trailing junk at the end of the document");
437+ d->error_message = _strdup("Trailing junk at the end of the document");
432 return d;
439 return d;