aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-10-24 17:12:30 +0900
committerJean Chalard <jchalard@google.com>2014-10-29 12:27:24 +0900
commitecab6aff5908bfd5b34670d2e2bb3696627fa47c (patch)
tree3573d2f3c91f217b1c7e629cd41ece24ebdb540f /common/src/com/android/inputmethod/latin
parent36799b2aa2982ec17341cd2c5ed81e608bcee8c6 (diff)
downloadlatinime-ecab6aff5908bfd5b34670d2e2bb3696627fa47c.tar.gz
latinime-ecab6aff5908bfd5b34670d2e2bb3696627fa47c.tar.xz
latinime-ecab6aff5908bfd5b34670d2e2bb3696627fa47c.zip
Remove Dict dependency on WordComposer and ProximityInfo
Bug: 18108776 Change-Id: I9b399a44241e05a7add9bb8094263aa76de37880
Diffstat (limited to 'common/src/com/android/inputmethod/latin')
-rw-r--r--common/src/com/android/inputmethod/latin/common/ComposedData.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/common/src/com/android/inputmethod/latin/common/ComposedData.java b/common/src/com/android/inputmethod/latin/common/ComposedData.java
new file mode 100644
index 000000000..0508d49cb
--- /dev/null
+++ b/common/src/com/android/inputmethod/latin/common/ComposedData.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+package com.android.inputmethod.latin.common;
+
+/**
+ * An immutable class that encapsulates a snapshot of word composition data.
+ */
+public class ComposedData {
+ public final InputPointers mInputPointers;
+ public final boolean mIsBatchMode;
+ public final String mTypedWord;
+ public ComposedData(final InputPointers inputPointers, final boolean isBatchMode,
+ final String typedWord) {
+ mInputPointers = inputPointers;
+ mIsBatchMode = isBatchMode;
+ mTypedWord = typedWord;
+ }
+
+ /**
+ * Copy the code points in the typed word to a destination array of ints.
+ *
+ * If the array is too small to hold the code points in the typed word, nothing is copied and
+ * -1 is returned.
+ *
+ * @param destination the array of ints.
+ * @return the number of copied code points.
+ */
+ public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
+ final int[] destination) {
+ // lastIndex is exclusive
+ final int lastIndex = mTypedWord.length()
+ - StringUtils.getTrailingSingleQuotesCount(mTypedWord);
+ if (lastIndex <= 0) {
+ // The string is empty or contains only single quotes.
+ return 0;
+ }
+
+ // The following function counts the number of code points in the text range which begins
+ // at index 0 and extends to the character at lastIndex.
+ final int codePointSize = Character.codePointCount(mTypedWord, 0, lastIndex);
+ if (codePointSize > destination.length) {
+ return -1;
+ }
+ return StringUtils.copyCodePointsAndReturnCodePointCount(destination, mTypedWord, 0,
+ lastIndex, true /* downCase */);
+ }
+}