-
Notifications
You must be signed in to change notification settings - Fork 6
/
c_bridge.h
61 lines (53 loc) · 2.62 KB
/
c_bridge.h
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
#ifndef __C_BRIDGE_H__
#define __C_BRIDGE_H__
// C_BRIDGE is a bridge between go and native pure c functions used to
// operate with ICU library code.
#include <unicode/utypes.h>
#include <unicode/ucsdet.h>
// MatchData contains information about one 'guess' of the
// encoding detector. It contains the guessed charset (ICU string identifiers,
// see ICU documentation for them) and a confidence coefficient, which is a
// number between 0 and 100 (100 is the best).
typedef struct MatchData {
const char* charset;
const char* language;
short int confidence;
} MatchData;
// detectCharset performs the detection (guessing) operation using a given detector (ICU internals),
// input data (bytes), input length and error status pointer (Read ICU docs abour error codes).
//
// After the detection is performed, all possible matches are put into the matchBuffer. If there are
// more results than matchBufferSize, then only matchBufferSize entries are put (So no overflow can
// ever happen).
//
// The results of this function are put into the matchBuffer, so it MUST NOT be called asynchronously.
// Caller should guarantee thread safety and perform locks while working with it.
const int detectCharset(void *detector,
void *input,
int input_len,
int *status,
MatchData *matchBuffer,
int matchBufferSize);
// convertToUtf16 performs conversion from any encoding to utf16. Utf16 is the ICU standard so
// it is easier to convert to/from it.
//
// The results of this function are put into the dest buffer, so it MUST NOT be called asynchronously.
// Caller should guarantee thread safety and perform locks while working with it.
int convertToUtf16(const char *srcEncoding,
UChar *dest,
int32_t destCapacity,
const char *src,
int32_t srcLength,
int *status);
// convertFromUtf16 performs conversion from utf16 to any other encoding. Utf16 is the ICU standard so
// it is easier to convert to/from it.
//
// The results of this function are put into the dest buffer, so it MUST NOT be called asynchronously.
// Caller should guarantee thread safety and perform locks while working with it.
int convertFromUtf16(const char *destEncoding,
char *dest,
int32_t destCapacity,
const UChar *src,
int32_t srcLength,
int *status);
#endif //__C_BRIDGE_H__