From 7cd7cf73f4ce6f0e577d6382eb0fc25f60dc63e1 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 16 Dec 2013 21:41:03 +0900 Subject: Fix a bug with languages without spaces and predictions This is simpler and more correct. Change-Id: I41806d2fc12b4ca25f76e32972b38f91f3d05c2b --- .../android/inputmethod/latin/utils/StringUtils.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'java/src/com/android/inputmethod/latin/utils/StringUtils.java') diff --git a/java/src/com/android/inputmethod/latin/utils/StringUtils.java b/java/src/com/android/inputmethod/latin/utils/StringUtils.java index df420417d..85f44541e 100644 --- a/java/src/com/android/inputmethod/latin/utils/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/StringUtils.java @@ -250,6 +250,24 @@ public final class StringUtils { return true; } + /** + * Returns true if all code points in text are whitespace, false otherwise. Empty is true. + */ + // Interestingly enough, U+00A0 NO-BREAK SPACE and U+200B ZERO-WIDTH SPACE are not considered + // whitespace, while EN SPACE, EM SPACE and IDEOGRAPHIC SPACES are. + public static boolean containsOnlyWhitespace(final String text) { + final int length = text.length(); + int i = 0; + while (i < length) { + final int codePoint = text.codePointAt(i); + if (!Character.isWhitespace(codePoint)) { + return false; + } + i += Character.charCount(codePoint); + } + return true; + } + @UsedForTesting public static boolean looksValidForDictionaryInsertion(final CharSequence text, final SettingsValues settings) { -- cgit v1.2.3-83-g751a