[string] Add UText shims; NFC

Add ICU shims for creating UTexts and performing grapheme breaking
using UTexts. This will allow us to explore multi-encoding grapheme
support throughout string.
This commit is contained in:
Michael Ilseman
2018-07-07 15:12:40 -07:00
parent ac09eaa8c7
commit 5358401d35
2 changed files with 48 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ extern "C" {
// Types
typedef struct UBreakIterator UBreakIterator;
typedef struct UText UText;
typedef struct UBreakIterator UNormalizer2;
typedef enum UBreakIteratorType {} UBreakIteratorType;
typedef enum UErrorCode {} UErrorCode;
@@ -40,6 +41,10 @@ UBreakIterator *ubrk_open(UBreakIteratorType, const char *, const UChar *,
int32_t ubrk_preceding(UBreakIterator *, int32_t);
int32_t ubrk_following(UBreakIterator *, int32_t);
void ubrk_setText(UBreakIterator *, const UChar *, int32_t, UErrorCode *);
void ubrk_setUText(UBreakIterator *, UText *, UErrorCode *);
UText *utext_openUTF8(UText *, const char *, int64_t, UErrorCode *);
UText *utext_openUChars(UText *, const UChar *, int64_t, UErrorCode *);
// Comparison, normalization, and character property APIs
int32_t unorm2_spanQuickCheckYes(const UNormalizer2 *, const UChar *, int32_t,
@@ -164,6 +169,32 @@ void swift::__swift_stdlib_ubrk_setText(
textLength, ptr_cast<UErrorCode>(status));
}
void swift::__swift_stdlib_ubrk_setUText(
swift::__swift_stdlib_UBreakIterator *bi, __swift_stdlib_UText *text,
__swift_stdlib_UErrorCode *status) {
return ubrk_setUText(ptr_cast<UBreakIterator>(bi), ptr_cast<UText>(text),
ptr_cast<UErrorCode>(status));
}
SWIFT_RUNTIME_STDLIB_INTERFACE swift::__swift_stdlib_UText *
swift::__swift_stdlib_utext_openUTF8(__swift_stdlib_UText *ut,
const char *s, int64_t len,
__swift_stdlib_UErrorCode *status) {
return ptr_cast<__swift_stdlib_UText>(
utext_openUTF8(ptr_cast<UText>(ut), s, len,
ptr_cast<UErrorCode>(status)));
}
SWIFT_RUNTIME_STDLIB_INTERFACE swift::__swift_stdlib_UText *
swift::__swift_stdlib_utext_openUChars(__swift_stdlib_UText *ut,
const __swift_stdlib_UChar *s,
int64_t len,
__swift_stdlib_UErrorCode *status) {
return ptr_cast<__swift_stdlib_UText>(
utext_openUChars(ptr_cast<UText>(ut), ptr_cast<UChar>(s), len,
ptr_cast<UErrorCode>(status)));
}
swift::__swift_stdlib_UBool swift::__swift_stdlib_unorm2_hasBoundaryBefore(
const __swift_stdlib_UNormalizer2 *ptr, __swift_stdlib_UChar32 char32) {
return unorm2_hasBoundaryBefore(ptr_cast<UNormalizer2>(ptr), char32);