summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2018-10-12 02:07:51 +0000
committerandroid-build-prod (mdb) <android-build-team-robot@google.com>2018-10-12 02:07:51 +0000
commitafb7f32e8228a0ca9ecaedcc195afe209619ff48 (patch)
treeaecaa44b8b90420667b0342c8516a8d60171f219
parentec27428856e338331f8ceac11f5b03fd79836289 (diff)
parentd8f8dfa2a0263e2881529073c486a18f51764faa (diff)
downloadminikin-master-cuttlefish-testing-release.tar.gz
Snap for 5061196 from d8f8dfa2a0263e2881529073c486a18f51764faa to master-cuttlefish-testing-releasemaster-cuttlefish-testing-release
Change-Id: I9b1de50e0f9a02b58450afa7a9f1c17f674aa6c8
-rw-r--r--include/minikin/IcuUtils.h33
-rw-r--r--libs/minikin/WordBreaker.cpp33
-rw-r--r--libs/minikin/WordBreaker.h7
-rw-r--r--tests/unittest/WordBreakerTests.cpp3
4 files changed, 59 insertions, 17 deletions
diff --git a/include/minikin/IcuUtils.h b/include/minikin/IcuUtils.h
new file mode 100644
index 0000000..f8d214d
--- /dev/null
+++ b/include/minikin/IcuUtils.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MINIKIN_ICUUTILS_H
+#define MINIKIN_ICUUTILS_H
+
+#include <unicode/ubrk.h>
+#include <memory>
+
+namespace minikin {
+
+struct IcuUbrkDeleter {
+ void operator()(UBreakIterator* v) { ubrk_close(v); }
+};
+
+using IcuUbrkUniquePtr = std::unique_ptr<UBreakIterator, IcuUbrkDeleter>;
+
+} // namespace minikin
+
+#endif // MINIKIN_ICUUTILS_H
diff --git a/libs/minikin/WordBreaker.cpp b/libs/minikin/WordBreaker.cpp
index dae5cab..af9873c 100644
--- a/libs/minikin/WordBreaker.cpp
+++ b/libs/minikin/WordBreaker.cpp
@@ -19,6 +19,7 @@
#include <list>
#include <map>
+#include <unicode/ubrk.h>
#include <unicode/uchar.h>
#include <unicode/utf16.h>
@@ -31,13 +32,21 @@
namespace minikin {
namespace {
-static icu::BreakIterator* createNewIterator(const Locale& locale) {
+static UBreakIterator* createNewIterator(const Locale& locale) {
// TODO: handle failure status
UErrorCode status = U_ZERO_ERROR;
- return icu::BreakIterator::createLineInstance(
- locale.isUnsupported() ? icu::Locale::getRoot()
- : icu::Locale::createFromName(locale.getString().c_str()),
- status);
+ const char* localeID;
+
+ if (locale.isUnsupported()) {
+ localeID = uloc_getDefault();
+ } else {
+ localeID = locale.getString().c_str();
+ }
+
+ char buf[ULOC_FULLNAME_CAPACITY] = {};
+ uloc_getName(localeID, buf, ULOC_FULLNAME_CAPACITY, &status);
+
+ return ubrk_open(UBreakIteratorType::UBRK_LINE, buf, nullptr, 0, &status);
}
} // namespace
@@ -53,7 +62,7 @@ ICULineBreakerPool::Slot ICULineBreakerPoolImpl::acquire(const Locale& locale) {
}
// Not found in pool. Create new one.
- return {id, std::unique_ptr<icu::BreakIterator>(createNewIterator(locale))};
+ return {id, IcuUbrkUniquePtr(createNewIterator(locale))};
}
void ICULineBreakerPoolImpl::release(ICULineBreakerPool::Slot&& slot) {
@@ -79,7 +88,7 @@ ssize_t WordBreaker::followingWithLocale(const Locale& locale, size_t from) {
UErrorCode status = U_ZERO_ERROR;
MINIKIN_ASSERT(mText != nullptr, "setText must be called first");
// TODO: handle failure status
- mIcuBreaker.breaker->setText(&mUText, status);
+ ubrk_setUText(mIcuBreaker.breaker.get(), &mUText, &status);
if (mInEmailOrUrl) {
// Note:
// Don't reset mCurrent, mLast, or mScanOffset for keeping email/URL context.
@@ -116,7 +125,7 @@ ssize_t WordBreaker::current() const {
**/
static bool isValidBreak(const uint16_t* buf, size_t bufEnd, int32_t i) {
const size_t position = static_cast<size_t>(i);
- if (i == icu::BreakIterator::DONE || position == bufEnd) {
+ if (i == UBRK_DONE || position == bufEnd) {
// If the iterator reaches the end, treat as break.
return true;
}
@@ -161,9 +170,9 @@ static bool isValidBreak(const uint16_t* buf, size_t bufEnd, int32_t i) {
// Customized iteratorNext that takes care of both resets and our modifications
// to ICU's behavior.
int32_t WordBreaker::iteratorNext() {
- int32_t result = mIcuBreaker.breaker->following(mCurrent);
+ int32_t result = ubrk_following(mIcuBreaker.breaker.get(), mCurrent);
while (!isValidBreak(mText, mTextSize, result)) {
- result = mIcuBreaker.breaker->next();
+ result = ubrk_next(mIcuBreaker.breaker.get());
}
return result;
}
@@ -211,11 +220,11 @@ void WordBreaker::detectEmailOrUrl() {
}
}
if (state == SAW_AT || state == SAW_COLON_SLASH_SLASH) {
- if (!mIcuBreaker.breaker->isBoundary(i)) {
+ if (!ubrk_isBoundary(mIcuBreaker.breaker.get(), i)) {
// If there are combining marks or such at the end of the URL or the email address,
// consider them a part of the URL or the email, and skip to the next actual
// boundary.
- i = mIcuBreaker.breaker->following(i);
+ i = ubrk_following(mIcuBreaker.breaker.get(), i);
}
mInEmailOrUrl = true;
} else {
diff --git a/libs/minikin/WordBreaker.h b/libs/minikin/WordBreaker.h
index 487c1fa..99023a2 100644
--- a/libs/minikin/WordBreaker.h
+++ b/libs/minikin/WordBreaker.h
@@ -26,8 +26,9 @@
#include <list>
#include <mutex>
-#include <unicode/brkiter.h>
+#include <unicode/ubrk.h>
+#include "minikin/IcuUtils.h"
#include "minikin/Macros.h"
#include "minikin/Range.h"
@@ -41,7 +42,7 @@ class ICULineBreakerPool {
public:
struct Slot {
Slot() : localeId(0), breaker(nullptr) {}
- Slot(uint64_t localeId, std::unique_ptr<icu::BreakIterator>&& breaker)
+ Slot(uint64_t localeId, IcuUbrkUniquePtr&& breaker)
: localeId(localeId), breaker(std::move(breaker)) {}
Slot(Slot&& other) = default;
@@ -52,7 +53,7 @@ public:
Slot& operator=(const Slot&) = delete;
uint64_t localeId;
- std::unique_ptr<icu::BreakIterator> breaker;
+ IcuUbrkUniquePtr breaker;
};
virtual ~ICULineBreakerPool() {}
virtual Slot acquire(const Locale& locale) = 0;
diff --git a/tests/unittest/WordBreakerTests.cpp b/tests/unittest/WordBreakerTests.cpp
index 394c64e..ee01d09 100644
--- a/tests/unittest/WordBreakerTests.cpp
+++ b/tests/unittest/WordBreakerTests.cpp
@@ -96,7 +96,6 @@ TEST(WordBreakerTest, postfixAndPrefix) {
TEST(WordBreakerTest, myanmarKinzi) {
uint16_t buf[] = {0x1004, 0x103A, 0x1039, 0x1000, 0x102C}; // NGA, ASAT, VIRAMA, KA, UU
WordBreaker breaker;
- icu::Locale burmese("my");
breaker.setText(buf, NELEM(buf));
EXPECT_EQ(0, breaker.current());
@@ -596,7 +595,7 @@ TEST(WordBreakerTest, LineBreakerPool_acquire_with_release) {
ICULineBreakerPool::Slot enUSBreaker = pool.acquire(enUS);
uint64_t enUSBreakerLocaleId = enUSBreaker.localeId;
- icu::BreakIterator* enUSBreakerPtr = enUSBreaker.breaker.get();
+ UBreakIterator* enUSBreakerPtr = enUSBreaker.breaker.get();
pool.release(std::move(enUSBreaker));
EXPECT_EQ(nullptr, enUSBreaker.breaker.get());