Code

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