Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
bridge.h File Reference
#include <stdbool.h>

Go to the source code of this file.

Functions

bool init_skunicode_impl (char *impl)
 
void cleanup_unicode_impl ()
 
void * toUpper (char *str)
 
void print (void *str)
 
double perf_compute_codeunit_flags (char *text)
 
int getFlags (int index)
 
void * getSentences (char *text, int *length)
 
bool trimSentence (char *text, int *sentence, int wordLimit)
 

Function Documentation

◆ cleanup_unicode_impl()

void cleanup_unicode_impl ( )

Definition at line 40 of file bridge.cpp.

40 {
41 if (gUnicode == nullptr) {
42 SkDebugf("Unicode object does not exist\n");
43 return;
44 }
45 delete gUnicode.get();
46}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ getFlags()

int getFlags ( int  index)

Definition at line 68 of file bridge.cpp.

68 {
69 if (gUnicode == nullptr) {
70 SK_ABORT("Unicode object does not exist");
71 } else if (gCodeUnitFlags.size() == 0) {
72 SK_ABORT("Unicode object is empty or not initialized\n");
73 } else if (index < 0 || index >= gCodeUnitFlags.size()) {
74 SK_ABORT("Index value %d outside of valid range [%d:%d)\n", index, 0, gCodeUnitFlags.size());
75 }
76 return gCodeUnitFlags[index];
77}
#define SK_ABORT(message,...)
Definition SkAssert.h:70

◆ getSentences()

void * getSentences ( char *  text,
int length 
)

Definition at line 79 of file bridge.cpp.

79 {
80 if (gUnicode == nullptr) {
81 SkDebugf("Unicode object does not exist");
82 return nullptr;
83 }
84
85 gSentences.clear();
86 gUnicode->getSentences(text, strlen(text), nullptr, &gSentences);
87 *length = gSentences.size();
88
89 return reinterpret_cast<SkUnicode::Position*>(gSentences.data());
90}
size_t Position
Definition SkUnicode.h:98
size_t length
std::u16string text

◆ init_skunicode_impl()

bool init_skunicode_impl ( char *  impl)

Definition at line 19 of file bridge.cpp.

19 {
20
21 SkString unicodeName(impl);
22 if (unicodeName.equals("icu")) {
23 gUnicode = SkUnicode::ICU::Make();
24 } else if (unicodeName.equals("icu4x")) {
25 gUnicode = SkUnicode::ICU4X::Make();
26 } else if (unicodeName.equals("libgrapheme")) {
27 gUnicode = SkUnicode::Libgrapheme::Make();
28 } else {
29 SkDebugf("Implementation '%s' not supported\n", impl);
30 return false;
31 }
32 auto ptr = reinterpret_cast<void*>(gUnicode.get());
33 if (ptr == nullptr) {
34 SkDebugf("Could not create Unicode object\n");
35 return false;
36 }
37 return true;
38}

◆ perf_compute_codeunit_flags()

double perf_compute_codeunit_flags ( char *  text)

Definition at line 48 of file bridge.cpp.

48 {
49 if (gUnicode == nullptr) {
50 SkDebugf("Unicode object does not exist\n");
51 return -1;
52 }
53 double time = SkTime::GetNSecs();
54 gUnicode->computeCodeUnitFlags(text, strlen(text), false, &gCodeUnitFlags);
55 if (gCodeUnitFlags.size() < strlen(text)) {
56 SkDebugf("computeCodeUnitFlags failed: %d < %zu\n%s\n\n\n", gCodeUnitFlags.size(), strlen(text), text);
57 return -1;
58 }
59 std::vector<SkUnicode::Position> positions;
60 gUnicode->getUtf8Words(text, strlen(text), nullptr, &positions);
61 double result = SkTime::GetNSecs() - time;
62 for (auto pos : positions) {
64 }
65 return result;
66}
SkPoint pos
GAsyncResult * result
double GetNSecs()
Definition SkTime.cpp:17

◆ print()

void print ( void *  str)

Definition at line 126 of file bridge.cpp.

126 {
127 auto ptr = reinterpret_cast<SkString*>(str);
128 SkDebugf("%s\n", ptr->c_str());
129}

◆ toUpper()

void * toUpper ( char *  str)

Definition at line 117 of file bridge.cpp.

117 {
118 if (gUnicode == nullptr) {
119 SkDebugf("Unicode object does not exist");
120 return nullptr;
121 }
122 auto res = new SkString(gUnicode->toUpper(SkString(str)));
123 return reinterpret_cast<void*>(res);
124}

◆ trimSentence()

bool trimSentence ( char *  text,
int sentence,
int  wordLimit 
)

Definition at line 92 of file bridge.cpp.

92 {
93 *sentence = 0;
94 if (gUnicode == nullptr) {
95 SkDebugf("Unicode object does not exist");
96 return true;
97 }
98
99 gWords.clear();
100 gUnicode->getUtf8Words(text, strlen(text), nullptr, &gWords);
101
102 for (auto word : gWords) {
103 if (word > wordLimit) {
104 return true;
105 } else {
106 *sentence = word;
107 }
108 }
109 if (strlen(text) <= wordLimit) {
110 *sentence = strlen(text);
111 return false;
112 }
113 return true;
114}
intptr_t word
Definition globals.h:500