1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#ifndef _LIBHX_LIBXML_HELPER_H
#define _LIBHX_LIBXML_HELPER_H 1
#ifdef __cplusplus
# include <cstring>
#else
# include <string.h>
#endif
#include <libHX/defs.h>
#include <libxml/parser.h>
#ifdef __cplusplus
extern "C" {
#endif
static __inline__ int xml_strcmp(const xmlChar *a, const char *b)
{
#ifdef __cplusplus
return strcmp(signed_cast<const char *>(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<const char *>(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<char *>(xmlGetProp(node,
signed_cast<const xmlChar *>(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<char *>(xmlGetNsProp(node,
signed_cast<const xmlChar *>(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<const xmlChar *>(name),
signed_cast<const xmlChar *>(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<const xmlChar *>(name),
signed_cast<const xmlChar *>(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<const xmlChar *>(name),
signed_cast<const xmlChar *>(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 */
|