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 4 #include "include/core/SkTypes.h" 5 #include "modules/skplaintexteditor/src/word_boundaries.h" 6 #include "modules/skunicode/include/SkUnicode.h" 7 #include <memory> 8 GetUtf8WordBoundaries(const char * begin,size_t byteCount,const char * locale)9std::vector<bool> GetUtf8WordBoundaries(const char* begin, size_t byteCount, const char* locale) { 10 auto unicode = SkUnicode::Make(); 11 if (nullptr == unicode) { 12 return {}; 13 } 14 std::vector<SkUnicode::Position> positions; 15 if (!unicode->getWords(begin, byteCount, locale, &positions) || byteCount == 0) { 16 return {}; 17 } 18 std::vector<bool> result; 19 result.resize(byteCount); 20 for (auto& pos : positions) { 21 result[pos] = true; 22 } 23 return result; 24 } 25