bindings.c

 1// This file is a stupid wrapper to avoid the automated suffixing libicu is
 2// doing in unicode/urename.h.
 3//
 4// By default it will suffix each of its symbols with "_65" (with 65 being the
 5// soname), which completely messes with Rust’s binding ability.
 6
 7#include <unicode/umachine.h>
 8#include <unicode/utypes.h>
 9#include <unicode/usprep.h>
10#include <unicode/utrace.h>
11#include <unicode/uidna.h>
12#include <unicode/uspoof.h>
13#include <unicode/ustring.h>
14#include <string.h>
15
16const char* icu_error_code_to_name(UErrorCode code) {
17	return u_errorName(code);
18}
19
20UIDNA* icu_idna_open(uint32_t options, UErrorCode* pErrorCode) {
21	return uidna_openUTS46(options, pErrorCode);
22}
23
24int32_t icu_idna_name_to_ascii(const UIDNA* idna, const char* name, int32_t length, char* dest, int32_t capacity, UIDNAInfo* pInfo, UErrorCode* pErrorCode) {
25	return uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode);
26}
27
28int32_t icu_idna_name_to_unicode(const UIDNA* idna, const char* name, int32_t length, char* dest, int32_t capacity, UIDNAInfo* pInfo, UErrorCode* pErrorCode) {
29	return uidna_nameToUnicodeUTF8(idna, name, length, dest, capacity, pInfo, pErrorCode);
30}
31
32UStringPrepProfile* icu_stringprep_open(UStringPrepProfileType type, UErrorCode* status) {
33	return usprep_openByType(type, status);
34}
35
36int32_t icu_stringprep_prepare(const UStringPrepProfile* prep, const UChar* src, int32_t srcLength, UChar* dest, int32_t destCapacity, int32_t options, UParseError* parseError, UErrorCode* status) {
37	return usprep_prepare(prep, src, srcLength, dest, destCapacity, options, parseError, status);
38}
39
40void icu_trace_set_level(UTraceLevel traceLevel) {
41	utrace_setLevel(traceLevel);
42}
43
44USpoofChecker* icu_spoof_open(UErrorCode* status) {
45	return uspoof_open(status);
46}
47
48void icu_spoof_set_checks(USpoofChecker* sc, int32_t checks, UErrorCode* status) {
49	uspoof_setChecks(sc, checks, status);
50}
51
52int32_t icu_spoof_get_skeleton(USpoofChecker* sc, uint32_t type, const char* id, int32_t length, char* dest, int32_t destCapacity, UErrorCode* status) {
53	return uspoof_getSkeletonUTF8(sc, type, id, length, dest, destCapacity, status);
54}