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
8 #include "modules/skunicode/src/SkUnicode_icu.h"
9
10 #include <memory>
11 #include <unicode/ubrk.h>
12 #include <unicode/utypes.h>
13 #include <utility>
14
15 #define SKICU_FUNC(funcname) funcname,
16
17 // ubrk_clone added as draft in ICU69 and Android API 31 (first ICU NDK).
18 // ubrk_safeClone deprecated in ICU69 and not exposed by Android.
19 template<typename...> using void_t = void;
20 template<typename T, typename = void>
21 struct SkUbrkClone {
cloneSkUbrkClone22 static UBreakIterator* clone(T bi, UErrorCode* status) {
23 return ubrk_safeClone(bi, nullptr, nullptr, status);
24 }
25 };
26 template<typename T>
27 struct SkUbrkClone<T, void_t<decltype(ubrk_clone(std::declval<T>(), nullptr))>> {
cloneSkUbrkClone28 static UBreakIterator* clone(T bi, UErrorCode* status) {
29 return ubrk_clone(bi, status);
30 }
31 };
32
SkLoadICULib()33 std::unique_ptr<SkICULib> SkLoadICULib() {
34
35 return std::make_unique<SkICULib>(SkICULib{
36 SKICU_EMIT_FUNCS
37
38 &SkUbrkClone<const UBreakIterator*>::clone,
39 nullptr,
40 });
41 }
42