1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//
5
6// Enable calling ICU functions through shims to enable support for
7// multiple versions of ICU.
8
9#ifndef __ICUSHIM_H__
10#define __ICUSHIM_H__
11
12#include "config.h"
13
14#define U_DISABLE_RENAMING 1
15
16// All ICU headers need to be included here so that all function prototypes are
17// available before the function pointers are declared below.
18#include <unicode/locid.h>
19#include <unicode/ucurr.h>
20#include <unicode/ucal.h>
21#include <unicode/uchar.h>
22#include <unicode/ucol.h>
23#include <unicode/udat.h>
24#include <unicode/udatpg.h>
25#include <unicode/uenum.h>
26#include <unicode/uidna.h>
27#include <unicode/uldnames.h>
28#include <unicode/ulocdata.h>
29#include <unicode/unorm2.h>
30#include <unicode/unum.h>
31#include <unicode/ures.h>
32#include <unicode/usearch.h>
33#include <unicode/utf16.h>
34#include <unicode/utypes.h>
35#include <unicode/urename.h>
36#include <unicode/ustring.h>
37
38// List of all functions from the ICU libraries that are used in the System.Globalization.Native.so
39#define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \
40 PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc) \
41 PER_FUNCTION_BLOCK(u_getVersion, libicuuc) \
42 PER_FUNCTION_BLOCK(u_strlen, libicuuc) \
43 PER_FUNCTION_BLOCK(u_strncpy, libicuuc) \
44 PER_FUNCTION_BLOCK(u_tolower, libicuuc) \
45 PER_FUNCTION_BLOCK(u_toupper, libicuuc) \
46 PER_FUNCTION_BLOCK(ucal_add, libicui18n) \
47 PER_FUNCTION_BLOCK(ucal_close, libicui18n) \
48 PER_FUNCTION_BLOCK(ucal_get, libicui18n) \
49 PER_FUNCTION_BLOCK(ucal_getAttribute, libicui18n) \
50 PER_FUNCTION_BLOCK(ucal_getKeywordValuesForLocale, libicui18n) \
51 PER_FUNCTION_BLOCK(ucal_getLimit, libicui18n) \
52 PER_FUNCTION_BLOCK(ucal_getTimeZoneDisplayName, libicui18n) \
53 PER_FUNCTION_BLOCK(ucal_open, libicui18n) \
54 PER_FUNCTION_BLOCK(ucal_set, libicui18n) \
55 PER_FUNCTION_BLOCK(ucol_close, libicui18n) \
56 PER_FUNCTION_BLOCK(ucol_closeElements, libicui18n) \
57 PER_FUNCTION_BLOCK(ucol_getRules, libicui18n) \
58 PER_FUNCTION_BLOCK(ucol_getSortKey, libicui18n) \
59 PER_FUNCTION_BLOCK(ucol_getStrength, libicui18n) \
60 PER_FUNCTION_BLOCK(ucol_getVersion, libicui18n) \
61 PER_FUNCTION_BLOCK(ucol_next, libicui18n) \
62 PER_FUNCTION_BLOCK(ucol_open, libicui18n) \
63 PER_FUNCTION_BLOCK(ucol_openElements, libicui18n) \
64 PER_FUNCTION_BLOCK(ucol_openRules, libicui18n) \
65 PER_FUNCTION_BLOCK(ucol_safeClone, libicui18n) \
66 PER_FUNCTION_BLOCK(ucol_setAttribute, libicui18n) \
67 PER_FUNCTION_BLOCK(ucol_strcoll, libicui18n) \
68 PER_FUNCTION_BLOCK(ucurr_forLocale, libicui18n) \
69 PER_FUNCTION_BLOCK(ucurr_getName, libicui18n) \
70 PER_FUNCTION_BLOCK(udat_close, libicui18n) \
71 PER_FUNCTION_BLOCK(udat_countSymbols, libicui18n) \
72 PER_FUNCTION_BLOCK(udat_getSymbols, libicui18n) \
73 PER_FUNCTION_BLOCK(udat_open, libicui18n) \
74 PER_FUNCTION_BLOCK(udat_setCalendar, libicui18n) \
75 PER_FUNCTION_BLOCK(udat_toPattern, libicui18n) \
76 PER_FUNCTION_BLOCK(udatpg_close, libicui18n) \
77 PER_FUNCTION_BLOCK(udatpg_getBestPattern, libicui18n) \
78 PER_FUNCTION_BLOCK(udatpg_open, libicui18n) \
79 PER_FUNCTION_BLOCK(uenum_close, libicuuc) \
80 PER_FUNCTION_BLOCK(uenum_count, libicuuc) \
81 PER_FUNCTION_BLOCK(uenum_next, libicuuc) \
82 PER_FUNCTION_BLOCK(uidna_close, libicuuc) \
83 PER_FUNCTION_BLOCK(uidna_nameToASCII, libicuuc) \
84 PER_FUNCTION_BLOCK(uidna_nameToUnicode, libicuuc) \
85 PER_FUNCTION_BLOCK(uidna_openUTS46, libicuuc) \
86 PER_FUNCTION_BLOCK(uldn_close, libicui18n) \
87 PER_FUNCTION_BLOCK(uldn_keyValueDisplayName, libicui18n) \
88 PER_FUNCTION_BLOCK(uldn_open, libicui18n) \
89 PER_FUNCTION_BLOCK(uloc_canonicalize, libicuuc) \
90 PER_FUNCTION_BLOCK(uloc_countAvailable, libicuuc) \
91 PER_FUNCTION_BLOCK(uloc_getAvailable, libicuuc) \
92 PER_FUNCTION_BLOCK(uloc_getBaseName, libicuuc) \
93 PER_FUNCTION_BLOCK(uloc_getCharacterOrientation, libicuuc) \
94 PER_FUNCTION_BLOCK(uloc_getCountry, libicuuc) \
95 PER_FUNCTION_BLOCK(uloc_getDefault, libicuuc) \
96 PER_FUNCTION_BLOCK(uloc_getDisplayCountry, libicuuc) \
97 PER_FUNCTION_BLOCK(uloc_getDisplayLanguage, libicuuc) \
98 PER_FUNCTION_BLOCK(uloc_getDisplayName, libicuuc) \
99 PER_FUNCTION_BLOCK(uloc_getISO3Country, libicuuc) \
100 PER_FUNCTION_BLOCK(uloc_getISO3Language, libicuuc) \
101 PER_FUNCTION_BLOCK(uloc_getKeywordValue, libicuuc) \
102 PER_FUNCTION_BLOCK(uloc_getLanguage, libicuuc) \
103 PER_FUNCTION_BLOCK(uloc_getLCID, libicuuc) \
104 PER_FUNCTION_BLOCK(uloc_getName, libicuuc) \
105 PER_FUNCTION_BLOCK(uloc_getParent, libicuuc) \
106 PER_FUNCTION_BLOCK(uloc_setKeywordValue, libicuuc) \
107 PER_FUNCTION_BLOCK(ulocdata_getMeasurementSystem, libicui18n) \
108 PER_FUNCTION_BLOCK(unorm2_getNFCInstance, libicuuc) \
109 PER_FUNCTION_BLOCK(unorm2_getNFDInstance, libicuuc) \
110 PER_FUNCTION_BLOCK(unorm2_getNFKCInstance, libicuuc) \
111 PER_FUNCTION_BLOCK(unorm2_getNFKDInstance, libicuuc) \
112 PER_FUNCTION_BLOCK(unorm2_isNormalized, libicuuc) \
113 PER_FUNCTION_BLOCK(unorm2_normalize, libicuuc) \
114 PER_FUNCTION_BLOCK(unum_close, libicui18n) \
115 PER_FUNCTION_BLOCK(unum_getAttribute, libicui18n) \
116 PER_FUNCTION_BLOCK(unum_getSymbol, libicui18n) \
117 PER_FUNCTION_BLOCK(unum_open, libicui18n) \
118 PER_FUNCTION_BLOCK(unum_toPattern, libicui18n) \
119 PER_FUNCTION_BLOCK(ures_close, libicuuc) \
120 PER_FUNCTION_BLOCK(ures_getByKey, libicuuc) \
121 PER_FUNCTION_BLOCK(ures_getSize, libicuuc) \
122 PER_FUNCTION_BLOCK(ures_getStringByIndex, libicuuc) \
123 PER_FUNCTION_BLOCK(ures_open, libicuuc) \
124 PER_FUNCTION_BLOCK(usearch_close, libicui18n) \
125 PER_FUNCTION_BLOCK(usearch_first, libicui18n) \
126 PER_FUNCTION_BLOCK(usearch_getMatchedLength, libicui18n) \
127 PER_FUNCTION_BLOCK(usearch_last, libicui18n) \
128 PER_FUNCTION_BLOCK(usearch_openFromCollator, libicui18n)
129
130#if HAVE_SET_MAX_VARIABLE
131#define FOR_ALL_ICU_FUNCTIONS \
132 FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \
133 PER_FUNCTION_BLOCK(ucol_setMaxVariable, libicui18n)
134#else
135#define FOR_ALL_ICU_FUNCTIONS \
136 FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \
137 PER_FUNCTION_BLOCK(ucol_setVariableTop, libicui18n)
138#endif
139
140// Declare pointers to all the used ICU functions
141#define PER_FUNCTION_BLOCK(fn, lib) extern decltype(fn)* fn##_ptr;
142FOR_ALL_ICU_FUNCTIONS
143#undef PER_FUNCTION_BLOCK
144
145// Redefine all calls to ICU functions as calls through pointers that are set
146// to the functions of the selected version of ICU in the initialization.
147#define u_charsToUChars(...) u_charsToUChars_ptr(__VA_ARGS__)
148#define u_getVersion(...) u_getVersion_ptr(__VA_ARGS__)
149#define u_strlen(...) u_strlen_ptr(__VA_ARGS__)
150#define u_strncpy(...) u_strncpy_ptr(__VA_ARGS__)
151#define u_tolower(...) u_tolower_ptr(__VA_ARGS__)
152#define u_toupper(...) u_toupper_ptr(__VA_ARGS__)
153#define ucal_add(...) ucal_add_ptr(__VA_ARGS__)
154#define ucal_close(...) ucal_close_ptr(__VA_ARGS__)
155#define ucal_get(...) ucal_get_ptr(__VA_ARGS__)
156#define ucal_getAttribute(...) ucal_getAttribute_ptr(__VA_ARGS__)
157#define ucal_getKeywordValuesForLocale(...) ucal_getKeywordValuesForLocale_ptr(__VA_ARGS__)
158#define ucal_getLimit(...) ucal_getLimit_ptr(__VA_ARGS__)
159#define ucal_getTimeZoneDisplayName(...) ucal_getTimeZoneDisplayName_ptr(__VA_ARGS__)
160#define ucal_open(...) ucal_open_ptr(__VA_ARGS__)
161#define ucal_set(...) ucal_set_ptr(__VA_ARGS__)
162#define ucol_close(...) ucol_close_ptr(__VA_ARGS__)
163#define ucol_closeElements(...) ucol_closeElements_ptr(__VA_ARGS__)
164#define ucol_getRules(...) ucol_getRules_ptr(__VA_ARGS__)
165#define ucol_getSortKey(...) ucol_getSortKey_ptr(__VA_ARGS__)
166#define ucol_getStrength(...) ucol_getStrength_ptr(__VA_ARGS__)
167#define ucol_getVersion(...) ucol_getVersion_ptr(__VA_ARGS__)
168#define ucol_next(...) ucol_next_ptr(__VA_ARGS__)
169#define ucol_open(...) ucol_open_ptr(__VA_ARGS__)
170#define ucol_openElements(...) ucol_openElements_ptr(__VA_ARGS__)
171#define ucol_openRules(...) ucol_openRules_ptr(__VA_ARGS__)
172#define ucol_safeClone(...) ucol_safeClone_ptr(__VA_ARGS__)
173#define ucol_setAttribute(...) ucol_setAttribute_ptr(__VA_ARGS__)
174#if HAVE_SET_MAX_VARIABLE
175#define ucol_setMaxVariable(...) ucol_setMaxVariable_ptr(__VA_ARGS__)
176#else
177#define ucol_setVariableTop(...) ucol_setVariableTop_ptr(__VA_ARGS__)
178#endif
179#define ucol_strcoll(...) ucol_strcoll_ptr(__VA_ARGS__)
180#define ucurr_forLocale(...) ucurr_forLocale_ptr(__VA_ARGS__)
181#define ucurr_getName(...) ucurr_getName_ptr(__VA_ARGS__)
182#define udat_close(...) udat_close_ptr(__VA_ARGS__)
183#define udat_countSymbols(...) udat_countSymbols_ptr(__VA_ARGS__)
184#define udat_getSymbols(...) udat_getSymbols_ptr(__VA_ARGS__)
185#define udat_open(...) udat_open_ptr(__VA_ARGS__)
186#define udat_setCalendar(...) udat_setCalendar_ptr(__VA_ARGS__)
187#define udat_toPattern(...) udat_toPattern_ptr(__VA_ARGS__)
188#define udatpg_close(...) udatpg_close_ptr(__VA_ARGS__)
189#define udatpg_getBestPattern(...) udatpg_getBestPattern_ptr(__VA_ARGS__)
190#define udatpg_open(...) udatpg_open_ptr(__VA_ARGS__)
191#define uenum_close(...) uenum_close_ptr(__VA_ARGS__)
192#define uenum_count(...) uenum_count_ptr(__VA_ARGS__)
193#define uenum_next(...) uenum_next_ptr(__VA_ARGS__)
194#define uidna_close(...) uidna_close_ptr(__VA_ARGS__)
195#define uidna_nameToASCII(...) uidna_nameToASCII_ptr(__VA_ARGS__)
196#define uidna_nameToUnicode(...) uidna_nameToUnicode_ptr(__VA_ARGS__)
197#define uidna_openUTS46(...) uidna_openUTS46_ptr(__VA_ARGS__)
198#define uldn_close(...) uldn_close_ptr(__VA_ARGS__)
199#define uldn_keyValueDisplayName(...) uldn_keyValueDisplayName_ptr(__VA_ARGS__)
200#define uldn_open(...) uldn_open_ptr(__VA_ARGS__)
201#define uloc_canonicalize(...) uloc_canonicalize_ptr(__VA_ARGS__)
202#define uloc_countAvailable(...) uloc_countAvailable_ptr(__VA_ARGS__)
203#define uloc_getAvailable(...) uloc_getAvailable_ptr(__VA_ARGS__)
204#define uloc_getBaseName(...) uloc_getBaseName_ptr(__VA_ARGS__)
205#define uloc_getCharacterOrientation(...) uloc_getCharacterOrientation_ptr(__VA_ARGS__)
206#define uloc_getCountry(...) uloc_getCountry_ptr(__VA_ARGS__)
207#define uloc_getDefault(...) uloc_getDefault_ptr(__VA_ARGS__)
208#define uloc_getDisplayCountry(...) uloc_getDisplayCountry_ptr(__VA_ARGS__)
209#define uloc_getDisplayLanguage(...) uloc_getDisplayLanguage_ptr(__VA_ARGS__)
210#define uloc_getDisplayName(...) uloc_getDisplayName_ptr(__VA_ARGS__)
211#define uloc_getISO3Country(...) uloc_getISO3Country_ptr(__VA_ARGS__)
212#define uloc_getISO3Language(...) uloc_getISO3Language_ptr(__VA_ARGS__)
213#define uloc_getKeywordValue(...) uloc_getKeywordValue_ptr(__VA_ARGS__)
214#define uloc_getLanguage(...) uloc_getLanguage_ptr(__VA_ARGS__)
215#define uloc_getLCID(...) uloc_getLCID_ptr(__VA_ARGS__)
216#define uloc_getName(...) uloc_getName_ptr(__VA_ARGS__)
217#define uloc_getParent(...) uloc_getParent_ptr(__VA_ARGS__)
218#define uloc_setKeywordValue(...) uloc_setKeywordValue_ptr(__VA_ARGS__)
219#define ulocdata_getMeasurementSystem(...) ulocdata_getMeasurementSystem_ptr(__VA_ARGS__)
220#define unorm2_getNFCInstance(...) unorm2_getNFCInstance_ptr(__VA_ARGS__)
221#define unorm2_getNFDInstance(...) unorm2_getNFDInstance_ptr(__VA_ARGS__)
222#define unorm2_getNFKCInstance(...) unorm2_getNFKCInstance_ptr(__VA_ARGS__)
223#define unorm2_getNFKDInstance(...) unorm2_getNFKDInstance_ptr(__VA_ARGS__)
224#define unorm2_isNormalized(...) unorm2_isNormalized_ptr(__VA_ARGS__)
225#define unorm2_normalize(...) unorm2_normalize_ptr(__VA_ARGS__)
226#define unum_close(...) unum_close_ptr(__VA_ARGS__)
227#define unum_getAttribute(...) unum_getAttribute_ptr(__VA_ARGS__)
228#define unum_getSymbol(...) unum_getSymbol_ptr(__VA_ARGS__)
229#define unum_open(...) unum_open_ptr(__VA_ARGS__)
230#define unum_toPattern(...) unum_toPattern_ptr(__VA_ARGS__)
231#define ures_close(...) ures_close_ptr(__VA_ARGS__)
232#define ures_getByKey(...) ures_getByKey_ptr(__VA_ARGS__)
233#define ures_getSize(...) ures_getSize_ptr(__VA_ARGS__)
234#define ures_getStringByIndex(...) ures_getStringByIndex_ptr(__VA_ARGS__)
235#define ures_open(...) ures_open_ptr(__VA_ARGS__)
236#define usearch_close(...) usearch_close_ptr(__VA_ARGS__)
237#define usearch_first(...) usearch_first_ptr(__VA_ARGS__)
238#define usearch_getMatchedLength(...) usearch_getMatchedLength_ptr(__VA_ARGS__)
239#define usearch_last(...) usearch_last_ptr(__VA_ARGS__)
240#define usearch_openFromCollator(...) usearch_openFromCollator_ptr(__VA_ARGS__)
241
242#endif // __ICUSHIM_H__
243