15static std::vector<SkUnicode::Position> gSentences;
16static std::vector<SkUnicode::Position> gWords;
22 if (unicodeName.
equals(
"icu")) {
24 }
else if (unicodeName.
equals(
"icu4x")) {
26 }
else if (unicodeName.
equals(
"libgrapheme")) {
29 SkDebugf(
"Implementation '%s' not supported\n", impl);
32 auto ptr =
reinterpret_cast<void*
>(gUnicode.get());
34 SkDebugf(
"Could not create Unicode object\n");
41 if (gUnicode ==
nullptr) {
42 SkDebugf(
"Unicode object does not exist\n");
45 delete gUnicode.get();
49 if (gUnicode ==
nullptr) {
50 SkDebugf(
"Unicode object does not exist\n");
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);
59 std::vector<SkUnicode::Position> positions;
60 gUnicode->getUtf8Words(
text, strlen(
text),
nullptr, &positions);
62 for (
auto pos : positions) {
63 gCodeUnitFlags[
pos] |= SkUnicode::CodeUnitFlags::kWordBreak;
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());
76 return gCodeUnitFlags[index];
80 if (gUnicode ==
nullptr) {
81 SkDebugf(
"Unicode object does not exist");
86 gUnicode->getSentences(
text, strlen(
text),
nullptr, &gSentences);
87 *
length = gSentences.size();
94 if (gUnicode ==
nullptr) {
95 SkDebugf(
"Unicode object does not exist");
100 gUnicode->getUtf8Words(
text, strlen(
text),
nullptr, &gWords);
102 for (
auto word : gWords) {
103 if (
word > wordLimit) {
109 if (strlen(
text) <= wordLimit) {
110 *sentence = strlen(
text);
118 if (gUnicode ==
nullptr) {
119 SkDebugf(
"Unicode object does not exist");
123 return reinterpret_cast<void*
>(res);
127 auto ptr =
reinterpret_cast<SkString*
>(str);
#define SK_ABORT(message,...)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
double perf_compute_codeunit_flags(char *text)
void cleanup_unicode_impl()
bool trimSentence(char *text, int *sentence, int wordLimit)
void * getSentences(char *text, int *length)
bool init_skunicode_impl(char *impl)
void * toUpper(char *str)
bool equals(const SkString &) const
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
static double time(int loops, Benchmark *bench, Target *target)