on master help sign in
57 lines 2.1 kB history raw
2#include <stdint.h>
4typedef struct document document;
6// Pair of indexes into the input string
7typedef struct
8{
9 int32_t start;
10 int32_t length;
11} str;
13typedef struct
15 str name;
16 str value;
17} attr;
19typedef struct
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 // Not usable, but required to get the correct sizing when returning arrays of nodes
25 str attrs; // all the attributes, in the attribute buffer (not usable)
26 str nodes; // all the nodes, in the node buffer (not usable)
27} node;
29// Convention: if slen can be -1 for nul-terminated, or given explicitly
31// Parse a document, returns a potentially invalid document - use document_error to check
32// Must use document_free to release the memory (even if invalid).
33// The string must be nul terminated, e.g. slen != -1 ==> slen[0]
34document* hexml_document_parse(const char* s, int slen);
36// Free the memory returned from document_parse.
37void hexml_document_free(document* d);
39// Generate a fresh string with the same semantics as the node.
40// Requires an input buffer, returns the size of the rendered document.
41// Requires the string passed to document_parse to be valid.
42int hexml_node_render(const document* d, const node* n, char* buffer, int length);
44// Return either NULL (successful parse) or the error message.
45char* hexml_document_error(const document* d);
47// Return the root node of the document - imagine the document is wrapped in <>$DOC</> tags.
48node* hexml_document_node(const document* d);
50// List all items within a node
51node* hexml_node_children(const document* d, const node* n, int* res);
52attr* hexml_node_attributes(const document* d, const node* n, int* res);
54// Search for given strings within a node, note that prev may be NULL
55// Requires the string passed to document_parse to be valid.
56node* hexml_node_child(const document* d, const node* parent, const node* prev, const char* s, int slen);
57attr* hexml_node_attribute(const document* d, const node* n, const char* s, int slen);