1 #include "xml/croco-node-iface.h"
2 #include "xml/node.h"
3 #include <glib/gstrfuncs.h>
5 static char const *
6 local_part(char const *const qname)
7 {
8 char const *ret = std::strrchr(qname, ':');
9 if (ret)
10 return ++ret;
11 else
12 return qname;
13 }
15 namespace Inkscape {
16 namespace XML {
18 extern "C" {
20 static CRXMLNodePtr get_parent(CRXMLNodePtr n) { return static_cast<Node const *>(n)->parent(); }
21 static CRXMLNodePtr get_first_child(CRXMLNodePtr n) { return static_cast<Node const *>(n)->firstChild(); }
22 static CRXMLNodePtr get_next(CRXMLNodePtr n) { return static_cast<Node const *>(n)->next(); }
24 static CRXMLNodePtr get_prev(CRXMLNodePtr cn)
25 {
26 Node const *n = static_cast<Node const *>(cn);
27 unsigned const n_pos = n->position();
28 if (n_pos) {
29 return n->parent()->nthChild(n_pos - 1);
30 } else {
31 return NULL;
32 }
33 }
35 static char *get_attr(CRXMLNodePtr n, char const *a)
36 {
37 return g_strdup(static_cast<Node const *>(n)->attribute(a));
38 }
40 static char const *get_local_name(CRXMLNodePtr n) { return local_part(static_cast<Node const *>(n)->name()); }
41 static gboolean is_element_node(CRXMLNodePtr n) { return static_cast<Node const *>(n)->type() == ELEMENT_NODE; }
42 }
44 CRNodeIface const croco_node_iface = {
45 get_parent,
46 get_first_child,
47 get_next,
48 get_prev,
49 get_local_name,
50 get_attr,
51 g_free,
52 is_element_node
53 };
55 }
56 }
59 /*
60 Local Variables:
61 mode:c++
62 c-file-style:"stroustrup"
63 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
64 indent-tabs-mode:nil
65 fill-column:99
66 End:
67 */
68 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :