12ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* GENERATED SOURCE. DO NOT MODIFY. */ 2f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// © 2016 and later: Unicode, Inc. and others. 3f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html#License 42ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* 52ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ******************************************************************************** 62ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Copyright (C) 2010-2014, Google, International Business Machines Corporation * 72ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and others. All Rights Reserved. * 82ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ******************************************************************************** 92ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpackage android.icu.lang; 112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/** 142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * A number of utilities for dealing with CharSequences and related classes. 152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For accessing codepoints with a CharSequence, also see 162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <ul> 172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>{@link java.lang.Character#codePointAt(CharSequence, int)}</li> 182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>{@link java.lang.Character#codePointBefore(CharSequence, int)}</li> 192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>{@link java.lang.Character#codePointCount(CharSequence, int, int)}</li> 202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>{@link java.lang.Character#charCount(int)}</li> 212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>{@link java.lang.Character#offsetByCodePoints(CharSequence, int, int)}</li> 222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>{@link java.lang.Character#toChars(int, char[], int)}</li> 232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>{@link java.lang.Character#toCodePoint(char, char)}</li> 242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </ul> 252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @author markdavis 262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 27836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide Only a subset of ICU is exposed in Android 28836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller@Deprecated 312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpublic class CharSequences { 322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // TODO 332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // compareTo(a, b); 342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // compareToIgnoreCase(a, b) 352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // contentEquals(a, b) 362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // contentEqualsIgnoreCase(a, b) 372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // contains(a, b) => indexOf >= 0 392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // endsWith(a, b) 402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // startsWith(a, b) 412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // lastIndexOf(a, b, fromIndex) 432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // indexOf(a, ch, fromIndex) 442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // lastIndexOf(a, ch, fromIndex); 452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // s.trim() => UnicodeSet.trim(CharSequence s); return a subsequence starting with the first character not in the set to the last character not in the set. 472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // add UnicodeSet.split(CharSequence s); 482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Find the longest n such that a[aIndex,n] = b[bIndex,n], and n is on a character boundary. 512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 52836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int matchAfter(CharSequence a, CharSequence b, int aIndex, int bIndex) { 562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int i = aIndex, j = bIndex; 572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int alen = a.length(); 582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int blen = b.length(); 592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (; i < alen && j < blen; ++i, ++j) { 602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char ca = a.charAt(i); 612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char cb = b.charAt(j); 622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (ca != cb) { 632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller break; 642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // if we failed a match make sure that we didn't match half a character 672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int result = i - aIndex; 682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (result != 0 && !onCharacterBoundary(a, i) && !onCharacterBoundary(b, j)) { 692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller --result; // backup 702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return result; 722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Count the code point length. Unpaired surrogates count as 1. 762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 77836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int codePointLength(CharSequence s) { 812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return Character.codePointCount(s, 0, s.length()); 822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// int length = s.length(); 832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// int result = length; 842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// for (int i = 1; i < length; ++i) { 852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// char ch = s.charAt(i); 862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// if (0xDC00 <= ch && ch <= 0xDFFF) { 872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// char ch0 = s.charAt(i-1); 882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// if (0xD800 <= ch && ch <= 0xDbFF) { 892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// --result; 902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// } 912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// } 922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller// } 932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Utility function for comparing codepoint to string without generating new 972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * string. 982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 100836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 1012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 1032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final boolean equals(int codepoint, CharSequence other) { 1042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (other == null) { 1052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 1062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller switch (other.length()) { 1082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller case 1: return codepoint == other.charAt(0); 1092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller case 2: return codepoint > 0xFFFF && codepoint == Character.codePointAt(other, 0); 1102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller default: return false; 1112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 116836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 1172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 1192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final boolean equals(CharSequence other, int codepoint) { 1202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return equals(codepoint, other); 1212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Utility to compare a string to a code point. 1252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Same results as turning the code point into a string (with the [ugly] new StringBuilder().appendCodePoint(codepoint).toString()) 1262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and comparing, but much faster (no object creation). 1272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Actually, there is one difference; a null compares as less. 1282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Note that this (=String) order is UTF-16 order -- *not* code point order. 1292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 131836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 1322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 1342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int compare(CharSequence string, int codePoint) { 1352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (codePoint < Character.MIN_CODE_POINT || codePoint > Character.MAX_CODE_POINT) { 1362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException(); 1372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int stringLength = string.length(); 1392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (stringLength == 0) { 1402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return -1; 1412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char firstChar = string.charAt(0); 1432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int offset = codePoint - Character.MIN_SUPPLEMENTARY_CODE_POINT; 1442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (offset < 0) { // BMP codePoint 1462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int result = firstChar - codePoint; 1472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (result != 0) { 1482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return result; 1492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return stringLength - 1; 1512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // non BMP 1532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char lead = (char)((offset >>> 10) + Character.MIN_HIGH_SURROGATE); 1542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int result = firstChar - lead; 1552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (result != 0) { 1562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return result; 1572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (stringLength > 1) { 1592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char trail = (char)((offset & 0x3ff) + Character.MIN_LOW_SURROGATE); 1602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller result = string.charAt(1) - trail; 1612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (result != 0) { 1622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return result; 1632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return stringLength - 2; 1662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Utility to compare a string to a code point. 1702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Same results as turning the code point into a string and comparing, but much faster (no object creation). 1712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Actually, there is one difference; a null compares as less. 1722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Note that this (=String) order is UTF-16 order -- *not* code point order. 1732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 175836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 1762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 1782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int compare(int codepoint, CharSequence a) { 179f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert int result = compare(a, codepoint); 180f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert return result > 0 ? -1 : result < 0 ? 1 : 0; // Reverse the order. 1812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return the value of the first code point, if the string is exactly one code point. Otherwise return Integer.MAX_VALUE. 1852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 187836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 1882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 1902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int getSingleCodePoint(CharSequence s) { 1912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int length = s.length(); 1922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (length < 1 || length > 2) { 1932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return Integer.MAX_VALUE; 1942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int result = Character.codePointAt(s, 0); 1962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return (result < 0x10000) == (length == 1) ? result : Integer.MAX_VALUE; 1972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Utility function for comparing objects that may be null 2012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * string. 2022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 204836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 2052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 2072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final <T extends Object> boolean equals(T a, T b) { 2082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return a == null ? b == null 2092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller : b == null ? false 2102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller : a.equals(b); 2112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Utility for comparing the contents of CharSequences 2152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 217836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 2182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 2202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int compare(CharSequence a, CharSequence b) { 2212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int alength = a.length(); 2222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int blength = b.length(); 2232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int min = alength <= blength ? alength : blength; 2242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (int i = 0; i < min; ++i) { 2252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int diff = a.charAt(i) - b.charAt(i); 2262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (diff != 0) { 2272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return diff; 2282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return alength - blength; 2312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Utility for comparing the contents of CharSequences 2352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 237836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 2382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 2402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static boolean equalsChars(CharSequence a, CharSequence b) { 2412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // do length test first for fast path 2422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return a.length() == b.length() && compare(a,b) == 0; 2432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Are we on a character boundary? 2472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 249836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 2502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 2522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static boolean onCharacterBoundary(CharSequence s, int i) { 2532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return i <= 0 2542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller || i >= s.length() 2552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller || !Character.isHighSurrogate(s.charAt(i-1)) 2562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller || !Character.isLowSurrogate(s.charAt(i)); 2572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Find code point in string. 2612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 263836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 2642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 2662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int indexOf(CharSequence s, int codePoint) { 2672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int cp; 2682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (int i = 0; i < s.length(); i += Character.charCount(cp)) { 2692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller cp = Character.codePointAt(s, i); 2702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (cp == codePoint) { 2712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return i; 2722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return -1; 2752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Utility function for simplified, more robust loops, such as: 2792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 2802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for (int codePoint : CharSequences.codePoints(string)) { 2812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * doSomethingWith(codePoint); 2822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 2832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 2842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 286836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 2872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 2892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static int[] codePoints(CharSequence s) { 2902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int[] result = new int[s.length()]; // in the vast majority of cases, the length is the same 2912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int j = 0; 2922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (int i = 0; i < s.length(); ++i) { 2932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char cp = s.charAt(i); 2942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (cp >= 0xDC00 && cp <= 0xDFFF && i != 0 ) { // hand-code for speed 2952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller char last = (char) result[j-1]; 2962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (last >= 0xD800 && last <= 0xDBFF) { 2972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Note: j-1 is safe, because j can only be zero if i is zero. But i!=0 in this block. 2982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller result[j-1] = Character.toCodePoint(last, cp); 2992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller continue; 3002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller result[j++] = cp; 3032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (j == result.length) { 3052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return result; 3062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int[] shortResult = new int[j]; 3082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller System.arraycopy(result, 0, shortResult, 0, j); 3092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return shortResult; 3102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private CharSequences() { 3132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller} 315