-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcfuncs.go
63 lines (53 loc) · 1.65 KB
/
cfuncs.go
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
// gosax: Go wrapper for libxml SAX.
//
// C helpers for internal use.
//
// Eli Bendersky [https://eli.thegreenplace.net]
// This code is in the public domain.
package gosax
/*
#cgo pkg-config: libxml-2.0
#include <libxml/tree.h>
#include <libxml/parser.h>
extern void goStartDocument(void*);
extern void goEndDocument(void*);
extern void goStartElement(void*, const xmlChar*, const xmlChar**, int);
extern void goStartElementNoAttr(void*, const xmlChar*);
extern void goEndElement(void*, const xmlChar*);
extern void goCharacters(void*, const xmlChar*, int);
extern void goCharactersRaw(void*, const xmlChar*, int);
void startDocumentCgo(void* user_data) {
goStartDocument(user_data);
}
void endDocumentCgo(void* user_data) {
goEndDocument(user_data);
}
void startElementCgo(void* user_data,
const xmlChar* name,
const xmlChar** attrs) {
// The attrs array is terminated with a NULL pointer. To make it usable in
// Go, we find the length and pass it explicitly to the Go callback.
int i = 0;
if (attrs != NULL) {
while (attrs[i] != NULL) {
i++;
}
}
goStartElement(user_data, name, attrs, i);
}
void startElementNoAttrCgo(void* user_data,
const xmlChar* name,
const xmlChar** attrs) {
goStartElementNoAttr(user_data, name);
}
void endElementCgo(void* user_data, const xmlChar* name) {
goEndElement(user_data, name);
}
void charactersCgo(void* user_data, const xmlChar* ch, int len) {
goCharacters(user_data, ch, len);
}
void charactersRawCgo(void* user_data, const xmlChar* ch, int len) {
goCharactersRaw(user_data, ch, len);
}
*/
import "C"