From 2f0f44212fc1e86bd7bd54431bf6a0cd62aa093c Mon Sep 17 00:00:00 2001 From: Ishibashi Takako Date: Thu, 4 Nov 2010 08:43:33 +0100 Subject: [PATCH] JPtextinput: Dont break emoji characters when cutting strings. In the LengthFilter make sure that we do not cut the string so a last emoji character gets broken and replaced by some garbage character. We need to check if the last char is the high surrogate and if so drop the high surrogate also. Change-Id: I210e7e41aa0761ecbb2b32e3ebf680a04382c287 --- core/java/android/text/InputFilter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/java/android/text/InputFilter.java b/core/java/android/text/InputFilter.java index 2f55677ee24fa..8d4b08e3c40fb 100644 --- a/core/java/android/text/InputFilter.java +++ b/core/java/android/text/InputFilter.java @@ -88,7 +88,14 @@ public interface InputFilter } else if (keep >= end - start) { return null; // keep original } else { - return source.subSequence(start, start + keep); + keep += start; + if (Character.isHighSurrogate(source.charAt(keep - 1))) { + --keep; + if (keep == start) { + return ""; + } + } + return source.subSequence(start, keep); } }