diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-01-05 16:44:26 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-01-05 16:44:26 +0100 |
commit | dd08d816dca127808b2343005ec8a728b6cb2a2a (patch) | |
tree | c9b0bd578e38ddb42570471adff4e3f117177a20 /src/lib.c | |
parent | 0.0.25 (diff) | |
download | sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.gz sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.bz2 sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.lz sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.xz sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.zst sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.zip |
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; |