// Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "include/core/SkTypes.h" #include "include/private/SkTemplates.h" #include "modules/skplaintexteditor/src/word_boundaries.h" #include #include #include #include namespace { template using resource = std::unique_ptr>; using ICUBrk = resource; using ICUUText = resource; } // namespace std::vector GetUtf8WordBoundaries(const char* begin, size_t byteCount, const char* locale) { std::vector result; if (0 == byteCount) { return result; } result.resize(byteCount); UErrorCode status = U_ZERO_ERROR; UText sUtf8UText = UTEXT_INITIALIZER; ICUUText utf8UText(utext_openUTF8(&sUtf8UText, begin, byteCount, &status)); if (U_FAILURE(status)) { SkDebugf("Could not create utf8UText: %s", u_errorName(status)); return result; } ICUBrk wordBreakIterator(ubrk_open(UBRK_WORD, locale, nullptr, 0, &status)); if (!wordBreakIterator || U_FAILURE(status)) { SkDEBUGF("Could not create line break iterator: %s", u_errorName(status)); return result; } ubrk_setUText(&*wordBreakIterator, utf8UText.get(), &status); if (U_FAILURE(status)) { SkDebugf("Could not setText on break iterator: %s", u_errorName(status)); return result; } int32_t pos = ubrk_first(&*wordBreakIterator); while (pos != UBRK_DONE) { if ((size_t)pos < byteCount) { result[pos] = true; } pos = ubrk_next(&*wordBreakIterator); } return result; }