Merge change I6173d7c7 into eclair-mr2

* changes:
  Add isPrintableAscii() and isPrintableAsciiOnly() to TextUtils.java as hidden methods, and make vCard code use them.
This commit is contained in:
Android (Google) Code Review
2009-12-03 13:55:07 -08:00
2 changed files with 24 additions and 8 deletions

View File

@@ -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;

View File

@@ -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