summaryrefslogtreecommitdiffstats
path: root/src/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.c')
-rw-r--r--src/lib.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/lib.c b/src/lib.c
index 2377ec9..62ddf84 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -46,18 +46,23 @@ void eachNodeX (htmlDocPtr doc, const char * xpath, node_function_t f, void * da
eachNode(nodes, f, data);
xmlXPathFreeObject(nodes);
}
-xmlNodePtr nthNodeXN (xmlNodePtr node, const char * xpath, int n) {
- xmlXPathObjectPtr nodes = findNodesN(node, xpath);
- if (!nodes)
- return NULL;
- xmlNodeSetPtr nodeset = nodes->nodesetval;
- int size = nodeset->nodeNr;
- if (size <= n)
- return NULL;
- xmlNodePtr toreturn = (xmlNodePtr) nodeset->nodeTab[n];
- xmlXPathFreeObject(nodes);
- return toreturn;
+#define nthNodeFunctionGenerator(type, x) \
+xmlNodePtr nthNodeX##x (type node, const char * xpath, int n) { \
+ xmlXPathObjectPtr nodes = findNodes##x(node, xpath); \
+ if (!nodes) \
+ return NULL; \
+ xmlNodeSetPtr nodeset = nodes->nodesetval; \
+ int size = nodeset->nodeNr; \
+ if (size <= n) { \
+ xmlXPathFreeObject(nodes); \
+ return NULL; \
+ } \
+ xmlNodePtr toreturn = (xmlNodePtr) nodeset->nodeTab[n]; \
+ xmlXPathFreeObject(nodes); \
+ return toreturn; \
}
+nthNodeFunctionGenerator(htmlDocPtr,) // this one gets doc
+nthNodeFunctionGenerator(xmlNodePtr, N)
#define EACHNODE(node, nodes) /* you can instead use eachNodeX with anonymous function - no need to free and findnodes separatl */ \
for (int EACHNODE_i = 0; \
nodes ? nodes->nodesetval ? \
@@ -110,6 +115,9 @@ char * htmlspecialchars (const char * i) { /* remember to free the output */
case '"':
w += sprintf(o+w, "&quot;");
break;
+ case '\'':
+ w += sprintf(o+w, "&apos;");
+ break;
default:
o[w++] = *i;
break;