1104 return nonSyncContentEquals((AbstractStringBuilder)cs);
1105 }
1106 }
1107 // Argument is a String
1108 if (cs instanceof String) {
1109 return equals(cs);
1110 }
1111 // Argument is a generic CharSequence
1112 int n = cs.length();
1113 if (n != length()) {
1114 return false;
1115 }
1116 byte[] val = this.value;
1117 if (isLatin1()) {
1118 for (int i = 0; i < n; i++) {
1119 if ((val[i] & 0xff) != cs.charAt(i)) {
1120 return false;
1121 }
1122 }
1123 } else {
1124 for (int i = 0; i < n; i++) {
1125 if (StringUTF16.getChar(val, i) != cs.charAt(i)) {
1126 return false;
1127 }
1128 }
1129 }
1130 return true;
1131 }
1132
1133 /**
1134 * Compares this {@code String} to another {@code String}, ignoring case
1135 * considerations. Two strings are considered equal ignoring case if they
1136 * are of the same length and corresponding characters in the two strings
1137 * are equal ignoring case.
1138 *
1139 * <p> Two characters {@code c1} and {@code c2} are considered the same
1140 * ignoring case if at least one of the following is true:
1141 * <ul>
1142 * <li> The two characters are the same (as compared by the
1143 * {@code ==} operator)
1817 if (fromIndex < 0) {
1818 return -1;
1819 }
1820 /* Empty string always matches. */
1821 if (tgtCount == 0) {
1822 return fromIndex;
1823 }
1824 if (srcCoder == tgtCoder) {
1825 return srcCoder == LATIN1
1826 ? StringLatin1.lastIndexOf(src, srcCount, tgt, tgtCount, fromIndex)
1827 : StringUTF16.lastIndexOf(src, srcCount, tgt, tgtCount, fromIndex);
1828 }
1829 if (srcCoder == LATIN1) { // && tgtCoder == UTF16
1830 return -1;
1831 }
1832 // srcCoder == UTF16 && tgtCoder == LATIN1
1833 int min = tgtCount - 1;
1834 int i = min + fromIndex;
1835 int strLastIndex = tgtCount - 1;
1836
1837 char strLastChar = (char)(tgt[strLastIndex] & 0xff);
1838 startSearchForLastChar:
1839 while (true) {
1840 while (i >= min && StringUTF16.getChar(src, i) != strLastChar) {
1841 i--;
1842 }
1843 if (i < min) {
1844 return -1;
1845 }
1846 int j = i - 1;
1847 int start = j - strLastIndex;
1848 int k = strLastIndex - 1;
1849 while (j > start) {
1850 if (StringUTF16.getChar(src, j--) != (tgt[k--] & 0xff)) {
1851 i--;
1852 continue startSearchForLastChar;
1853 }
1854 }
1855 return start + 1;
1856 }
1857 }
|
1104 return nonSyncContentEquals((AbstractStringBuilder)cs);
1105 }
1106 }
1107 // Argument is a String
1108 if (cs instanceof String) {
1109 return equals(cs);
1110 }
1111 // Argument is a generic CharSequence
1112 int n = cs.length();
1113 if (n != length()) {
1114 return false;
1115 }
1116 byte[] val = this.value;
1117 if (isLatin1()) {
1118 for (int i = 0; i < n; i++) {
1119 if ((val[i] & 0xff) != cs.charAt(i)) {
1120 return false;
1121 }
1122 }
1123 } else {
1124 // Redundant: n == length() (see earlier check)
1125 checkOffset(n, val.length >> 1);
1126 for (int i = 0; i < n; i++) {
1127 if (StringUTF16.getChar(val, i) != cs.charAt(i)) {
1128 return false;
1129 }
1130 }
1131 }
1132 return true;
1133 }
1134
1135 /**
1136 * Compares this {@code String} to another {@code String}, ignoring case
1137 * considerations. Two strings are considered equal ignoring case if they
1138 * are of the same length and corresponding characters in the two strings
1139 * are equal ignoring case.
1140 *
1141 * <p> Two characters {@code c1} and {@code c2} are considered the same
1142 * ignoring case if at least one of the following is true:
1143 * <ul>
1144 * <li> The two characters are the same (as compared by the
1145 * {@code ==} operator)
1819 if (fromIndex < 0) {
1820 return -1;
1821 }
1822 /* Empty string always matches. */
1823 if (tgtCount == 0) {
1824 return fromIndex;
1825 }
1826 if (srcCoder == tgtCoder) {
1827 return srcCoder == LATIN1
1828 ? StringLatin1.lastIndexOf(src, srcCount, tgt, tgtCount, fromIndex)
1829 : StringUTF16.lastIndexOf(src, srcCount, tgt, tgtCount, fromIndex);
1830 }
1831 if (srcCoder == LATIN1) { // && tgtCoder == UTF16
1832 return -1;
1833 }
1834 // srcCoder == UTF16 && tgtCoder == LATIN1
1835 int min = tgtCount - 1;
1836 int i = min + fromIndex;
1837 int strLastIndex = tgtCount - 1;
1838
1839 char strLastChar = (char) (tgt[strLastIndex] & 0xff);
1840
1841 // Redundant:
1842 // i == min + fromIndex
1843 // fromIndex <= rightIndex (earlier check) ==>
1844 // i <= min + rightIndex == (tgtCount - 1) + (srcCount - tgtCount) == srcCount - 1 ==>
1845 // i <= srcCount - 1
1846 //
1847 // And (srcCount < src.length >> 1) is covered by:
1848 // ASB.lastIndexOf(String str, int fromIndex) {
1849 // checkIndex(count, value.length >> coder);
1850 checkIndex(i, src.length >> 1);
1851
1852 startSearchForLastChar:
1853 while (true) {
1854 while (i >= min && StringUTF16.getChar(src, i) != strLastChar) {
1855 i--;
1856 }
1857 if (i < min) {
1858 return -1;
1859 }
1860 int j = i - 1;
1861 int start = j - strLastIndex;
1862 int k = strLastIndex - 1;
1863 while (j > start) {
1864 if (StringUTF16.getChar(src, j--) != (tgt[k--] & 0xff)) {
1865 i--;
1866 continue startSearchForLastChar;
1867 }
1868 }
1869 return start + 1;
1870 }
1871 }
|