Flutter Engine
The Flutter Engine
Functions
SkShaperJSONWriter.cpp File Reference
#include "modules/skparagraph/tests/SkShaperJSONWriter.h"
#include "include/core/SkFont.h"
#include "include/core/SkSpan.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkUTF.h"
#include "src/utils/SkJSONWriter.h"
#include <algorithm>
#include <cstddef>
#include <limits>
#include <string>
#include <type_traits>

Go to the source code of this file.

Functions

static bool is_one_to_one (const char utf8[], size_t utf8Begin, size_t utf8End, std::vector< uint32_t > &clusters)
 

Function Documentation

◆ is_one_to_one()

static bool is_one_to_one ( const char  utf8[],
size_t  utf8Begin,
size_t  utf8End,
std::vector< uint32_t > &  clusters 
)
static

Definition at line 42 of file SkShaperJSONWriter.cpp.

43 {
44 size_t lastUtf8Index = utf8End;
45
46 auto checkCluster = [&](size_t clusterIndex) {
47 if (clusters[clusterIndex] >= lastUtf8Index) {
48 return false;
49 }
50 size_t utf8ClusterSize = lastUtf8Index - clusters[clusterIndex];
51 if (SkUTF::CountUTF8(&utf8[clusters[clusterIndex]], utf8ClusterSize) != 1) {
52 return false;
53 }
54 lastUtf8Index = clusters[clusterIndex];
55 return true;
56 };
57
58 if (clusters.front() <= clusters.back()) {
59 // left-to-right clusters
60 size_t clusterCursor = clusters.size();
61 while (clusterCursor > 0) {
62 if (!checkCluster(--clusterCursor)) { return false; }
63 }
64 } else {
65 // right-to-left clusters
66 size_t clusterCursor = 0;
67 while (clusterCursor < clusters.size()) {
68 if (!checkCluster(clusterCursor++)) { return false; }
69 }
70 }
71
72 return true;
73}
SK_SPI int CountUTF8(const char *utf8, size_t byteLength)
Definition: SkUTF.cpp:47