on master help sign in
Expose more details of node, meaning no need for accessor functions
c1824fbNeil Mitchell
cbits/hexml.c−12
@@ -34,16 +34,6 @@ typedef struct
34 attr* alloc; // what to call free on
34 attr* alloc; // what to call free on
35} attr_buffer;
35} attr_buffer;
36
36
37−
38−struct node
39−{
40− str name; // tag name, e.g. <[foo]>
41− str outer; // outer text, [<foo>bar</foo>]
42− str inner; // inner text, <foo>[bar]</foo>
43− str attrs; // all the attributes, in the attribute buffer
44− str nodes; // all the nodes, in the node buffer
45−};
46−
47typedef struct
37typedef struct
48{
38{
49 // have a cursor at the front, which is all the stuff I have written out, final
39 // have a cursor at the front, which is all the stuff I have written out, final
@@ -178,8 +168,6 @@ int document_render(document* d, char* buffer, int length)
178
168
179char* document_error(document* d){return d->error_message;}
169char* document_error(document* d){return d->error_message;}
180node* document_node(document* d){return &d->nodes.nodes[0];}
170node* document_node(document* d){return &d->nodes.nodes[0];}
181−str node_inner(node* n){return n->inner;}
182−str node_outer(node* n){return n->outer;}
183
171
184void document_free(document* d)
172void document_free(document* d)
185{
173{
cbits/hexml.h+9−5
@@ -2,7 +2,6 @@
2#include <stdint.h>
2#include <stdint.h>
3
3
4typedef struct document document;
4typedef struct document document;
5−typedef struct node node;
6
5
7// Pair of indexes into the input string
6// Pair of indexes into the input string
8typedef struct
7typedef struct
@@ -17,6 +16,15 @@ typedef struct
17 str value;
16 str value;
18} attr;
17} attr;
19
18
19+typedef struct
20+{
21+ str name; // tag name, e.g. <[foo]>
22+ str inner; // inner text, <foo>[bar]</foo>
23+ str outer; // outer text, [<foo>bar</foo>]
24+ str attrs; // all the attributes, in the attribute buffer (not usable)
25+ str nodes; // all the nodes, in the node buffer (not usable)
26+} node;
27+
20// Convention: if slen can be -1 for nul-terminated, or given explicitly
28// Convention: if slen can be -1 for nul-terminated, or given explicitly
21
29
22// Parse a document, returns a potentially invalid document - use document_error to check
30// Parse a document, returns a potentially invalid document - use document_error to check
@@ -36,10 +44,6 @@ char* document_error(document* d);
36// return the root node of the document - imagine the document is wrapped in <>$DOC</> tags
44// return the root node of the document - imagine the document is wrapped in <>$DOC</> tags
37node* document_node(document* d);
45node* document_node(document* d);
38
46
39−// Get the span of a node
40−str node_inner(node* n);
41−str node_outer(node* n);
42−
43// List all items within a node
47// List all items within a node
44node* node_children(document* d, node* n, int* res);
48node* node_children(document* d, node* n, int* res);
45attr* node_attributes(document* d, node* n, int* res);
49attr* node_attributes(document* d, node* n, int* res);