Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 973afa96 authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

Add isPrintableAscii() and isPrintableAsciiOnly() to TextUtils.java as hidden...

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
parent a45e9251
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -359,20 +359,14 @@ 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')) {
            if (!TextUtils.isPrintableAsciiOnly(value)) {
                return false;
            }
        }
        }
        return true;
    }

+22 −0
Original line number Diff line number Diff line
@@ -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