diff options
Diffstat (limited to 'core/java/android/pim/vcard/VCardUtils.java')
-rw-r--r-- | core/java/android/pim/vcard/VCardUtils.java | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/core/java/android/pim/vcard/VCardUtils.java b/core/java/android/pim/vcard/VCardUtils.java index 80457bb..ec75a98 100644 --- a/core/java/android/pim/vcard/VCardUtils.java +++ b/core/java/android/pim/vcard/VCardUtils.java @@ -352,6 +352,13 @@ public class VCardUtils { if (values == null) { return true; } + return containsOnlyPrintableAscii(Arrays.asList(values)); + } + + public static boolean containsOnlyPrintableAscii(final Collection<String> values) { + if (values == null) { + return true; + } final int asciiFirst = 0x20; final int asciiLast = 0x7E; // included for (final String value : values) { @@ -378,6 +385,13 @@ public class VCardUtils { if (values == null) { return true; } + return containsOnlyNonCrLfPrintableAscii(Arrays.asList(values)); + } + + public static boolean containsOnlyNonCrLfPrintableAscii(final Collection<String> values) { + if (values == null) { + return true; + } final int asciiFirst = 0x20; final int asciiLast = 0x7E; // included for (final String value : values) { @@ -399,32 +413,6 @@ public class VCardUtils { new HashSet<Character>(Arrays.asList('[', ']', '=', ':', '.', ',', ' ')); /** - * <P> - * Returns true when the given String is categorized as "word" specified in vCard spec 2.1. - * </P> - * <P> - * vCard 2.1 specifies:<BR /> - * word = <any printable 7bit us-ascii except []=:., > - * </P> - */ - public static boolean isV21Word(final String value) { - if (TextUtils.isEmpty(value)) { - return true; - } - final int asciiFirst = 0x20; - final int asciiLast = 0x7E; // included - 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) || - sUnAcceptableAsciiInV21WordSet.contains((char)c)) { - return false; - } - } - return true; - } - - /** * This is useful since vCard 3.0 often requires the ("X-") properties and groups * should contain only alphabets, digits, and hyphen. * @@ -437,6 +425,13 @@ public class VCardUtils { if (values == null) { return true; } + return containsOnlyAlphaDigitHyphen(Arrays.asList(values)); + } + + public static boolean containsOnlyAlphaDigitHyphen(final Collection<String> values) { + if (values == null) { + return true; + } final int upperAlphabetFirst = 0x41; // A final int upperAlphabetAfterLast = 0x5b; // [ final int lowerAlphabetFirst = 0x61; // a @@ -461,7 +456,33 @@ public class VCardUtils { } return true; } - + + /** + * <P> + * Returns true when the given String is categorized as "word" specified in vCard spec 2.1. + * </P> + * <P> + * vCard 2.1 specifies:<BR /> + * word = <any printable 7bit us-ascii except []=:., > + * </P> + */ + public static boolean isV21Word(final String value) { + if (TextUtils.isEmpty(value)) { + return true; + } + final int asciiFirst = 0x20; + final int asciiLast = 0x7E; // included + 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) || + sUnAcceptableAsciiInV21WordSet.contains((char)c)) { + return false; + } + } + return true; + } + public static String toHalfWidthString(final String orgString) { if (TextUtils.isEmpty(orgString)) { return null; |