-
Notifications
You must be signed in to change notification settings - Fork 11
/
xml_encoding.go
55 lines (48 loc) · 2.11 KB
/
xml_encoding.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
package golibxml
/*
#cgo pkg-config: libxml-2.0
#include <libxml/parser.h>
static inline void free_string(char* s) { free(s); }
static inline xmlChar *to_xmlcharptr(const char *s) { return (xmlChar *)s; }
static inline char *to_charptr(const xmlChar *s) { return (char *)s; }
*/
import "C"
import "unsafe"
////////////////////////////////////////////////////////////////////////////////
// TYPES/STRUCTS
////////////////////////////////////////////////////////////////////////////////
type Encoding int
const (
XML_CHAR_ENCODING_ERROR Encoding = -1 //: No char encoding detected
XML_CHAR_ENCODING_NONE = 0 //: No char encoding detected
XML_CHAR_ENCODING_UTF8 = 1 //: UTF-8
XML_CHAR_ENCODING_UTF16LE = 2 //: UTF-16 little endian
XML_CHAR_ENCODING_UTF16BE = 3 //: UTF-16 big endian
XML_CHAR_ENCODING_UCS4LE = 4 //: UCS-4 little endian
XML_CHAR_ENCODING_UCS4BE = 5 //: UCS-4 big endian
XML_CHAR_ENCODING_EBCDIC = 6 //: EBCDIC uh!
XML_CHAR_ENCODING_UCS4_2143 = 7 //: UCS-4 unusual ordering
XML_CHAR_ENCODING_UCS4_3412 = 8 //: UCS-4 unusual ordering
XML_CHAR_ENCODING_UCS2 = 9 //: UCS-2
XML_CHAR_ENCODING_8859_1 = 10 //: ISO-8859-1 ISO Latin 1
XML_CHAR_ENCODING_8859_2 = 11 //: ISO-8859-2 ISO Latin 2
XML_CHAR_ENCODING_8859_3 = 12 //: ISO-8859-3
XML_CHAR_ENCODING_8859_4 = 13 //: ISO-8859-4
XML_CHAR_ENCODING_8859_5 = 14 //: ISO-8859-5
XML_CHAR_ENCODING_8859_6 = 15 //: ISO-8859-6
XML_CHAR_ENCODING_8859_7 = 16 //: ISO-8859-7
XML_CHAR_ENCODING_8859_8 = 17 //: ISO-8859-8
XML_CHAR_ENCODING_8859_9 = 18 //: ISO-8859-9
XML_CHAR_ENCODING_2022_JP = 19 //: ISO-2022-JP
XML_CHAR_ENCODING_SHIFT_JIS = 20 //: Shift_JIS
XML_CHAR_ENCODING_EUC_JP = 21 //: EUC-JP
XML_CHAR_ENCODING_ASCII = 22 //: pure ASCII
)
////////////////////////////////////////////////////////////////////////////////
// INTERFACE
////////////////////////////////////////////////////////////////////////////////
// xmlDetectCharEncoding
func DetectCharEncoding(buffer[] byte) Encoding {
ptr := (*C.uchar)(unsafe.Pointer(&buffer[0]))
return Encoding(C.xmlDetectCharEncoding(ptr, C.int(len(buffer))))
}