From ecab6aff5908bfd5b34670d2e2bb3696627fa47c Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 24 Oct 2014 17:12:30 +0900 Subject: Remove Dict dependency on WordComposer and ProximityInfo Bug: 18108776 Change-Id: I9b399a44241e05a7add9bb8094263aa76de37880 --- .../inputmethod/latin/common/ComposedData.java | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 common/src/com/android/inputmethod/latin/common/ComposedData.java (limited to 'common/src/com/android/inputmethod/latin') 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 */); + } +} -- cgit v1.2.3-83-g751a