aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDan Zivkovic <zivkovic@google.com>2015-02-04 16:12:15 -0800
committerDan Zivkovic <zivkovic@google.com>2015-02-04 16:35:18 -0800
commitf3c319fb8ac29448c491af95261a4ce01b64a59c (patch)
tree5c16ae8c6d8b8aef5f0c622ca5b4dd28ddf0e29d /common
parentc71e4d65343bf782d80ce508786befa6ee3261cf (diff)
downloadlatinime-f3c319fb8ac29448c491af95261a4ce01b64a59c.tar.gz
latinime-f3c319fb8ac29448c491af95261a4ce01b64a59c.tar.xz
latinime-f3c319fb8ac29448c491af95261a4ce01b64a59c.zip
Selections spans should not split surrogate pair.
When committing a span after a revert, the offset logic was such that it split a surrogate unicode pair used to express an emoji. Checking the last character of the span lets us avoid this problem. Fix for bug 19255233. Change-Id: I07d18d9002b5075f7925319dd05962011656c311
Diffstat (limited to 'common')
-rw-r--r--common/src/com/android/inputmethod/latin/common/Constants.java3
-rw-r--r--common/src/com/android/inputmethod/latin/common/UnicodeSurrogate.java38
2 files changed, 38 insertions, 3 deletions
diff --git a/common/src/com/android/inputmethod/latin/common/Constants.java b/common/src/com/android/inputmethod/latin/common/Constants.java
index a860d3560..a10f866fc 100644
--- a/common/src/com/android/inputmethod/latin/common/Constants.java
+++ b/common/src/com/android/inputmethod/latin/common/Constants.java
@@ -163,7 +163,6 @@ public final class Constants {
// TODO: replace the following constants with state in InputTransaction?
public static final int NOT_A_COORDINATE = -1;
public static final int SUGGESTION_STRIP_COORDINATE = -2;
- public static final int SPELL_CHECKER_COORDINATE = -3;
public static final int EXTERNAL_KEYBOARD_COORDINATE = -4;
// A hint on how many characters to cache from the TextView. A good value of this is given by
@@ -214,8 +213,6 @@ public final class Constants {
public static final int CODE_DASH = '-';
public static final int CODE_SINGLE_QUOTE = '\'';
public static final int CODE_DOUBLE_QUOTE = '"';
- public static final int CODE_QUESTION_MARK = '?';
- public static final int CODE_EXCLAMATION_MARK = '!';
public static final int CODE_SLASH = '/';
public static final int CODE_BACKSLASH = '\\';
public static final int CODE_VERTICAL_BAR = '|';
diff --git a/common/src/com/android/inputmethod/latin/common/UnicodeSurrogate.java b/common/src/com/android/inputmethod/latin/common/UnicodeSurrogate.java
new file mode 100644
index 000000000..10974634d
--- /dev/null
+++ b/common/src/com/android/inputmethod/latin/common/UnicodeSurrogate.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2015 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;
+
+/**
+ * Emojis are supplementary characters expressed as a low+high pair. For instance,
+ * the emoji U+1F625 is encoded as "\uD83D\uDE25" in UTF-16, where '\uD83D' is in
+ * the range of [0xd800, 0xdbff] and '\uDE25' is in the range of [0xdc00, 0xdfff].
+ * {@see http://docs.oracle.com/javase/6/docs/api/java/lang/Character.html#unicode}
+ */
+public final class UnicodeSurrogate {
+ private static final char LOW_SURROGATE_MIN = '\uD800';
+ private static final char LOW_SURROGATE_MAX = '\uDBFF';
+ private static final char HIGH_SURROGATE_MIN = '\uDC00';
+ private static final char HIGH_SURROGATE_MAX = '\uDFFF';
+
+ public static boolean isLowSurrogate(final char c) {
+ return c >= LOW_SURROGATE_MIN && c <= LOW_SURROGATE_MAX;
+ }
+
+ public static boolean isHighSurrogate(final char c) {
+ return c >= HIGH_SURROGATE_MIN && c <= HIGH_SURROGATE_MAX;
+ }
+}