Flutter Engine
The Flutter Engine
SkUnicode_icu_builtin.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "include/private/base/SkFeatures.h" // IWYU pragma: keep
9
10#include <memory>
11#include <type_traits>
12#include <utility>
13
14#include <unicode/ubrk.h>
15#include <unicode/uloc.h>
16#include <unicode/utypes.h>
17
18namespace {
19
20// ubrk_clone added as draft in ICU69 and Android API 31 (first ICU NDK).
21// ubrk_safeClone deprecated in ICU69 and not exposed by Android.
22template<typename T, typename = void>
23struct SkUbrkClone {
24 static UBreakIterator* clone(T bi, UErrorCode* status) {
25 return ubrk_safeClone(bi, nullptr, nullptr, status);
26 }
27};
28template<typename T>
29struct SkUbrkClone<T, std::void_t<decltype(ubrk_clone(std::declval<T>(), nullptr))>> {
30 static UBreakIterator* clone(T bi, UErrorCode* status) {
31 return ubrk_clone(bi, status);
32 }
33};
34
35// ubrk_getLocaleByType has been in ICU since version 2.8
36// However, it was not included in the Android NDK
37template<typename T, typename = void>
38struct SkUbrkGetLocaleByType {
39 static const char* getLocaleByType(T bi, ULocDataLocaleType type, UErrorCode* status) {
40 *status = U_UNSUPPORTED_ERROR;
41 return nullptr;
42 }
43};
44template<typename T>
45struct SkUbrkGetLocaleByType<
46 T,
47 std::void_t<decltype(ubrk_getLocaleByType(std::declval<T>(),
48 std::declval<ULocDataLocaleType>(),
49 nullptr))>>
50{
51 static const char* getLocaleByType(T bi, ULocDataLocaleType type, UErrorCode* status) {
52 return ubrk_getLocaleByType(bi, type, status);
53 }
54};
55
56} // namespace
57
58#define SKICU_FUNC(funcname) funcname,
59std::unique_ptr<SkICULib> SkLoadICULib() {
60 return std::make_unique<SkICULib>(SkICULib{
62 &SkUbrkClone<const UBreakIterator*>::clone,
63 nullptr,
64 &SkUbrkGetLocaleByType<const UBreakIterator*>::getLocaleByType,
65 });
66}
67
std::unique_ptr< SkICULib > SkLoadICULib()
#define SKICU_EMIT_FUNCS
GLenum type
Definition: ref_ptr.h:256
#define T
Definition: precompiler.cc:65
void void_t
Definition: main.cc:65