Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
word_boundaries.cpp
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
7#include <memory>
8
9#if defined(SK_UNICODE_ICU_IMPLEMENTATION)
11#endif
12
13#if defined(SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION)
15#endif
16
17#if defined(SK_UNICODE_ICU4X_IMPLEMENTATION)
19#endif
20
21namespace {
23#if defined(SK_UNICODE_ICU_IMPLEMENTATION)
24 if (auto unicode = SkUnicodes::ICU::Make()) {
25 return unicode;
26 }
27#endif // defined(SK_UNICODE_ICU_IMPLEMENTATION)
28#if defined(SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION)
29 if (auto unicode = SkUnicodes::Libgrapheme::Make()) {
30 return unicode;
31 }
32#endif
33#if defined(SK_UNICODE_ICU4X_IMPLEMENTATION)
34 if (auto unicode = SkUnicodes::ICU4X::Make()) {
35 return unicode;
36 }
37#endif
38 SkDEBUGFAIL("Cannot make SkUnicode");
39 return nullptr;
40}
41}
42
43std::vector<bool> GetUtf8WordBoundaries(const char* begin, size_t byteCount, const char* locale) {
44 auto unicode = get_unicode();
45 if (nullptr == unicode) {
46 return {};
47 }
48 std::vector<SkUnicode::Position> positions;
49 if (!unicode->getWords(begin, byteCount, locale, &positions) || byteCount == 0) {
50 return {};
51 }
52 std::vector<bool> result;
53 result.resize(byteCount);
54 for (auto& pos : positions) {
55 result[pos] = true;
56 }
57 return result;
58}
SkPoint pos
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118
static const char * begin(const StringSlice &s)
Definition editor.cpp:252
GAsyncResult * result
SKUNICODE_API sk_sp< SkUnicode > Make()
SKUNICODE_API sk_sp< SkUnicode > Make()
SKUNICODE_API sk_sp< SkUnicode > Make()
static sk_sp< SkUnicode > get_unicode()
std::vector< bool > GetUtf8WordBoundaries(const char *begin, size_t byteCount, const char *locale)