diff options
Diffstat (limited to 'src/lib.c')
-rw-r--r-- | src/lib.c | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -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, """); break; + case '\'': + w += sprintf(o+w, "'"); + break; default: o[w++] = *i; break; |