From bd82d030011cd8b9655e5ded6b6df9343b42a6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 4 Feb 2015 14:09:54 +0100 Subject: Imported Upstream version 3.22 --- include/libHX/libxml_helper.h | 113 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 include/libHX/libxml_helper.h (limited to 'include/libHX/libxml_helper.h') diff --git a/include/libHX/libxml_helper.h b/include/libHX/libxml_helper.h new file mode 100644 index 0000000..599ede1 --- /dev/null +++ b/include/libHX/libxml_helper.h @@ -0,0 +1,113 @@ +#ifndef _LIBHX_LIBXML_HELPER_H +#define _LIBHX_LIBXML_HELPER_H 1 + +#ifdef __cplusplus +# include +#else +# include +#endif +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static __inline__ int xml_strcmp(const xmlChar *a, const char *b) +{ +#ifdef __cplusplus + return strcmp(signed_cast(a), b); +#else + return strcmp(signed_cast(const char *, a), b); +#endif +} + +static __inline__ int xml_strcasecmp(const xmlChar *a, const char *b) +{ +#ifdef __cplusplus + return strcasecmp(signed_cast(a), b); +#else + return strcasecmp(signed_cast(const char *, a), b); +#endif +} + +static __inline__ char *xml_getprop(xmlNode *node, const char *attr) +{ +#ifdef __cplusplus + return signed_cast(xmlGetProp(node, + signed_cast(attr))); +#else + return signed_cast(char *, xmlGetProp(node, + signed_cast(const xmlChar *, attr))); +#endif +} + +/** + * xmlGetNsProp takes, as 3rd argument, a full namespace string. + * That is unwieldy. + */ +static __inline__ char *xml_getnsprop(xmlNode *node, const char *nsprefix, + const char *key) +{ + const struct _xmlAttr *attr = NULL; + for (attr = node->properties; attr != NULL; attr = attr->next) + if (attr->ns != NULL && attr->ns->prefix != NULL && + xml_strcmp(attr->ns->prefix, nsprefix) == 0) + break; + if (attr == NULL) + return NULL; +#ifdef __cplusplus + return signed_cast(xmlGetNsProp(node, + signed_cast(key), attr->ns->href)); +#else + return signed_cast(char *, xmlGetNsProp(node, + signed_cast(const xmlChar *, key), attr->ns->href)); +#endif +} + +static __inline__ xmlAttr * +xml_newprop(xmlNode *node, const char *name, const char *value) +{ +#ifdef __cplusplus + return xmlNewProp(node, signed_cast(name), + signed_cast(value)); +#else + return xmlNewProp(node, signed_cast(const xmlChar *, name), + signed_cast(const xmlChar *, value)); +#endif +} + +/** + * @ptr: parent node + * @name: name of new node + * @value: string, or %NULL + */ +static __inline__ xmlNode * +xml_newnode(xmlNode *ptr, const char *name, const char *value) +{ +#ifdef __cplusplus + return xmlNewTextChild(ptr, NULL, signed_cast(name), + signed_cast(value)); +#else + return xmlNewTextChild(ptr, NULL, signed_cast(const xmlChar *, name), + signed_cast(const xmlChar *, value)); +#endif +} + +static __inline__ xmlAttr * +xml_setprop(xmlNode *node, const char *name, const char *value) +{ +#ifdef __cplusplus + return xmlSetProp(node, signed_cast(name), + signed_cast(value)); +#else + return xmlSetProp(node, signed_cast(const xmlChar *, name), + signed_cast(const xmlChar *, value)); +#endif +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _LIBHX_LIBXML_HELPER_H */ -- cgit v1.2.3