From 973afa96bf184be6b8b5a25963568650e70750f7 Mon Sep 17 00:00:00 2001 From: Daisuke Miyakawa Date: Thu, 3 Dec 2009 10:43:45 +0900 Subject: [PATCH] Add isPrintableAscii() and isPrintableAsciiOnly() to TextUtils.java as hidden methods, and make vCard code use them. In the future, ContactsProvider will use those methods. See also the change 34604 Internal issue number: 2275764, 2195990 --- core/java/android/pim/vcard/VCardUtils.java | 10 ++-------- core/java/android/text/TextUtils.java | 22 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core/java/android/pim/vcard/VCardUtils.java b/core/java/android/pim/vcard/VCardUtils.java index ec75a9882032b..11b112b76dbb1 100644 --- a/core/java/android/pim/vcard/VCardUtils.java +++ b/core/java/android/pim/vcard/VCardUtils.java @@ -359,18 +359,12 @@ public class VCardUtils { if (values == null) { return true; } - final int asciiFirst = 0x20; - final int asciiLast = 0x7E; // included for (final String value : values) { if (TextUtils.isEmpty(value)) { continue; } - final int length = value.length(); - for (int i = 0; i < length; i = value.offsetByCodePoints(i, 1)) { - final int c = value.codePointAt(i); - if (!((asciiFirst <= c && c <= asciiLast) || c == '\r' || c == '\n')) { - return false; - } + if (!TextUtils.isPrintableAsciiOnly(value)) { + return false; } } return true; diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java index 53096dddefb59..afb22acef433f 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -1500,6 +1500,28 @@ public class TextUtils { return true; } + /** + * @hide + */ + public static boolean isPrintableAscii(final char c) { + final int asciiFirst = 0x20; + final int asciiLast = 0x7E; // included + return (asciiFirst <= c && c <= asciiLast) || c == '\r' || c == '\n'; + } + + /** + * @hide + */ + public static boolean isPrintableAsciiOnly(final CharSequence str) { + final int len = str.length(); + for (int i = 0; i < len; i++) { + if (!isPrintableAscii(str.charAt(i))) { + return false; + } + } + return true; + } + /** * Capitalization mode for {@link #getCapsMode}: capitalize all * characters. This value is explicitly defined to be the same as