16
16
17
17
#include " ../SwiftShims/UnicodeShims.h"
18
18
19
- #if !defined(__APPLE__)
20
- #include " swift/Basic/Lazy.h"
21
- #include " swift/Runtime/Config.h"
22
- #include " swift/Runtime/Debug.h"
19
+ #include < stdint.h>
23
20
24
- #include < algorithm>
25
- #include < mutex>
26
- #include < assert.h>
21
+ #if defined(__APPLE__)
22
+
23
+ // Declare a few external functions to avoid a dependency on ICU headers.
24
+ extern " C" {
25
+ typedef struct UBreakIterator UBreakIterator;
26
+ typedef enum UBreakIteratorType {} UBreakIteratorType;
27
+ typedef enum UErrorCode {} UErrorCode;
28
+ typedef uint16_t UChar;
29
+
30
+ void ubrk_close (UBreakIterator *);
31
+ UBreakIterator *ubrk_open (UBreakIteratorType, const char *, const UChar *,
32
+ int32_t , UErrorCode *);
33
+ int32_t ubrk_preceding (UBreakIterator *, int32_t );
34
+ int32_t ubrk_following (UBreakIterator *, int32_t );
35
+ void ubrk_setText (UBreakIterator *, const UChar *, int32_t , UErrorCode *);
36
+ }
37
+
38
+ #else
27
39
28
40
#pragma clang diagnostic push
29
41
#pragma clang diagnostic ignored "-Wdocumentation"
36
48
37
49
#pragma clang diagnostic pop
38
50
51
+ #endif
52
+
53
+ #if !defined(__APPLE__)
54
+ #include " swift/Basic/Lazy.h"
55
+ #include " swift/Runtime/Config.h"
56
+ #include " swift/Runtime/Debug.h"
57
+
58
+ #include < algorithm>
59
+ #include < mutex>
60
+ #include < assert.h>
39
61
40
62
static const UCollator *MakeRootCollator () {
41
63
UErrorCode ErrorCode = U_ZERO_ERROR;
@@ -88,11 +110,7 @@ class ASCIICollation {
88
110
for (unsigned char c = 0 ; c < 128 ; ++c) {
89
111
UErrorCode ErrorCode = U_ZERO_ERROR;
90
112
intptr_t NumCollationElts = 0 ;
91
- #if defined(__CYGWIN__) || defined( _MSC_VER) || defined(__linux__)
92
113
UChar Buffer[1 ];
93
- #else
94
- uint16_t Buffer[1 ];
95
- #endif
96
114
Buffer[0 ] = c;
97
115
98
116
UCollationElements *CollationIterator =
@@ -129,19 +147,13 @@ swift::_swift_stdlib_unicode_compare_utf16_utf16(const uint16_t *LeftString,
129
147
int32_t LeftLength,
130
148
const uint16_t *RightString,
131
149
int32_t RightLength) {
132
- #if defined(__CYGWIN__) || defined( _MSC_VER) || defined(__linux__)
133
150
// ICU UChar type is platform dependent. In Cygwin, it is defined
134
151
// as wchar_t which size is 2. It seems that the underlying binary
135
152
// representation is same with swift utf16 representation.
136
153
// On Clang 4.0 under a recent Linux, ICU uses the built-in char16_t type.
137
154
return ucol_strcoll (GetRootCollator (),
138
- reinterpret_cast <const UChar *>(LeftString), LeftLength,
139
- reinterpret_cast <const UChar *>(RightString), RightLength);
140
- #else
141
- return ucol_strcoll (GetRootCollator (),
142
- LeftString, LeftLength,
143
- RightString, RightLength);
144
- #endif
155
+ reinterpret_cast <const UChar *>(LeftString), LeftLength,
156
+ reinterpret_cast <const UChar *>(RightString), RightLength);
145
157
}
146
158
147
159
// / Compares the strings via the Unicode Collation Algorithm on the root locale.
@@ -159,12 +171,8 @@ swift::_swift_stdlib_unicode_compare_utf8_utf16(const unsigned char *LeftString,
159
171
UErrorCode ErrorCode = U_ZERO_ERROR;
160
172
161
173
uiter_setUTF8 (&LeftIterator, reinterpret_cast <const char *>(LeftString), LeftLength);
162
- #if defined(__CYGWIN__) || defined( _MSC_VER) || defined(__linux__)
163
174
uiter_setString (&RightIterator, reinterpret_cast <const UChar *>(RightString),
164
175
RightLength);
165
- #else
166
- uiter_setString (&RightIterator, RightString, RightLength);
167
- #endif
168
176
169
177
uint32_t Diff = ucol_strcollIter (GetRootCollator (),
170
178
&LeftIterator, &RightIterator, &ErrorCode);
@@ -202,14 +210,9 @@ swift::_swift_stdlib_unicode_compare_utf8_utf8(const unsigned char *LeftString,
202
210
void *swift::_swift_stdlib_unicodeCollationIterator_create (
203
211
const __swift_uint16_t *Str, __swift_uint32_t Length) {
204
212
UErrorCode ErrorCode = U_ZERO_ERROR;
205
- #if defined(__CYGWIN__) || defined( _MSC_VER) || defined(__linux__)
206
- UCollationElements *CollationIterator = ucol_openElements (
207
- GetRootCollator (), reinterpret_cast <const UChar *>(Str), Length,
208
- &ErrorCode);
209
- #else
210
- UCollationElements *CollationIterator = ucol_openElements (
211
- GetRootCollator (), Str, Length, &ErrorCode);
212
- #endif
213
+ UCollationElements *CollationIterator =
214
+ ucol_openElements (GetRootCollator (), reinterpret_cast <const UChar *>(Str),
215
+ Length, &ErrorCode);
213
216
if (U_FAILURE (ErrorCode)) {
214
217
swift::crash (" _swift_stdlib_unicodeCollationIterator_create: ucol_openElements() failed." );
215
218
}
@@ -247,17 +250,11 @@ swift::_swift_stdlib_unicode_strToUpper(uint16_t *Destination,
247
250
const uint16_t *Source,
248
251
int32_t SourceLength) {
249
252
UErrorCode ErrorCode = U_ZERO_ERROR;
250
- #if defined(__CYGWIN__) || defined( _MSC_VER) || defined(__linux__)
251
253
uint32_t OutputLength = u_strToUpper (reinterpret_cast <UChar *>(Destination),
252
254
DestinationCapacity,
253
255
reinterpret_cast <const UChar *>(Source),
254
256
SourceLength,
255
257
" " , &ErrorCode);
256
- #else
257
- uint32_t OutputLength = u_strToUpper (Destination, DestinationCapacity,
258
- Source, SourceLength,
259
- " " , &ErrorCode);
260
- #endif
261
258
if (U_FAILURE (ErrorCode) && ErrorCode != U_BUFFER_OVERFLOW_ERROR) {
262
259
swift::crash (" u_strToUpper: Unexpected error uppercasing unicode string." );
263
260
}
@@ -274,17 +271,11 @@ swift::_swift_stdlib_unicode_strToLower(uint16_t *Destination,
274
271
const uint16_t *Source,
275
272
int32_t SourceLength) {
276
273
UErrorCode ErrorCode = U_ZERO_ERROR;
277
- #if defined(__CYGWIN__) || defined( _MSC_VER) || defined(__linux__)
278
274
uint32_t OutputLength = u_strToLower (reinterpret_cast <UChar *>(Destination),
279
275
DestinationCapacity,
280
276
reinterpret_cast <const UChar *>(Source),
281
277
SourceLength,
282
278
" " , &ErrorCode);
283
- #else
284
- uint32_t OutputLength = u_strToLower (Destination, DestinationCapacity,
285
- Source, SourceLength,
286
- " " , &ErrorCode);
287
- #endif
288
279
if (U_FAILURE (ErrorCode) && ErrorCode != U_BUFFER_OVERFLOW_ERROR) {
289
280
swift::crash (" u_strToLower: Unexpected error lowercasing unicode string." );
290
281
}
@@ -303,28 +294,6 @@ template <typename T, typename U> const T *ptr_cast(const U *p) {
303
294
}
304
295
}
305
296
306
- #if defined(__APPLE__)
307
- #include < stdint.h>
308
- extern " C" {
309
- // Declare a few external functions to avoid a dependency on ICU headers.
310
- typedef struct UBreakIterator UBreakIterator;
311
- typedef enum UBreakIteratorType {} UBreakIteratorType;
312
- typedef enum UErrorCode {} UErrorCode;
313
- typedef uint16_t UChar;
314
-
315
- void ubrk_close (UBreakIterator *);
316
- UBreakIterator *ubrk_open (UBreakIteratorType, const char *, const UChar *,
317
- int32_t , UErrorCode *);
318
- int32_t ubrk_preceding (UBreakIterator *, int32_t );
319
- int32_t ubrk_following (UBreakIterator *, int32_t );
320
- void ubrk_setText (UBreakIterator *, const UChar *, int32_t , UErrorCode *);
321
- }
322
-
323
- // Force an autolink with ICU
324
- asm (" .linker_option \" -licucore\"\n " );
325
-
326
- #endif // defined(__APPLE__)
327
-
328
297
void swift::__swift_stdlib_ubrk_close (
329
298
swift::__swift_stdlib_UBreakIterator *bi) {
330
299
ubrk_close (ptr_cast<UBreakIterator>(bi));
@@ -333,16 +302,10 @@ void swift::__swift_stdlib_ubrk_close(
333
302
swift::__swift_stdlib_UBreakIterator *swift::__swift_stdlib_ubrk_open (
334
303
swift::__swift_stdlib_UBreakIteratorType type, const char *locale,
335
304
const uint16_t *text, int32_t textLength, __swift_stdlib_UErrorCode *status) {
336
- #if defined(__CYGWIN__) || defined( _MSC_VER) || defined(__linux__)
337
305
return ptr_cast<swift::__swift_stdlib_UBreakIterator>(
338
306
ubrk_open (static_cast <UBreakIteratorType>(type), locale,
339
307
reinterpret_cast <const UChar *>(text), textLength,
340
308
ptr_cast<UErrorCode>(status)));
341
- #else
342
- return ptr_cast<swift::__swift_stdlib_UBreakIterator>(
343
- ubrk_open (static_cast <UBreakIteratorType>(type), locale, text, textLength,
344
- ptr_cast<UErrorCode>(status)));
345
- #endif
346
309
}
347
310
348
311
int32_t
@@ -356,9 +319,18 @@ swift::__swift_stdlib_ubrk_following(swift::__swift_stdlib_UBreakIterator *bi,
356
319
int32_t offset) {
357
320
return ubrk_following (ptr_cast<UBreakIterator>(bi), offset);
358
321
}
322
+
359
323
void swift::__swift_stdlib_ubrk_setText (
360
324
swift::__swift_stdlib_UBreakIterator *bi, const __swift_stdlib_UChar *text,
361
325
__swift_int32_t textLength, __swift_stdlib_UErrorCode *status) {
362
326
return ubrk_setText (ptr_cast<UBreakIterator>(bi), ptr_cast<UChar>(text),
363
327
textLength, ptr_cast<UErrorCode>(status));
364
328
}
329
+
330
+ // Force an autolink with ICU
331
+ #if defined(__MACH__)
332
+ asm (" .linker_option \" -licucore\"\n " );
333
+ #elif defined(_WIN32)
334
+ #pragma comment(lib, "icucore.lib")
335
+ #endif // defined(__MACH__)
336
+
0 commit comments