code
stringlengths 11
173k
| docstring
stringlengths 2
593k
| func_name
stringlengths 2
189
| language
stringclasses 1
value | repo
stringclasses 844
values | path
stringlengths 11
294
| url
stringlengths 60
339
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public int getLevelDbm() {
return level;
} |
Returns the detected signal level on this radio chain in dBm (aka RSSI).
@return A signal level in dBm.
| RadioChainInfo::getLevelDbm | java | Reginer/aosp-android-jar | android-35/src/android/net/wifi/nl80211/RadioChainInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/net/wifi/nl80211/RadioChainInfo.java | MIT |
public RadioChainInfo(int chainId, int level) {
this.chainId = chainId;
this.level = level;
} |
Construct a RadioChainInfo.
| RadioChainInfo::RadioChainInfo | java | Reginer/aosp-android-jar | android-35/src/android/net/wifi/nl80211/RadioChainInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/net/wifi/nl80211/RadioChainInfo.java | MIT |
public static int length(String value) {
return value.length();
} | /*
Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
package java.lang;
import java.util.Arrays;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import static java.lang.String.UTF16;
import static java.lang.String.LATIN1;
final class StringUTF16 {
public static byte[] newBytesFor(int len) {
if (len < 0) {
throw new NegativeArraySizeException();
}
if (len > MAX_LENGTH) {
throw new OutOfMemoryError("UTF16 String size is " + len +
", should be less than " + MAX_LENGTH);
}
return new byte[len << 1];
}
@HotSpotIntrinsicCandidate
// intrinsic performs no bounds checks
static void putChar(byte[] val, int index, int c) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
val[index++] = (byte)(c >> HI_BYTE_SHIFT);
val[index] = (byte)(c >> LO_BYTE_SHIFT);
}
@HotSpotIntrinsicCandidate
// intrinsic performs no bounds checks
static char getChar(byte[] val, int index) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
return (char)(((val[index++] & 0xff) << HI_BYTE_SHIFT) |
((val[index] & 0xff) << LO_BYTE_SHIFT));
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of charAt().
// @IntrinsicCandidate
// intrinsic performs no bounds checks
/*
static char getChar(byte[] val, int index) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
return (char)(((val[index++] & 0xff) << HI_BYTE_SHIFT) |
((val[index] & 0xff) << LO_BYTE_SHIFT));
@IntrinsicCandidate
static char getChar(String val, int index) {
return val.charAt(index);
}
// END Android-added: Pass String instead of byte[]; implement in terms of charAt().
public static int length(byte[] value) {
return value.length >> 1;
}
// BEGIN Android-added: Pass String instead of byte[].
/*
public static int length(byte[] value) {
return value.length >> 1;
| StringUTF16::length | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static void getBytes(byte[] value, int srcBegin, int srcEnd, byte dst[], int dstBegin) {
srcBegin <<= 1;
srcEnd <<= 1;
for (int i = srcBegin + (1 >> LO_BYTE_SHIFT); i < srcEnd; i += 2) {
dst[dstBegin++] = value[i];
}
} | /*
Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
package java.lang;
import java.util.Arrays;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import static java.lang.String.UTF16;
import static java.lang.String.LATIN1;
final class StringUTF16 {
public static byte[] newBytesFor(int len) {
if (len < 0) {
throw new NegativeArraySizeException();
}
if (len > MAX_LENGTH) {
throw new OutOfMemoryError("UTF16 String size is " + len +
", should be less than " + MAX_LENGTH);
}
return new byte[len << 1];
}
@HotSpotIntrinsicCandidate
// intrinsic performs no bounds checks
static void putChar(byte[] val, int index, int c) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
val[index++] = (byte)(c >> HI_BYTE_SHIFT);
val[index] = (byte)(c >> LO_BYTE_SHIFT);
}
@HotSpotIntrinsicCandidate
// intrinsic performs no bounds checks
static char getChar(byte[] val, int index) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
return (char)(((val[index++] & 0xff) << HI_BYTE_SHIFT) |
((val[index] & 0xff) << LO_BYTE_SHIFT));
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of charAt().
// @IntrinsicCandidate
// intrinsic performs no bounds checks
/*
static char getChar(byte[] val, int index) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
return (char)(((val[index++] & 0xff) << HI_BYTE_SHIFT) |
((val[index] & 0xff) << LO_BYTE_SHIFT));
@IntrinsicCandidate
static char getChar(String val, int index) {
return val.charAt(index);
}
// END Android-added: Pass String instead of byte[]; implement in terms of charAt().
public static int length(byte[] value) {
return value.length >> 1;
}
// BEGIN Android-added: Pass String instead of byte[].
/*
public static int length(byte[] value) {
return value.length >> 1;
public static int length(String value) {
return value.length();
}
// END Android-added: Pass String instead of byte[].
private static int codePointAt(byte[] value, int index, int end, boolean checked) {
assert index < end;
if (checked) {
checkIndex(index, value);
}
char c1 = getChar(value, index);
if (Character.isHighSurrogate(c1) && ++index < end) {
if (checked) {
checkIndex(index, value);
}
char c2 = getChar(value, index);
if (Character.isLowSurrogate(c2)) {
return Character.toCodePoint(c1, c2);
}
}
return c1;
}
public static int codePointAt(byte[] value, int index, int end) {
return codePointAt(value, index, end, false /* unchecked */);
}
private static int codePointBefore(byte[] value, int index, boolean checked) {
--index;
if (checked) {
checkIndex(index, value);
}
char c2 = getChar(value, index);
if (Character.isLowSurrogate(c2) && index > 0) {
--index;
if (checked) {
checkIndex(index, value);
}
char c1 = getChar(value, index);
if (Character.isHighSurrogate(c1)) {
return Character.toCodePoint(c1, c2);
}
}
return c2;
}
public static int codePointBefore(byte[] value, int index) {
return codePointBefore(value, index, false /* unchecked */);
}
private static int codePointCount(byte[] value, int beginIndex, int endIndex, boolean checked) {
assert beginIndex <= endIndex;
int count = endIndex - beginIndex;
int i = beginIndex;
if (checked && i < endIndex) {
checkBoundsBeginEnd(i, endIndex, value);
}
for (; i < endIndex - 1; ) {
if (Character.isHighSurrogate(getChar(value, i++)) &&
Character.isLowSurrogate(getChar(value, i))) {
count--;
i++;
}
}
return count;
}
public static int codePointCount(byte[] value, int beginIndex, int endIndex) {
return codePointCount(value, beginIndex, endIndex, false /* unchecked */);
}
public static char[] toChars(byte[] value) {
char[] dst = new char[value.length >> 1];
getChars(value, 0, dst.length, dst, 0);
return dst;
}
@HotSpotIntrinsicCandidate
public static byte[] toBytes(char[] value, int off, int len) {
byte[] val = newBytesFor(len);
for (int i = 0; i < len; i++) {
putChar(val, i, value[off]);
off++;
}
return val;
}
public static byte[] compress(char[] val, int off, int len) {
byte[] ret = new byte[len];
if (compress(val, off, ret, 0, len) == len) {
return ret;
}
return null;
}
public static byte[] compress(byte[] val, int off, int len) {
byte[] ret = new byte[len];
if (compress(val, off, ret, 0, len) == len) {
return ret;
}
return null;
}
// compressedCopy char[] -> byte[]
@HotSpotIntrinsicCandidate
public static int compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) {
for (int i = 0; i < len; i++) {
char c = src[srcOff];
if (c > 0xFF) {
len = 0;
break;
}
dst[dstOff] = (byte)c;
srcOff++;
dstOff++;
}
return len;
}
// compressedCopy byte[] -> byte[]
@HotSpotIntrinsicCandidate
public static int compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
// We need a range check here because 'getChar' has no checks
checkBoundsOffCount(srcOff, len, src);
for (int i = 0; i < len; i++) {
char c = getChar(src, srcOff);
if (c > 0xFF) {
len = 0;
break;
}
dst[dstOff] = (byte)c;
srcOff++;
dstOff++;
}
return len;
}
public static byte[] toBytes(int[] val, int index, int len) {
final int end = index + len;
// Pass 1: Compute precise size of char[]
int n = len;
for (int i = index; i < end; i++) {
int cp = val[i];
if (Character.isBmpCodePoint(cp))
continue;
else if (Character.isValidCodePoint(cp))
n++;
else throw new IllegalArgumentException(Integer.toString(cp));
}
// Pass 2: Allocate and fill in <high, low> pair
byte[] buf = newBytesFor(n);
for (int i = index, j = 0; i < end; i++, j++) {
int cp = val[i];
if (Character.isBmpCodePoint(cp)) {
putChar(buf, j, cp);
} else {
putChar(buf, j++, Character.highSurrogate(cp));
putChar(buf, j, Character.lowSurrogate(cp));
}
}
return buf;
}
public static byte[] toBytes(char c) {
byte[] result = new byte[2];
putChar(result, 0, c);
return result;
}
static byte[] toBytesSupplementary(int cp) {
byte[] result = new byte[4];
putChar(result, 0, Character.highSurrogate(cp));
putChar(result, 1, Character.lowSurrogate(cp));
return result;
}
@HotSpotIntrinsicCandidate
public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
// We need a range check here because 'getChar' has no checks
if (srcBegin < srcEnd) {
checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value);
}
for (int i = srcBegin; i < srcEnd; i++) {
dst[dstBegin++] = getChar(value, i);
}
}
/* @see java.lang.String.getBytes(int, int, byte[], int) | StringUTF16::getBytes | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static int compareTo(byte[] value, byte[] other, int len1, int len2) {
checkOffset(len1, value);
checkOffset(len2, other);
return compareValues(value, other, len1, len2);
} | /*
Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
package java.lang;
import java.util.Arrays;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import static java.lang.String.UTF16;
import static java.lang.String.LATIN1;
final class StringUTF16 {
public static byte[] newBytesFor(int len) {
if (len < 0) {
throw new NegativeArraySizeException();
}
if (len > MAX_LENGTH) {
throw new OutOfMemoryError("UTF16 String size is " + len +
", should be less than " + MAX_LENGTH);
}
return new byte[len << 1];
}
@HotSpotIntrinsicCandidate
// intrinsic performs no bounds checks
static void putChar(byte[] val, int index, int c) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
val[index++] = (byte)(c >> HI_BYTE_SHIFT);
val[index] = (byte)(c >> LO_BYTE_SHIFT);
}
@HotSpotIntrinsicCandidate
// intrinsic performs no bounds checks
static char getChar(byte[] val, int index) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
return (char)(((val[index++] & 0xff) << HI_BYTE_SHIFT) |
((val[index] & 0xff) << LO_BYTE_SHIFT));
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of charAt().
// @IntrinsicCandidate
// intrinsic performs no bounds checks
/*
static char getChar(byte[] val, int index) {
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
index <<= 1;
return (char)(((val[index++] & 0xff) << HI_BYTE_SHIFT) |
((val[index] & 0xff) << LO_BYTE_SHIFT));
@IntrinsicCandidate
static char getChar(String val, int index) {
return val.charAt(index);
}
// END Android-added: Pass String instead of byte[]; implement in terms of charAt().
public static int length(byte[] value) {
return value.length >> 1;
}
// BEGIN Android-added: Pass String instead of byte[].
/*
public static int length(byte[] value) {
return value.length >> 1;
public static int length(String value) {
return value.length();
}
// END Android-added: Pass String instead of byte[].
private static int codePointAt(byte[] value, int index, int end, boolean checked) {
assert index < end;
if (checked) {
checkIndex(index, value);
}
char c1 = getChar(value, index);
if (Character.isHighSurrogate(c1) && ++index < end) {
if (checked) {
checkIndex(index, value);
}
char c2 = getChar(value, index);
if (Character.isLowSurrogate(c2)) {
return Character.toCodePoint(c1, c2);
}
}
return c1;
}
public static int codePointAt(byte[] value, int index, int end) {
return codePointAt(value, index, end, false /* unchecked */);
}
private static int codePointBefore(byte[] value, int index, boolean checked) {
--index;
if (checked) {
checkIndex(index, value);
}
char c2 = getChar(value, index);
if (Character.isLowSurrogate(c2) && index > 0) {
--index;
if (checked) {
checkIndex(index, value);
}
char c1 = getChar(value, index);
if (Character.isHighSurrogate(c1)) {
return Character.toCodePoint(c1, c2);
}
}
return c2;
}
public static int codePointBefore(byte[] value, int index) {
return codePointBefore(value, index, false /* unchecked */);
}
private static int codePointCount(byte[] value, int beginIndex, int endIndex, boolean checked) {
assert beginIndex <= endIndex;
int count = endIndex - beginIndex;
int i = beginIndex;
if (checked && i < endIndex) {
checkBoundsBeginEnd(i, endIndex, value);
}
for (; i < endIndex - 1; ) {
if (Character.isHighSurrogate(getChar(value, i++)) &&
Character.isLowSurrogate(getChar(value, i))) {
count--;
i++;
}
}
return count;
}
public static int codePointCount(byte[] value, int beginIndex, int endIndex) {
return codePointCount(value, beginIndex, endIndex, false /* unchecked */);
}
public static char[] toChars(byte[] value) {
char[] dst = new char[value.length >> 1];
getChars(value, 0, dst.length, dst, 0);
return dst;
}
@HotSpotIntrinsicCandidate
public static byte[] toBytes(char[] value, int off, int len) {
byte[] val = newBytesFor(len);
for (int i = 0; i < len; i++) {
putChar(val, i, value[off]);
off++;
}
return val;
}
public static byte[] compress(char[] val, int off, int len) {
byte[] ret = new byte[len];
if (compress(val, off, ret, 0, len) == len) {
return ret;
}
return null;
}
public static byte[] compress(byte[] val, int off, int len) {
byte[] ret = new byte[len];
if (compress(val, off, ret, 0, len) == len) {
return ret;
}
return null;
}
// compressedCopy char[] -> byte[]
@HotSpotIntrinsicCandidate
public static int compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) {
for (int i = 0; i < len; i++) {
char c = src[srcOff];
if (c > 0xFF) {
len = 0;
break;
}
dst[dstOff] = (byte)c;
srcOff++;
dstOff++;
}
return len;
}
// compressedCopy byte[] -> byte[]
@HotSpotIntrinsicCandidate
public static int compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
// We need a range check here because 'getChar' has no checks
checkBoundsOffCount(srcOff, len, src);
for (int i = 0; i < len; i++) {
char c = getChar(src, srcOff);
if (c > 0xFF) {
len = 0;
break;
}
dst[dstOff] = (byte)c;
srcOff++;
dstOff++;
}
return len;
}
public static byte[] toBytes(int[] val, int index, int len) {
final int end = index + len;
// Pass 1: Compute precise size of char[]
int n = len;
for (int i = index; i < end; i++) {
int cp = val[i];
if (Character.isBmpCodePoint(cp))
continue;
else if (Character.isValidCodePoint(cp))
n++;
else throw new IllegalArgumentException(Integer.toString(cp));
}
// Pass 2: Allocate and fill in <high, low> pair
byte[] buf = newBytesFor(n);
for (int i = index, j = 0; i < end; i++, j++) {
int cp = val[i];
if (Character.isBmpCodePoint(cp)) {
putChar(buf, j, cp);
} else {
putChar(buf, j++, Character.highSurrogate(cp));
putChar(buf, j, Character.lowSurrogate(cp));
}
}
return buf;
}
public static byte[] toBytes(char c) {
byte[] result = new byte[2];
putChar(result, 0, c);
return result;
}
static byte[] toBytesSupplementary(int cp) {
byte[] result = new byte[4];
putChar(result, 0, Character.highSurrogate(cp));
putChar(result, 1, Character.lowSurrogate(cp));
return result;
}
@HotSpotIntrinsicCandidate
public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
// We need a range check here because 'getChar' has no checks
if (srcBegin < srcEnd) {
checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value);
}
for (int i = srcBegin; i < srcEnd; i++) {
dst[dstBegin++] = getChar(value, i);
}
}
/* @see java.lang.String.getBytes(int, int, byte[], int)
public static void getBytes(byte[] value, int srcBegin, int srcEnd, byte dst[], int dstBegin) {
srcBegin <<= 1;
srcEnd <<= 1;
for (int i = srcBegin + (1 >> LO_BYTE_SHIFT); i < srcEnd; i += 2) {
dst[dstBegin++] = value[i];
}
}
@HotSpotIntrinsicCandidate
public static boolean equals(byte[] value, byte[] other) {
if (value.length == other.length) {
int len = value.length >> 1;
for (int i = 0; i < len; i++) {
if (getChar(value, i) != getChar(other, i)) {
return false;
}
}
return true;
}
return false;
}
@HotSpotIntrinsicCandidate
public static int compareTo(byte[] value, byte[] other) {
int len1 = length(value);
int len2 = length(other);
return compareValues(value, other, len1, len2);
}
/*
Checks the boundary and then compares the byte arrays.
| StringUTF16::compareTo | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
private static int indexOfSupplementary(byte[] value, int ch, int fromIndex, int max) {
if (Character.isValidCodePoint(ch)) {
final char hi = Character.highSurrogate(ch);
final char lo = Character.lowSurrogate(ch);
checkBoundsBeginEnd(fromIndex, max, value);
for (int i = fromIndex; i < max - 1; i++) {
if (getChar(value, i) == hi && getChar(value, i + 1 ) == lo) {
return i;
}
}
}
return -1;
} |
Handles (rare) calls of indexOf with a supplementary character.
| StringUTF16::indexOfSupplementary | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
| StringUTF16::lastIndexOfSupplementary | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
*/
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
| StringUTF16::indexOfNonWhitespace | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
*/
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
| StringUTF16::lastIndexOfNonWhitespace | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
| StringUTF16::strip | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
| StringUTF16::stripLeading | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
| StringUTF16::stripTrailing | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
| LinesSpliterator::LinesSpliterator | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
| LinesSpliterator::LinesSpliterator | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
| LinesSpliterator::lines | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public static String newString(String val, int index, int len) {
return val.substring(index, index + len);
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
}
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
while (off < end) {
putChar(val, index++, str[off++]);
}
}
public static String newString(byte[] val, int index, int len) {
// Android-changed: Skip compression check because ART's StringFactory will do so.
/*
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
return StringFactory.newStringFromUtf16Bytes(val, index << 1, len);
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of substring().
/*
public static String newString(byte[] val, int index, int len) {
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
}
| LinesSpliterator::newString | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
CharsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
}
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
while (off < end) {
putChar(val, index++, str[off++]);
}
}
public static String newString(byte[] val, int index, int len) {
// Android-changed: Skip compression check because ART's StringFactory will do so.
/*
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
return StringFactory.newStringFromUtf16Bytes(val, index << 1, len);
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of substring().
/*
public static String newString(byte[] val, int index, int len) {
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
}
public static String newString(String val, int index, int len) {
return val.substring(index, index + len);
}
// END Android-added: Pass String instead of byte[]; implement in terms of substring().
public static void fillNull(byte[] val, int index, int end) {
Arrays.fill(val, index << 1, end << 1, (byte)0);
}
static class CharsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CharsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
| CharsSpliteratorForString::CharsSpliteratorForString | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
CharsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
}
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
while (off < end) {
putChar(val, index++, str[off++]);
}
}
public static String newString(byte[] val, int index, int len) {
// Android-changed: Skip compression check because ART's StringFactory will do so.
/*
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
return StringFactory.newStringFromUtf16Bytes(val, index << 1, len);
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of substring().
/*
public static String newString(byte[] val, int index, int len) {
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
}
public static String newString(String val, int index, int len) {
return val.substring(index, index + len);
}
// END Android-added: Pass String instead of byte[]; implement in terms of substring().
public static void fillNull(byte[] val, int index, int end) {
Arrays.fill(val, index << 1, end << 1, (byte)0);
}
static class CharsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CharsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CharsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
| CharsSpliteratorForString::CharsSpliteratorForString | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
CodePointsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
}
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
while (off < end) {
putChar(val, index++, str[off++]);
}
}
public static String newString(byte[] val, int index, int len) {
// Android-changed: Skip compression check because ART's StringFactory will do so.
/*
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
return StringFactory.newStringFromUtf16Bytes(val, index << 1, len);
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of substring().
/*
public static String newString(byte[] val, int index, int len) {
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
}
public static String newString(String val, int index, int len) {
return val.substring(index, index + len);
}
// END Android-added: Pass String instead of byte[]; implement in terms of substring().
public static void fillNull(byte[] val, int index, int end) {
Arrays.fill(val, index << 1, end << 1, (byte)0);
}
static class CharsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CharsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CharsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
CharsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliteratorForString(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
// BEGIN Android-changed: Pass String instead of byte[].
/*
byte[] a; int i, hi; // hoist accesses and checks from loop
String a; int i, hi; // hoist accesses and checks from loop
// END Android-changed: Pass String instead of byte[].
if (action == null)
throw new NullPointerException();
// BEGIN Android-changed: Pass String instead of byte[].
/*
if (((a = array).length >> 1) >= (hi = fence) &&
if (((a = array).length()) >= (hi = fence) &&
// END Android-changed: Pass String instead of byte[].
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
| CodePointsSpliteratorForString::CodePointsSpliteratorForString | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
CodePointsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
}
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
while (off < end) {
putChar(val, index++, str[off++]);
}
}
public static String newString(byte[] val, int index, int len) {
// Android-changed: Skip compression check because ART's StringFactory will do so.
/*
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
return StringFactory.newStringFromUtf16Bytes(val, index << 1, len);
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of substring().
/*
public static String newString(byte[] val, int index, int len) {
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
}
public static String newString(String val, int index, int len) {
return val.substring(index, index + len);
}
// END Android-added: Pass String instead of byte[]; implement in terms of substring().
public static void fillNull(byte[] val, int index, int end) {
Arrays.fill(val, index << 1, end << 1, (byte)0);
}
static class CharsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CharsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CharsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
CharsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliteratorForString(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
// BEGIN Android-changed: Pass String instead of byte[].
/*
byte[] a; int i, hi; // hoist accesses and checks from loop
String a; int i, hi; // hoist accesses and checks from loop
// END Android-changed: Pass String instead of byte[].
if (action == null)
throw new NullPointerException();
// BEGIN Android-changed: Pass String instead of byte[].
/*
if (((a = array).length >> 1) >= (hi = fence) &&
if (((a = array).length()) >= (hi = fence) &&
// END Android-changed: Pass String instead of byte[].
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CodePointsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
| CodePointsSpliteratorForString::CodePointsSpliteratorForString | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
private static int advance(String a, int i, int hi, IntConsumer action) {
// END Android-changed: Pass String instead of byte[].
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
}
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
while (off < end) {
putChar(val, index++, str[off++]);
}
}
public static String newString(byte[] val, int index, int len) {
// Android-changed: Skip compression check because ART's StringFactory will do so.
/*
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
return StringFactory.newStringFromUtf16Bytes(val, index << 1, len);
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of substring().
/*
public static String newString(byte[] val, int index, int len) {
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
}
public static String newString(String val, int index, int len) {
return val.substring(index, index + len);
}
// END Android-added: Pass String instead of byte[]; implement in terms of substring().
public static void fillNull(byte[] val, int index, int end) {
Arrays.fill(val, index << 1, end << 1, (byte)0);
}
static class CharsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CharsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CharsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
CharsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliteratorForString(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
// BEGIN Android-changed: Pass String instead of byte[].
/*
byte[] a; int i, hi; // hoist accesses and checks from loop
String a; int i, hi; // hoist accesses and checks from loop
// END Android-changed: Pass String instead of byte[].
if (action == null)
throw new NullPointerException();
// BEGIN Android-changed: Pass String instead of byte[].
/*
if (((a = array).length >> 1) >= (hi = fence) &&
if (((a = array).length()) >= (hi = fence) &&
// END Android-changed: Pass String instead of byte[].
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CodePointsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
CodePointsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliteratorForString(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliteratorForString(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
// BEGIN Android-changed: Pass String instead of byte[].
/*
byte[] a; int i, hi; // hoist accesses and checks from loop
String a; int i, hi; // hoist accesses and checks from loop
// END Android-changed: Pass String instead of byte[].
if (action == null)
throw new NullPointerException();
// BEGIN Android-changed: Pass String instead of byte[].
/*
if (((a = array).length >> 1) >= (hi = fence) &&
if (((a = array).length()) >= (hi = fence) &&
// END Android-changed: Pass String instead of byte[].
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
// BEGIN Android-changed: Pass String instead of byte[].
/*
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
| CodePointsSpliteratorForString::advance | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
private static void reverseAllValidSurrogatePairs(byte[] val, int count) {
for (int i = 0; i < count - 1; i++) {
char c2 = getChar(val, i);
if (Character.isLowSurrogate(c2)) {
char c1 = getChar(val, i + 1);
if (Character.isHighSurrogate(c1)) {
putChar(val, i++, c1);
putChar(val, i, c2);
}
}
}
} |
Handles (rare) calls of lastIndexOf with a supplementary character.
private static int lastIndexOfSupplementary(final byte[] value, int ch, int fromIndex) {
if (Character.isValidCodePoint(ch)) {
char hi = Character.highSurrogate(ch);
char lo = Character.lowSurrogate(ch);
int i = Math.min(fromIndex, (value.length >> 1) - 2);
for (; i >= 0; i--) {
if (getChar(value, i) == hi && getChar(value, i + 1) == lo) {
return i;
}
}
}
return -1;
}
public static String replace(byte[] value, char oldChar, char newChar) {
int len = value.length >> 1;
int i = -1;
while (++i < len) {
if (getChar(value, i) == oldChar) {
break;
}
}
if (i < len) {
byte buf[] = new byte[value.length];
for (int j = 0; j < i; j++) {
putChar(buf, j, getChar(value, j)); // TBD:arraycopy?
}
while (i < len) {
char c = getChar(value, i);
putChar(buf, i, c == oldChar ? newChar : c);
i++;
}
// Check if we should try to compress to latin1
if (String.COMPACT_STRINGS &&
!StringLatin1.canEncode(oldChar) &&
StringLatin1.canEncode(newChar)) {
byte[] val = compress(buf, 0, len);
if (val != null) {
return new String(val, LATIN1);
}
}
return new String(buf, UTF16);
}
return null;
}
// BEGIN Android-removed: Removed unused code.
/*
public static boolean regionMatchesCI(byte[] value, int toffset,
byte[] other, int ooffset, int len) {
int last = toffset + len;
assert toffset >= 0 && ooffset >= 0;
assert ooffset + len <= length(other);
assert last <= length(value);
while (toffset < last) {
char c1 = getChar(value, toffset++);
char c2 = getChar(other, ooffset++);
if (c1 == c2) {
continue;
}
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
return false;
}
return true;
}
public static boolean regionMatchesCI_Latin1(byte[] value, int toffset,
byte[] other, int ooffset,
int len) {
return StringLatin1.regionMatchesCI_UTF16(other, ooffset, value, toffset, len);
}
public static String toLowerCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toLowerCase(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len)
return str;
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// lowerCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toLowerCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toLowerCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (cp == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
Character.isSurrogate((char)cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
if (cp == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
return toLowerCaseEx(str, value, result, i, locale, true);
}
cp = Character.toLowerCase(cp);
if (!Character.isBmpCodePoint(cp)) {
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toLowerCaseEx(String str, byte[] value,
byte[] result, int first, Locale locale,
boolean localeDependent) {
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int lowerChar;
char[] lowerCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent ||
srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale);
} else {
lowerChar = Character.toLowerCase(srcChar);
}
if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp
putChar(result, resultOffset++, lowerChar);
} else {
if (lowerChar == Character.ERROR) {
lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale);
} else {
lowerCharArray = Character.toChars(lowerChar);
}
/* Grow result if needed *
int mapLen = lowerCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, lowerCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
public static String toUpperCase(String str, byte[] value, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
int first;
boolean hasSurr = false;
final int len = value.length >> 1;
// Now check if there are any characters that need to be changed, or are surrogate
for (first = 0 ; first < len; first++) {
int cp = (int)getChar(value, first);
if (Character.isSurrogate((char)cp)) {
hasSurr = true;
break;
}
if (cp != Character.toUpperCaseEx(cp)) { // no need to check Character.ERROR
break;
}
}
if (first == len) {
return str;
}
byte[] result = new byte[value.length];
System.arraycopy(value, 0, result, 0, first << 1); // Just copy the first few
// upperCase characters.
String lang = locale.getLanguage();
if (lang == "tr" || lang == "az" || lang == "lt") {
return toUpperCaseEx(str, value, result, first, locale, true);
}
if (hasSurr) {
return toUpperCaseEx(str, value, result, first, locale, false);
}
int bits = 0;
for (int i = first; i < len; i++) {
int cp = (int)getChar(value, i);
if (Character.isSurrogate((char)cp)) {
return toUpperCaseEx(str, value, result, i, locale, false);
}
cp = Character.toUpperCaseEx(cp);
if (!Character.isBmpCodePoint(cp)) { // Character.ERROR is not bmp
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
private static String toUpperCaseEx(String str, byte[] value,
byte[] result, int first,
Locale locale, boolean localeDependent)
{
assert(result.length == value.length);
assert(first >= 0);
int resultOffset = first;
int length = value.length >> 1;
int srcCount;
for (int i = first; i < length; i += srcCount) {
int srcChar = getChar(value, i);
int upperChar;
char[] upperCharArray;
srcCount = 1;
if (Character.isSurrogate((char)srcChar)) {
srcChar = codePointAt(value, i, length);
srcCount = Character.charCount(srcChar);
}
if (localeDependent) {
upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale);
} else {
upperChar = Character.toUpperCaseEx(srcChar);
}
if (Character.isBmpCodePoint(upperChar)) {
putChar(result, resultOffset++, upperChar);
} else {
if (upperChar == Character.ERROR) {
if (localeDependent) {
upperCharArray =
ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
} else {
upperCharArray = Character.toUpperCaseCharArray(srcChar);
}
} else {
upperCharArray = Character.toChars(upperChar);
}
/* Grow result if needed *
int mapLen = upperCharArray.length;
if (mapLen > srcCount) {
byte[] result2 = newBytesFor((result.length >> 1) + mapLen - srcCount);
System.arraycopy(result, 0, result2, 0, resultOffset << 1);
result = result2;
}
assert resultOffset >= 0;
assert resultOffset + mapLen <= length(result);
for (int x = 0; x < mapLen; ++x) {
putChar(result, resultOffset++, upperCharArray[x]);
}
}
}
return newString(result, 0, resultOffset);
}
// END Android-removed: Removed unused code.
public static String trim(byte[] value) {
int length = value.length >> 1;
int len = length;
int st = 0;
while (st < len && getChar(value, st) <= ' ') {
st++;
}
while (st < len && getChar(value, len - 1) <= ' ') {
len--;
}
return ((st > 0) || (len < length )) ?
// Android-changed: Avoid byte[] allocation.
// new String(Arrays.copyOfRange(value, st << 1, len << 1), UTF16) :
StringFactory.newStringFromUtf16Bytes(value, st << 1, len - st) :
null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
public static int indexOfNonWhitespace(String value) {
int length = value.length();
int left = 0;
while (left < length) {
/*
int codepoint = codePointAt(value, left, length);
int codepoint = value.codePointAt(left);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
left += Character.charCount(codepoint);
}
return left;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length >> 1;
int right = length;
public static int lastIndexOfNonWhitespace(String value) {
int right = value.length();
while (0 < right) {
/*
int codepoint = codePointBefore(value, right);
int codepoint = value.codePointBefore(right);
// END Android-changed: Pass String instead of byte[].
if (codepoint != ' ' && codepoint != '\t' && !Character.isWhitespace(codepoint)) {
break;
}
right -= Character.charCount(codepoint);
}
return right;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String strip(byte[] value) {
int length = value.length >> 1;
public static String strip(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
return ((left > 0) || (right < length)) ? newString(value, left, right - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripLeading(byte[] value) {
int length = value.length >> 1;
public static String stripLeading(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int left = indexOfNonWhitespace(value);
if (left == length) {
return "";
}
return (left != 0) ? newString(value, left, length - left) : null;
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
public static String stripTrailing(byte[] value) {
int length = value.length >> 1;
public static String stripTrailing(String value) {
int length = value.length();
// END Android-changed: Pass String instead of byte[].
int right = lastIndexOfNonWhitespace(value);
if (right == 0) {
return "";
}
return (right != length) ? newString(value, 0, right) : null;
}
private final static class LinesSpliterator implements Spliterator<String> {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private byte[] value;
private String value;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value) {
this(value, 0, value.length >>> 1);
LinesSpliterator(String value) {
this(value, 0, value.length());
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
LinesSpliterator(byte[] value, int start, int length) {
LinesSpliterator(String value, int start, int length) {
// END Android-changed: Pass String instead of byte[].
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
char ch = getChar(value, current);
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
if (getChar(value, start) == '\r') {
int next = start + 1;
if (next < fence && getChar(value, next) == '\n') {
return next + 1;
}
}
return start + 1;
}
return fence;
}
private String next() {
int start = index;
int end = indexOfLineSeparator(start);
index = skipLineSeparator(end);
return newString(value, start, end - start);
}
@Override
public boolean tryAdvance(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("tryAdvance action missing");
}
if (index != fence) {
action.accept(next());
return true;
}
return false;
}
@Override
public void forEachRemaining(Consumer<? super String> action) {
if (action == null) {
throw new NullPointerException("forEachRemaining action missing");
}
while (index != fence) {
action.accept(next());
}
}
@Override
public Spliterator<String> trySplit() {
int half = (fence + index) >>> 1;
int mid = skipLineSeparator(indexOfLineSeparator(half));
if (mid < fence) {
int start = index;
index = mid;
return new LinesSpliterator(value, start, mid - start);
}
return null;
}
@Override
public long estimateSize() {
return fence - index + 1;
}
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
static Stream<String> lines(byte[] value) {
static Stream<String> lines(String value) {
return StreamSupport.stream(new LinesSpliterator(value), false);
// END Android-changed: Pass String instead of byte[].
}
private static void putChars(byte[] val, int index, char[] str, int off, int end) {
while (off < end) {
putChar(val, index++, str[off++]);
}
}
public static String newString(byte[] val, int index, int len) {
// Android-changed: Skip compression check because ART's StringFactory will do so.
/*
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
return StringFactory.newStringFromUtf16Bytes(val, index << 1, len);
}
// BEGIN Android-added: Pass String instead of byte[]; implement in terms of substring().
/*
public static String newString(byte[] val, int index, int len) {
if (String.COMPACT_STRINGS) {
byte[] buf = compress(val, index, len);
if (buf != null) {
return new String(buf, LATIN1);
}
}
int last = index + len;
return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
}
public static String newString(String val, int index, int len) {
return val.substring(index, index + len);
}
// END Android-added: Pass String instead of byte[]; implement in terms of substring().
public static void fillNull(byte[] val, int index, int end) {
Arrays.fill(val, index << 1, end << 1, (byte)0);
}
static class CharsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliterator implements Spliterator.OfInt {
private final byte[] array;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
}
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliterator(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
byte[] a; int i, hi; // hoist accesses and checks from loop
if (action == null)
throw new NullPointerException();
if (((a = array).length >> 1) >= (hi = fence) &&
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CharsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CharsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CharsSpliterator(byte[] array, int origin, int fence, int acs) {
CharsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED | Spliterator.SIZED
| Spliterator.SUBSIZED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid)
? null
: new CharsSpliteratorForString(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
// BEGIN Android-changed: Pass String instead of byte[].
/*
byte[] a; int i, hi; // hoist accesses and checks from loop
String a; int i, hi; // hoist accesses and checks from loop
// END Android-changed: Pass String instead of byte[].
if (action == null)
throw new NullPointerException();
// BEGIN Android-changed: Pass String instead of byte[].
/*
if (((a = array).length >> 1) >= (hi = fence) &&
if (((a = array).length()) >= (hi = fence) &&
// END Android-changed: Pass String instead of byte[].
(i = index) >= 0 && i < (index = hi)) {
do {
action.accept(charAt(a, i));
} while (++i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
static class CodePointsSpliteratorForString implements Spliterator.OfInt {
// BEGIN Android-changed: Pass String instead of byte[].
/*
private final byte[] array;
private final String array;
// END Android-changed: Pass String instead of byte[].
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int cs;
// BEGIN Android-changed: Pass String instead of byte[].
/*
CodePointsSpliterator(byte[] array, int acs) {
this(array, 0, array.length >> 1, acs);
CodePointsSpliteratorForString(String array, int acs) {
this(array, 0, array.length(), acs);
// END Android-changed: Pass String instead of byte[].
}
// BEGIN Android-changed: Pass String instead of byte[].
/*
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
CodePointsSpliteratorForString(String array, int origin, int fence, int acs) {
// END Android-changed: Pass String instead of byte[].
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
@Override
public OfInt trySplit() {
int lo = index, mid = (lo + fence) >>> 1;
if (lo >= mid)
return null;
int midOneLess;
// If the mid-point intersects a surrogate pair
if (Character.isLowSurrogate(charAt(array, mid)) &&
Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
// If there is only one pair it cannot be split
if (lo >= midOneLess)
return null;
// Shift the mid-point to align with the surrogate pair
return new CodePointsSpliteratorForString(array, lo, index = midOneLess, cs);
}
return new CodePointsSpliteratorForString(array, lo, index = mid, cs);
}
@Override
public void forEachRemaining(IntConsumer action) {
// BEGIN Android-changed: Pass String instead of byte[].
/*
byte[] a; int i, hi; // hoist accesses and checks from loop
String a; int i, hi; // hoist accesses and checks from loop
// END Android-changed: Pass String instead of byte[].
if (action == null)
throw new NullPointerException();
// BEGIN Android-changed: Pass String instead of byte[].
/*
if (((a = array).length >> 1) >= (hi = fence) &&
if (((a = array).length()) >= (hi = fence) &&
// END Android-changed: Pass String instead of byte[].
(i = index) >= 0 && i < (index = hi)) {
do {
i = advance(a, i, hi, action);
} while (i < hi);
}
}
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
index = advance(array, index, fence, action);
return true;
}
return false;
}
// Advance one code point from the index, i, and return the next
// index to advance from
// BEGIN Android-changed: Pass String instead of byte[].
/*
private static int advance(byte[] a, int i, int hi, IntConsumer action) {
private static int advance(String a, int i, int hi, IntConsumer action) {
// END Android-changed: Pass String instead of byte[].
char c1 = charAt(a, i++);
int cp = c1;
if (Character.isHighSurrogate(c1) && i < hi) {
char c2 = charAt(a, i);
if (Character.isLowSurrogate(c2)) {
i++;
cp = Character.toCodePoint(c1, c2);
}
}
action.accept(cp);
return i;
}
@Override
public long estimateSize() { return (long)(fence - index); }
@Override
public int characteristics() {
return cs;
}
}
////////////////////////////////////////////////////////////////
public static void putCharSB(byte[] val, int index, int c) {
checkIndex(index, val);
putChar(val, index, c);
}
public static void putCharsSB(byte[] val, int index, char[] ca, int off, int end) {
checkBoundsBeginEnd(index, index + end - off, val);
putChars(val, index, ca, off, end);
}
public static void putCharsSB(byte[] val, int index, CharSequence s, int off, int end) {
checkBoundsBeginEnd(index, index + end - off, val);
for (int i = off; i < end; i++) {
putChar(val, index++, s.charAt(i));
}
}
public static int codePointAtSB(byte[] val, int index, int end) {
return codePointAt(val, index, end, true /* checked */);
}
public static int codePointBeforeSB(byte[] val, int index) {
return codePointBefore(val, index, true /* checked */);
}
public static int codePointCountSB(byte[] val, int beginIndex, int endIndex) {
return codePointCount(val, beginIndex, endIndex, true /* checked */);
}
public static int getChars(int i, int begin, int end, byte[] value) {
checkBoundsBeginEnd(begin, end, value);
int pos = getChars(i, end, value);
assert begin == pos;
return pos;
}
public static int getChars(long l, int begin, int end, byte[] value) {
checkBoundsBeginEnd(begin, end, value);
int pos = getChars(l, end, value);
assert begin == pos;
return pos;
}
public static boolean contentEquals(byte[] v1, byte[] v2, int len) {
checkBoundsOffCount(0, len, v2);
for (int i = 0; i < len; i++) {
if ((char)(v1[i] & 0xff) != getChar(v2, i)) {
return false;
}
}
return true;
}
public static boolean contentEquals(byte[] value, CharSequence cs, int len) {
checkOffset(len, value);
for (int i = 0; i < len; i++) {
if (getChar(value, i) != cs.charAt(i)) {
return false;
}
}
return true;
}
public static int putCharsAt(byte[] value, int i, char c1, char c2, char c3, char c4) {
int end = i + 4;
checkBoundsBeginEnd(i, end, value);
putChar(value, i++, c1);
putChar(value, i++, c2);
putChar(value, i++, c3);
putChar(value, i++, c4);
assert(i == end);
return end;
}
public static int putCharsAt(byte[] value, int i, char c1, char c2, char c3, char c4, char c5) {
int end = i + 5;
checkBoundsBeginEnd(i, end, value);
putChar(value, i++, c1);
putChar(value, i++, c2);
putChar(value, i++, c3);
putChar(value, i++, c4);
putChar(value, i++, c5);
assert(i == end);
return end;
}
public static char charAt(byte[] value, int index) {
checkIndex(index, value);
return getChar(value, index);
}
// BEGIN Android-added: Pass String instead of byte[].
public static char charAt(String value, int index) {
checkIndex(index, value);
return getChar(value, index);
}
// END Android-added: Pass String instead of byte[].
public static void reverse(byte[] val, int count) {
checkOffset(count, val);
int n = count - 1;
boolean hasSurrogates = false;
for (int j = (n-1) >> 1; j >= 0; j--) {
int k = n - j;
char cj = getChar(val, j);
char ck = getChar(val, k);
putChar(val, j, ck);
putChar(val, k, cj);
if (Character.isSurrogate(cj) ||
Character.isSurrogate(ck)) {
hasSurrogates = true;
}
}
if (hasSurrogates) {
reverseAllValidSurrogatePairs(val, count);
}
}
/** Outlined helper method for reverse() | CodePointsSpliteratorForString::reverseAllValidSurrogatePairs | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
static int getChars(int i, int index, byte[] buf) {
int q, r;
int charPos = index;
boolean negative = (i < 0);
if (!negative) {
i = -i;
}
// Get 2 digits/iteration using ints
while (i <= -100) {
q = i / 100;
r = (q * 100) - i;
i = q;
putChar(buf, --charPos, Integer.DigitOnes[r]);
putChar(buf, --charPos, Integer.DigitTens[r]);
}
// We know there are at most two digits left at this point.
q = i / 10;
r = (q * 10) - i;
putChar(buf, --charPos, '0' + r);
// Whatever left is the remaining digit.
if (q < 0) {
putChar(buf, --charPos, '0' - q);
}
if (negative) {
putChar(buf, --charPos, '-');
}
return charPos;
} |
This is a variant of {@link Integer#getChars(int, int, byte[])}, but for
UTF-16 coder.
@param i value to convert
@param index next index, after the least significant digit
@param buf target buffer, UTF16-coded.
@return index of the most significant digit or minus sign, if present
| CodePointsSpliteratorForString::getChars | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
static int getChars(long i, int index, byte[] buf) {
long q;
int r;
int charPos = index;
boolean negative = (i < 0);
if (!negative) {
i = -i;
}
// Get 2 digits/iteration using longs until quotient fits into an int
while (i <= Integer.MIN_VALUE) {
q = i / 100;
r = (int)((q * 100) - i);
i = q;
putChar(buf, --charPos, Integer.DigitOnes[r]);
putChar(buf, --charPos, Integer.DigitTens[r]);
}
// Get 2 digits/iteration using ints
int q2;
int i2 = (int)i;
while (i2 <= -100) {
q2 = i2 / 100;
r = (q2 * 100) - i2;
i2 = q2;
putChar(buf, --charPos, Integer.DigitOnes[r]);
putChar(buf, --charPos, Integer.DigitTens[r]);
}
// We know there are at most two digits left at this point.
q2 = i2 / 10;
r = (q2 * 10) - i2;
putChar(buf, --charPos, '0' + r);
// Whatever left is the remaining digit.
if (q2 < 0) {
putChar(buf, --charPos, '0' - q2);
}
if (negative) {
putChar(buf, --charPos, '-');
}
return charPos;
} |
This is a variant of {@link Long#getChars(long, int, byte[])}, but for
UTF-16 coder.
@param i value to convert
@param index next index, after the least significant digit
@param buf target buffer, UTF16-coded.
@return index of the most significant digit or minus sign, if present
| CodePointsSpliteratorForString::getChars | java | Reginer/aosp-android-jar | android-34/src/java/lang/StringUTF16.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/java/lang/StringUTF16.java | MIT |
public void setAidl(HalVersion halVersion, android.hardware.radio.sim.IRadioSim sim) {
mHalVersion = halVersion;
mSimProxy = sim;
mIsAidl = true;
Rlog.d(TAG, "AIDL initialized");
} |
Set IRadioSim as the AIDL implementation for RadioServiceProxy
@param halVersion Radio HAL version
@param sim IRadioSim implementation
| RadioSimProxy::setAidl | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public android.hardware.radio.sim.IRadioSim getAidl() {
return mSimProxy;
} |
Get the AIDL implementation of RadioSimProxy
@return IRadioSim implementation
| RadioSimProxy::getAidl | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void areUiccApplicationsEnabled(int serial) throws RemoteException {
if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
if (isAidl()) {
mSimProxy.areUiccApplicationsEnabled(serial);
} else {
((android.hardware.radio.V1_5.IRadio) mRadioProxy).areUiccApplicationsEnabled(serial);
}
} |
Call IRadioSim#areUiccApplicationsEnabled
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::areUiccApplicationsEnabled | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid)
throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid);
} else {
mRadioProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid);
}
} |
Call IRadioSim#changeIccPin2ForApp
@param serial Serial number of request
@param oldPin2 Old PIN value
@param newPin2 New PIN value
@param aid Application ID
@throws RemoteException
| RadioSimProxy::changeIccPin2ForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void changeIccPinForApp(int serial, String oldPin, String newPin, String aid)
throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.changeIccPinForApp(serial, oldPin, newPin, aid);
} else {
mRadioProxy.changeIccPinForApp(serial, oldPin, newPin, aid);
}
} |
Call IRadioSim#changeIccPinForApp
@param serial Serial number of request
@param oldPin Old PIN value
@param newPin New PIN value
@param aid Application ID
@throws RemoteException
| RadioSimProxy::changeIccPinForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void enableUiccApplications(int serial, boolean enable) throws RemoteException {
if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
if (isAidl()) {
mSimProxy.enableUiccApplications(serial, enable);
} else {
((android.hardware.radio.V1_5.IRadio) mRadioProxy).enableUiccApplications(
serial, enable);
}
} |
Call IRadioSim#enableUiccApplications
@param serial Serial number of request
@param enable Whether or not to enable UiccApplications on the SIM
@throws RemoteException
| RadioSimProxy::enableUiccApplications | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getAllowedCarriers(int serial) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.getAllowedCarriers(serial);
} else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) {
((android.hardware.radio.V1_4.IRadio) mRadioProxy).getAllowedCarriers_1_4(serial);
} else {
mRadioProxy.getAllowedCarriers(serial);
}
} |
Call IRadioSim#getAllowedCarriers
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::getAllowedCarriers | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getCdmaSubscription(int serial) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.getCdmaSubscription(serial);
} else {
mRadioProxy.getCDMASubscription(serial);
}
} |
Call IRadioSim#getCdmaSubscription
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::getCdmaSubscription | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getCdmaSubscriptionSource(int serial) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.getCdmaSubscriptionSource(serial);
} else {
mRadioProxy.getCdmaSubscriptionSource(serial);
}
} |
Call IRadioSim#getCdmaSubscriptionSource
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::getCdmaSubscriptionSource | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getFacilityLockForApp(int serial, String facility, String password,
int serviceClass, String appId) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId);
} else {
mRadioProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId);
}
} |
Call IRadioSim#getFacilityLockForApp
@param serial Serial number of request
@param facility One of CB_FACILTY_*
@param password Password or "" if not required
@param serviceClass Sum of SERVICE_CLASS_*
@param appId Application ID or null if none
@throws RemoteException
| RadioSimProxy::getFacilityLockForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getIccCardStatus(int serial) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.getIccCardStatus(serial);
} else {
mRadioProxy.getIccCardStatus(serial);
}
} |
Call IRadioSim#getIccCardStatus
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::getIccCardStatus | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getImsiForApp(int serial, String aid) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.getImsiForApp(serial, aid);
} else {
mRadioProxy.getImsiForApp(serial, aid);
}
} |
Call IRadioSim#getImsiForApp
@param serial Serial number of request
@param aid Application ID
@throws RemoteException
| RadioSimProxy::getImsiForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getSimPhonebookCapacity(int serial) throws RemoteException {
if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
if (isAidl()) {
mSimProxy.getSimPhonebookCapacity(serial);
} else {
((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookCapacity(serial);
}
} |
Call IRadioSim#getSimPhonebookCapacity
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::getSimPhonebookCapacity | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void getSimPhonebookRecords(int serial) throws RemoteException {
if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
if (isAidl()) {
mSimProxy.getSimPhonebookRecords(serial);
} else {
((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookRecords(serial);
}
} |
Call IRadioSim#getSimPhonebookRecords
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::getSimPhonebookRecords | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void iccCloseLogicalChannel(int serial, int channelId) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.iccCloseLogicalChannel(serial, channelId);
} else {
mRadioProxy.iccCloseLogicalChannel(serial, channelId);
}
} |
Call IRadioSim#iccCloseLogicalChannel
@param serial Serial number of request
@param channelId Channel ID of the channel to be closed
@throws RemoteException
| RadioSimProxy::iccCloseLogicalChannel | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void iccIoForApp(int serial, int command, int fileId, String path, int p1, int p2,
int p3, String data, String pin2, String aid) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
android.hardware.radio.sim.IccIo iccIo = new android.hardware.radio.sim.IccIo();
iccIo.command = command;
iccIo.fileId = fileId;
iccIo.path = path;
iccIo.p1 = p1;
iccIo.p2 = p2;
iccIo.p3 = p3;
iccIo.data = data;
iccIo.pin2 = pin2;
iccIo.aid = aid;
mSimProxy.iccIoForApp(serial, iccIo);
} else {
android.hardware.radio.V1_0.IccIo iccIo = new android.hardware.radio.V1_0.IccIo();
iccIo.command = command;
iccIo.fileId = fileId;
iccIo.path = path;
iccIo.p1 = p1;
iccIo.p2 = p2;
iccIo.p3 = p3;
iccIo.data = data;
iccIo.pin2 = pin2;
iccIo.aid = aid;
mRadioProxy.iccIOForApp(serial, iccIo);
}
} |
Call IRadioSim#iccIoForApp
@param serial Serial number of request
@param command Command
@param fileId File ID
@param path Path
@param p1 P1 value of the command
@param p2 P2 value of the command
@param p3 P3 value of the command
@param data Data to be sent
@param pin2 PIN 2 value
@param aid Application ID
@throws RemoteException
| RadioSimProxy::iccIoForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void iccOpenLogicalChannel(int serial, String aid, int p2) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.iccOpenLogicalChannel(serial, aid, p2);
} else {
mRadioProxy.iccOpenLogicalChannel(serial, aid, p2);
}
} |
Call IRadioSim#iccOpenLogicalChannel
@param serial Serial number of request
@param aid Application ID
@param p2 P2 value of the command
@throws RemoteException
| RadioSimProxy::iccOpenLogicalChannel | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void iccTransmitApduBasicChannel(int serial, int cla, int instruction, int p1, int p2,
int p3, String data) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.iccTransmitApduBasicChannel(serial,
RILUtils.convertToHalSimApduAidl(0, cla, instruction, p1, p2, p3, data));
} else {
mRadioProxy.iccTransmitApduBasicChannel(serial,
RILUtils.convertToHalSimApdu(0, cla, instruction, p1, p2, p3, data));
}
} |
Call IRadioSim#iccTransmitApduBasicChannel
@param serial Serial number of request
@param cla Class of the command
@param instruction Instruction of the command
@param p1 P1 value of the command
@param p2 P2 value of the command
@param p3 P3 value of the command
@param data Data to be sent
@throws RemoteException
| RadioSimProxy::iccTransmitApduBasicChannel | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction,
int p1, int p2, int p3, String data) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.iccTransmitApduLogicalChannel(serial,
RILUtils.convertToHalSimApduAidl(channel, cla, instruction, p1, p2, p3, data));
} else {
mRadioProxy.iccTransmitApduLogicalChannel(serial,
RILUtils.convertToHalSimApdu(channel, cla, instruction, p1, p2, p3, data));
}
} |
Call IRadioSim#iccTransmitApduLogicalChannel
@param serial Serial number of request
@param channel Channel ID of the channel to use for communication
@param cla Class of the command
@param instruction Instruction of the command
@param p1 P1 value of the command
@param p2 P2 value of the command
@param p3 P3 value of the command
@param data Data to be sent
@throws RemoteException
| RadioSimProxy::iccTransmitApduLogicalChannel | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void reportStkServiceIsRunning(int serial) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.reportStkServiceIsRunning(serial);
} else {
mRadioProxy.reportStkServiceIsRunning(serial);
}
} |
Call IRadioSim#reportStkServiceIsRunning
@param serial Serial number of request
@throws RemoteException
| RadioSimProxy::reportStkServiceIsRunning | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void requestIccSimAuthentication(int serial, int authContext, String authData,
String aid) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.requestIccSimAuthentication(serial, authContext, authData, aid);
} else {
mRadioProxy.requestIccSimAuthentication(serial, authContext, authData, aid);
}
} |
Call IRadioSim#requestIccSimAuthentication
@param serial Serial number of request
@param authContext P2 parameter that specifies the authentication context
@param authData Authentication challenge data
@param aid Application ID of the application/slot to send the auth command to
@throws RemoteException
| RadioSimProxy::requestIccSimAuthentication | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void sendEnvelope(int serial, String contents) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.sendEnvelope(serial, contents);
} else {
mRadioProxy.sendEnvelope(serial, contents);
}
} |
Call IRadioSim#sendEnvelope
@param serial Serial number of request
@param contents String containing SAT/USAT response in hexadecimal format starting with
command tag
@throws RemoteException
| RadioSimProxy::sendEnvelope | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void sendEnvelopeWithStatus(int serial, String contents) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.sendEnvelopeWithStatus(serial, contents);
} else {
mRadioProxy.sendEnvelopeWithStatus(serial, contents);
}
} |
Call IRadioSim#sendEnvelopeWithStatus
@param serial Serial number of request
@param contents String containing SAT/USAT response in hexadecimal format starting with
command tag
@throws RemoteException
| RadioSimProxy::sendEnvelopeWithStatus | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void sendTerminalResponseToSim(int serial, String contents) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.sendTerminalResponseToSim(serial, contents);
} else {
mRadioProxy.sendTerminalResponseToSim(serial, contents);
}
} |
Call IRadioSim#sendTerminalResponseToSim
@param serial Serial number of request
@param contents String containing SAT/USAT response in hexadecimal format starting with
first byte of response data
@throws RemoteException
| RadioSimProxy::sendTerminalResponseToSim | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void setAllowedCarriers(int serial, CarrierRestrictionRules carrierRestrictionRules,
Message result) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
// Prepare structure with allowed list, excluded list and priority
android.hardware.radio.sim.CarrierRestrictions carrierRestrictions =
new android.hardware.radio.sim.CarrierRestrictions();
carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionListAidl(
carrierRestrictionRules.getAllowedCarriers());
carrierRestrictions.excludedCarriers = RILUtils.convertToHalCarrierRestrictionListAidl(
carrierRestrictionRules.getExcludedCarriers());
carrierRestrictions.allowedCarriersPrioritized =
(carrierRestrictionRules.getDefaultCarrierRestriction()
== CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
mSimProxy.setAllowedCarriers(serial, carrierRestrictions,
RILUtils.convertToHalSimLockMultiSimPolicyAidl(
carrierRestrictionRules.getMultiSimPolicy()));
} else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) {
// Prepare structure with allowed list, excluded list and priority
android.hardware.radio.V1_4.CarrierRestrictionsWithPriority carrierRestrictions =
new android.hardware.radio.V1_4.CarrierRestrictionsWithPriority();
carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionList(
carrierRestrictionRules.getAllowedCarriers());
carrierRestrictions.excludedCarriers = RILUtils.convertToHalCarrierRestrictionList(
carrierRestrictionRules.getExcludedCarriers());
carrierRestrictions.allowedCarriersPrioritized =
(carrierRestrictionRules.getDefaultCarrierRestriction()
== CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
((android.hardware.radio.V1_4.IRadio) mRadioProxy).setAllowedCarriers_1_4(
serial, carrierRestrictions, RILUtils.convertToHalSimLockMultiSimPolicy(
carrierRestrictionRules.getMultiSimPolicy()));
} else {
boolean isAllCarriersAllowed = carrierRestrictionRules.isAllCarriersAllowed();
boolean supported = (isAllCarriersAllowed
|| (carrierRestrictionRules.getExcludedCarriers().isEmpty()
&& (carrierRestrictionRules.getDefaultCarrierRestriction()
== CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED)))
&& (RILUtils.convertToHalSimLockMultiSimPolicy(
carrierRestrictionRules.getMultiSimPolicy())
== android.hardware.radio.V1_4.SimLockMultiSimPolicy.NO_MULTISIM_POLICY);
if (!supported) {
// Feature is not supported by IRadio interface
if (result != null) {
AsyncResult.forMessage(result, null,
CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
result.sendToTarget();
}
return;
}
// Prepare structure with allowed list
android.hardware.radio.V1_0.CarrierRestrictions carrierRestrictions =
new android.hardware.radio.V1_0.CarrierRestrictions();
carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionList(
carrierRestrictionRules.getAllowedCarriers());
mRadioProxy.setAllowedCarriers(serial, isAllCarriersAllowed, carrierRestrictions);
}
} |
Call IRadioSim#setAllowedCarriers
@param serial Serial number of request
@param carrierRestrictionRules Allowed carriers
@param result Result to return in case of error
@throws RemoteException
| RadioSimProxy::setAllowedCarriers | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void setCarrierInfoForImsiEncryption(int serial, ImsiEncryptionInfo imsiEncryptionInfo)
throws RemoteException {
if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_1)) return;
if (isAidl()) {
android.hardware.radio.sim.ImsiEncryptionInfo halImsiInfo =
new android.hardware.radio.sim.ImsiEncryptionInfo();
halImsiInfo.mnc = imsiEncryptionInfo.getMnc();
halImsiInfo.mcc = imsiEncryptionInfo.getMcc();
halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
if (imsiEncryptionInfo.getExpirationTime() != null) {
halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
}
halImsiInfo.carrierKey = imsiEncryptionInfo.getPublicKey().getEncoded();
halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType();
mSimProxy.setCarrierInfoForImsiEncryption(serial, halImsiInfo);
} else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
android.hardware.radio.V1_6.ImsiEncryptionInfo halImsiInfo =
new android.hardware.radio.V1_6.ImsiEncryptionInfo();
halImsiInfo.base.mnc = imsiEncryptionInfo.getMnc();
halImsiInfo.base.mcc = imsiEncryptionInfo.getMcc();
halImsiInfo.base.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
if (imsiEncryptionInfo.getExpirationTime() != null) {
halImsiInfo.base.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
}
for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
halImsiInfo.base.carrierKey.add(new Byte(b));
}
halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType();
((android.hardware.radio.V1_6.IRadio) mRadioProxy).setCarrierInfoForImsiEncryption_1_6(
serial, halImsiInfo);
} else {
android.hardware.radio.V1_1.ImsiEncryptionInfo halImsiInfo =
new android.hardware.radio.V1_1.ImsiEncryptionInfo();
halImsiInfo.mnc = imsiEncryptionInfo.getMnc();
halImsiInfo.mcc = imsiEncryptionInfo.getMcc();
halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
if (imsiEncryptionInfo.getExpirationTime() != null) {
halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
}
for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
halImsiInfo.carrierKey.add(new Byte(b));
}
((android.hardware.radio.V1_1.IRadio) mRadioProxy).setCarrierInfoForImsiEncryption(
serial, halImsiInfo);
}
} |
Call IRadioSim#setCarrierInfoForImsiEncryption
@param serial Serial number of request
@param imsiEncryptionInfo ImsiEncryptionInfo
@throws RemoteException
| RadioSimProxy::setCarrierInfoForImsiEncryption | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void setCdmaSubscriptionSource(int serial, int cdmaSub) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.setCdmaSubscriptionSource(serial, cdmaSub);
} else {
mRadioProxy.setCdmaSubscriptionSource(serial, cdmaSub);
}
} |
Call IRadioSim#setCdmaSubscriptionSource
@param serial Serial number of request
@param cdmaSub One of CDMA_SUBSCRIPTION_*
@throws RemoteException
| RadioSimProxy::setCdmaSubscriptionSource | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void setFacilityLockForApp(int serial, String facility, boolean lockState,
String password, int serviceClass, String appId) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.setFacilityLockForApp(
serial, facility, lockState, password, serviceClass, appId);
} else {
mRadioProxy.setFacilityLockForApp(
serial, facility, lockState, password, serviceClass, appId);
}
} |
Call IRadioSim#setFacilityLockForApp
@param serial Serial number of request
@param facility One of CB_FACILTY_*
@param lockState True means lock, false means unlock
@param password Password or "" if not required
@param serviceClass Sum of SERVICE_CLASS_*
@param appId Application ID or null if none
@throws RemoteException
| RadioSimProxy::setFacilityLockForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void setSimCardPower(int serial, int state, Message result) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.setSimCardPower(serial, state);
} else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
((android.hardware.radio.V1_6.IRadio) mRadioProxy).setSimCardPower_1_6(serial, state);
} else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_1)) {
((android.hardware.radio.V1_1.IRadio) mRadioProxy).setSimCardPower_1_1(serial, state);
} else {
switch (state) {
case TelephonyManager.CARD_POWER_DOWN: {
mRadioProxy.setSimCardPower(serial, false);
break;
}
case TelephonyManager.CARD_POWER_UP: {
mRadioProxy.setSimCardPower(serial, true);
break;
}
default: {
if (result != null) {
AsyncResult.forMessage(result, null,
CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
result.sendToTarget();
}
}
}
}
} |
Call IRadioSim#setSimCardPower
@param serial Serial number of request
@param state SIM state (power down, power up, pass through)
@param result Result to return in case of error
@throws RemoteException
| RadioSimProxy::setSimCardPower | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void setUiccSubscription(int serial, int slotId, int appIndex, int subId, int subStatus)
throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
android.hardware.radio.sim.SelectUiccSub info =
new android.hardware.radio.sim.SelectUiccSub();
info.slot = slotId;
info.appIndex = appIndex;
info.subType = subId;
info.actStatus = subStatus;
mSimProxy.setUiccSubscription(serial, info);
} else {
android.hardware.radio.V1_0.SelectUiccSub info =
new android.hardware.radio.V1_0.SelectUiccSub();
info.slot = slotId;
info.appIndex = appIndex;
info.subType = subId;
info.actStatus = subStatus;
mRadioProxy.setUiccSubscription(serial, info);
}
} |
Call IRadioSim#setUiccSubscription
@param serial Serial number of request
@param slotId Slot ID
@param appIndex Application index in the card
@param subId Subscription ID
@param subStatus Activation status; 1 = activate and 0 = deactivate
@throws RemoteException
| RadioSimProxy::setUiccSubscription | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void supplyIccPin2ForApp(int serial, String pin2, String aid) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.supplyIccPin2ForApp(serial, pin2, aid);
} else {
mRadioProxy.supplyIccPin2ForApp(serial, pin2, aid);
}
} |
Call IRadioSim#supplyIccPin2ForApp
@param serial Serial number of request
@param pin2 PIN 2 value
@param aid Application ID
@throws RemoteException
| RadioSimProxy::supplyIccPin2ForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void supplyIccPinForApp(int serial, String pin, String aid) throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.supplyIccPinForApp(serial, pin, aid);
} else {
mRadioProxy.supplyIccPinForApp(serial, pin, aid);
}
} |
Call IRadioSim#supplyIccPinForApp
@param serial Serial number of request
@param pin PIN value
@param aid Application ID
@throws RemoteException
| RadioSimProxy::supplyIccPinForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid)
throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid);
} else {
mRadioProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid);
}
} |
Call IRadioSim#supplyIccPuk2ForApp
@param serial Serial number of request
@param puk2 PUK 2 value
@param pin2 PIN 2 value
@param aid Application ID
@throws RemoteException
| RadioSimProxy::supplyIccPuk2ForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void supplyIccPukForApp(int serial, String puk, String pin, String aid)
throws RemoteException {
if (isEmpty()) return;
if (isAidl()) {
mSimProxy.supplyIccPukForApp(serial, puk, pin, aid);
} else {
mRadioProxy.supplyIccPukForApp(serial, puk, pin, aid);
}
} |
Call IRadioSim#supplyIccPukForApp
@param serial Serial number of request
@param puk PUK value
@param pin PIN value
@param aid Application ID
@throws RemoteException
| RadioSimProxy::supplyIccPukForApp | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void supplySimDepersonalization(int serial, PersoSubState persoType, String controlKey)
throws RemoteException {
if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
if (isAidl()) {
mSimProxy.supplySimDepersonalization(serial,
RILUtils.convertToHalPersoTypeAidl(persoType), controlKey);
} else {
((android.hardware.radio.V1_5.IRadio) mRadioProxy).supplySimDepersonalization(serial,
RILUtils.convertToHalPersoType(persoType), controlKey);
}
} |
Call IRadioSim#supplySimDepersonalization
@param serial Serial number of request
@param persoType SIM personalization type
@param controlKey Unlock code for removing SIM personalization from this device
@throws RemoteException
| RadioSimProxy::supplySimDepersonalization | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
public void updateSimPhonebookRecords(int serial, SimPhonebookRecord recordInfo)
throws RemoteException {
if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
if (isAidl()) {
mSimProxy.updateSimPhonebookRecords(serial,
RILUtils.convertToHalPhonebookRecordInfoAidl(recordInfo));
} else {
((android.hardware.radio.V1_6.IRadio) mRadioProxy).updateSimPhonebookRecords(serial,
RILUtils.convertToHalPhonebookRecordInfo(recordInfo));
}
} |
Call IRadioSim#updateSimPhonebookRecords
@param serial Serial number of request
@param recordInfo ADN record information to be updated
@throws RemoteException
| RadioSimProxy::updateSimPhonebookRecords | java | Reginer/aosp-android-jar | android-33/src/com/android/internal/telephony/RadioSimProxy.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/internal/telephony/RadioSimProxy.java | MIT |
SocketInputStream(AbstractPlainSocketImpl impl) throws IOException {
super(impl.getFileDescriptor());
this.impl = impl;
socket = impl.getSocket();
} |
Creates a new SocketInputStream. Can only be called
by a Socket. This method needs to hang on to the owner Socket so
that the fd will not be closed.
@param impl the implemented socket input stream
| SocketInputStream::SocketInputStream | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
public final FileChannel getChannel() {
return null;
} |
Returns the unique {@link java.nio.channels.FileChannel FileChannel}
object associated with this file input stream.</p>
The {@code getChannel} method of {@code SocketInputStream}
returns {@code null} since it is a socket based stream.</p>
@return the file channel associated with this file input stream
@since 1.4
@spec JSR-51
| SocketInputStream::getChannel | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
private int socketRead(FileDescriptor fd,
byte b[], int off, int len,
int timeout)
throws IOException {
return socketRead0(fd, b, off, len, timeout);
} |
Reads into an array of bytes at the specified offset using
the received socket primitive.
@param fd the FileDescriptor
@param b the buffer into which the data is read
@param off the start offset of the data
@param len the maximum number of bytes read
@param timeout the read timeout in ms
@return the actual number of bytes read, -1 is
returned when the end of the stream is reached.
@exception IOException If an I/O error has occurred.
| SocketInputStream::socketRead | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
} |
Reads into a byte array data from the socket.
@param b the buffer into which the data is read
@return the actual number of bytes read, -1 is
returned when the end of the stream is reached.
@exception IOException If an I/O error has occurred.
| SocketInputStream::read | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
public int read(byte b[], int off, int length) throws IOException {
return read(b, off, length, impl.getTimeout());
} |
Reads into a byte array <i>b</i> at offset <i>off</i>,
<i>length</i> bytes of data.
@param b the buffer into which the data is read
@param off the start offset of the data
@param length the maximum number of bytes read
@return the actual number of bytes read, -1 is
returned when the end of the stream is reached.
@exception IOException If an I/O error has occurred.
| SocketInputStream::read | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
public int read() throws IOException {
if (eof) {
return -1;
}
temp = new byte[1];
int n = read(temp, 0, 1);
if (n <= 0) {
return -1;
}
return temp[0] & 0xff;
} |
Reads a single byte from the socket.
| SocketInputStream::read | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
public long skip(long numbytes) throws IOException {
if (numbytes <= 0) {
return 0;
}
long n = numbytes;
int buflen = (int) Math.min(1024, n);
byte data[] = new byte[buflen];
while (n > 0) {
int r = read(data, 0, (int) Math.min((long) buflen, n));
if (r < 0) {
break;
}
n -= r;
}
return numbytes - n;
} |
Skips n bytes of input.
@param numbytes the number of bytes to skip
@return the actual number of bytes skipped.
@exception IOException If an I/O error has occurred.
| SocketInputStream::skip | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
public int available() throws IOException {
// Android-changed: Bug fix, if eof == true, we must indicate that we
// have 0 bytes available.
if (eof) {
return 0;
} else {
return impl.available();
}
} |
Returns the number of bytes that can be read without blocking.
@return the number of immediately available bytes
| SocketInputStream::available | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
protected void finalize() {} |
Overrides finalize, the fd is closed by the Socket.
| SocketInputStream::finalize | java | Reginer/aosp-android-jar | android-31/src/java/net/SocketInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/java/net/SocketInputStream.java | MIT |
public int getSubscriptionId() {
return mSubId;
} |
Return the subscription Id of current TelephonyNetworkSpecifier object.
@return The subscription id.
| TelephonyNetworkSpecifier::getSubscriptionId | java | Reginer/aosp-android-jar | android-35/src/android/net/TelephonyNetworkSpecifier.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/net/TelephonyNetworkSpecifier.java | MIT |
public TelephonyNetworkSpecifier(int subId) {
this.mSubId = subId;
} |
@hide
| TelephonyNetworkSpecifier::TelephonyNetworkSpecifier | java | Reginer/aosp-android-jar | android-35/src/android/net/TelephonyNetworkSpecifier.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/net/TelephonyNetworkSpecifier.java | MIT |
public @NonNull Builder setSubscriptionId(int subId) {
mSubId = subId;
return this;
} |
Set the subscription id.
@param subId The subscription Id.
@return Instance of {@link Builder} to enable the chaining of the builder method.
| Builder::setSubscriptionId | java | Reginer/aosp-android-jar | android-35/src/android/net/TelephonyNetworkSpecifier.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/net/TelephonyNetworkSpecifier.java | MIT |
public @NonNull TelephonyNetworkSpecifier build() {
if (mSubId == SENTINEL_SUB_ID) {
throw new IllegalArgumentException("Subscription Id is not provided.");
}
return new TelephonyNetworkSpecifier(mSubId);
} |
Create a NetworkSpecifier for the cellular network request.
@return TelephonyNetworkSpecifier object.
@throws IllegalArgumentException when subscription Id is not provided through
{@link #setSubscriptionId(int)}.
| Builder::build | java | Reginer/aosp-android-jar | android-35/src/android/net/TelephonyNetworkSpecifier.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/net/TelephonyNetworkSpecifier.java | MIT |
public SigningInfo(SigningDetails signingDetails) {
mSigningDetails = new SigningDetails(signingDetails);
} |
@hide only packagemanager should be populating this
| SigningInfo::SigningInfo | java | Reginer/aosp-android-jar | android-33/src/android/content/pm/SigningInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/content/pm/SigningInfo.java | MIT |
public boolean hasMultipleSigners() {
return mSigningDetails.getSignatures() != null
&& mSigningDetails.getSignatures().length > 1;
} |
Although relatively uncommon, packages may be signed by more than one signer, in which case
their identity is viewed as being the set of all signers, not just any one.
| SigningInfo::hasMultipleSigners | java | Reginer/aosp-android-jar | android-33/src/android/content/pm/SigningInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/content/pm/SigningInfo.java | MIT |
public boolean hasPastSigningCertificates() {
return mSigningDetails.getPastSigningCertificates() != null
&& mSigningDetails.getPastSigningCertificates().length > 0;
} |
APK Signature Scheme v3 enables packages to provide a proof-of-rotation record that the
platform verifies, and uses, to allow the use of new signing certificates. This is only
available to packages that are not signed by multiple signers. In the event of a change to a
new signing certificate, the package's past signing certificates are presented as well. Any
check of a package's signing certificate should also include a search through its entire
signing history, since it could change to a new signing certificate at any time.
| SigningInfo::hasPastSigningCertificates | java | Reginer/aosp-android-jar | android-33/src/android/content/pm/SigningInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/content/pm/SigningInfo.java | MIT |
public Signature[] getSigningCertificateHistory() {
if (hasMultipleSigners()) {
return null;
} else if (!hasPastSigningCertificates()) {
// this package is only signed by one signer with no history, return it
return mSigningDetails.getSignatures();
} else {
// this package has provided proof of past signing certificates, include them
return mSigningDetails.getPastSigningCertificates();
}
} |
Returns the signing certificates this package has proven it is authorized to use. This
includes both the signing certificate associated with the signer of the package and the past
signing certificates it included as its proof of signing certificate rotation. Signing
certificates are returned in the order of rotation with the original signing certificate at
index 0, and the current signing certificate at the last index. This method is the preferred
replacement for the {@code GET_SIGNATURES} flag used with {@link
PackageManager#getPackageInfo(String, int)}. When determining if a package is signed by a
desired certificate, the returned array should be checked to determine if it is one of the
entries.
<note>
This method returns null if the package is signed by multiple signing certificates, as
opposed to being signed by one current signer and also providing the history of past
signing certificates. {@link #hasMultipleSigners()} may be used to determine if this
package is signed by multiple signers. Packages which are signed by multiple signers
cannot change their signing certificates and their {@code Signature} array should be
checked to make sure that every entry matches the looked-for signing certificates.
</note>
| SigningInfo::getSigningCertificateHistory | java | Reginer/aosp-android-jar | android-33/src/android/content/pm/SigningInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/content/pm/SigningInfo.java | MIT |
public Signature[] getApkContentsSigners() {
return mSigningDetails.getSignatures();
} |
Returns the signing certificates used to sign the APK contents of this application. Not
including any past signing certificates the package proved it is authorized to use.
<note>
This method should not be used unless {@link #hasMultipleSigners()} returns true,
indicating that {@link #getSigningCertificateHistory()} cannot be used, otherwise {@link
#getSigningCertificateHistory()} should be preferred.
</note>
| SigningInfo::getApkContentsSigners | java | Reginer/aosp-android-jar | android-33/src/android/content/pm/SigningInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/content/pm/SigningInfo.java | MIT |
ShellProtoLogGroup(boolean enabled, boolean logToProto, boolean logToLogcat, String tag) {
this.mEnabled = enabled;
this.mLogToProto = logToProto;
this.mLogToLogcat = logToLogcat;
this.mTag = tag;
} |
@param enabled set to false to exclude all log statements for this group from
compilation,
they will not be available in runtime.
@param logToProto enable binary logging for the group
@param logToLogcat enable text logging for the group
@param tag name of the source of the logged message
| ShellProtoLogGroup::ShellProtoLogGroup | java | Reginer/aosp-android-jar | android-34/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java | MIT |
private boolean isPipShown() {
return mState != STATE_NO_PIP;
} |
Returns {@code true} if Pip is shown.
| TvPipController::isPipShown | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/pip/tv/TvPipController.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/pip/tv/TvPipController.java | MIT |
private void updatePinnedStackBounds(int animationDuration, boolean immediate) {
if (mState == STATE_NO_PIP) {
return;
}
final boolean stayAtAnchorPosition = mTvPipMenuController.isInMoveMode();
final boolean disallowStashing = mState == STATE_PIP_MENU || stayAtAnchorPosition;
mTvPipBoundsController.recalculatePipBounds(stayAtAnchorPosition, disallowStashing,
animationDuration, immediate);
} |
Update the PiP bounds based on the state of the PiP and keep clear areas.
| TvPipController::updatePinnedStackBounds | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/pip/tv/TvPipController.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/pip/tv/TvPipController.java | MIT |
public void setUseLowPriority(boolean useLowPriority) {
if (mUseLowPriority != useLowPriority) {
mDirtyContentViews |= (FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED);
}
mUseLowPriority = useLowPriority;
} |
Set whether content should use a low priority version of its content views.
| RowContentBindParams::setUseLowPriority | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
public void setUseIncreasedCollapsedHeight(boolean useIncreasedHeight) {
if (mUseIncreasedHeight != useIncreasedHeight) {
mDirtyContentViews |= FLAG_CONTENT_VIEW_CONTRACTED;
}
mUseIncreasedHeight = useIncreasedHeight;
} |
Set whether content should use an increased height version of its contracted view.
| RowContentBindParams::setUseIncreasedCollapsedHeight | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
public void setUseIncreasedHeadsUpHeight(boolean useIncreasedHeadsUpHeight) {
if (mUseIncreasedHeadsUpHeight != useIncreasedHeadsUpHeight) {
mDirtyContentViews |= FLAG_CONTENT_VIEW_HEADS_UP;
}
mUseIncreasedHeadsUpHeight = useIncreasedHeadsUpHeight;
} |
Set whether content should use an increased height version of its heads up view.
| RowContentBindParams::setUseIncreasedHeadsUpHeight | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
public void requireContentViews(@InflationFlag int contentViews) {
@InflationFlag int newContentViews = contentViews &= ~mContentViews;
mContentViews |= contentViews;
mDirtyContentViews |= newContentViews;
} |
Require the specified content views to be bound after the rebind request.
@see InflationFlag
| RowContentBindParams::requireContentViews | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
public void markContentViewsFreeable(@InflationFlag int contentViews) {
@InflationFlag int existingContentViews = contentViews &= mContentViews;
mContentViews &= ~contentViews;
mDirtyContentViews |= existingContentViews;
} |
Mark the content view to be freed. The view may not be immediately freeable since it may
be visible and animating out but this lets the binder know to free the view when safe.
Note that the callback passed into {@link RowContentBindStage#requestRebind}
may return before the view is actually freed since the view is considered up-to-date.
@see InflationFlag
| RowContentBindParams::markContentViewsFreeable | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
public void rebindAllContentViews() {
mDirtyContentViews = mContentViews;
} |
Request that all content views be rebound. This may happen if, for example, the underlying
layout has changed.
| RowContentBindParams::rebindAllContentViews | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
void clearDirtyContentViews() {
mDirtyContentViews = 0;
} |
Clears all dirty content views so that they no longer need to be rebound.
| RowContentBindParams::clearDirtyContentViews | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
public void setNeedsReinflation(boolean needsReinflation) {
mViewsNeedReinflation = needsReinflation;
@InflationFlag int currentContentViews = mContentViews;
mDirtyContentViews |= currentContentViews;
} |
Set whether all content views need to be reinflated even if cached.
TODO: This should probably be a more global config on {@link NotifBindPipeline} since this
generally corresponds to a Context/Configuration change that all stages should know about.
| RowContentBindParams::setNeedsReinflation | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java | MIT |
public boolean satisfiesNetworkSpecifier(@NonNull WifiNetworkSpecifier ns) {
// None of these should be null by construction.
// {@link WifiNetworkSpecifier.Builder} enforces non-null in {@link WifiNetworkSpecifier}.
// {@link WifiNetworkFactory} ensures non-null in {@link WifiNetworkAgentSpecifier}.
checkNotNull(ns);
checkNotNull(ns.ssidPatternMatcher);
checkNotNull(ns.bssidPatternMatcher);
checkNotNull(ns.wifiConfiguration.allowedKeyManagement);
checkNotNull(this.mWifiConfiguration.SSID);
checkNotNull(this.mWifiConfiguration.BSSID);
checkNotNull(this.mWifiConfiguration.allowedKeyManagement);
if (!mMatchLocalOnlySpecifiers) {
// Specifiers that match non-local-only networks only match against the band.
return ns.getBand() == mBand;
}
if (ns.getBand() != ScanResult.UNSPECIFIED && ns.getBand() != mBand) {
return false;
}
final String ssidWithQuotes = this.mWifiConfiguration.SSID;
checkState(ssidWithQuotes.startsWith("\"") && ssidWithQuotes.endsWith("\""));
final String ssidWithoutQuotes = ssidWithQuotes.substring(1, ssidWithQuotes.length() - 1);
if (!ns.ssidPatternMatcher.match(ssidWithoutQuotes)) {
return false;
}
final MacAddress bssid = MacAddress.fromString(this.mWifiConfiguration.BSSID);
final MacAddress matchBaseAddress = ns.bssidPatternMatcher.first;
final MacAddress matchMask = ns.bssidPatternMatcher.second;
if (!bssid.matches(matchBaseAddress, matchMask)) {
return false;
}
if (!ns.wifiConfiguration.allowedKeyManagement.equals(
this.mWifiConfiguration.allowedKeyManagement)) {
return false;
}
return true;
} |
Match {@link WifiNetworkSpecifier} in app's {@link NetworkRequest} with the
{@link WifiNetworkAgentSpecifier} in wifi platform's {@link android.net.NetworkAgent}.
| WifiNetworkAgentSpecifier::satisfiesNetworkSpecifier | java | Reginer/aosp-android-jar | android-34/src/android/net/wifi/WifiNetworkAgentSpecifier.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/net/wifi/WifiNetworkAgentSpecifier.java | MIT |
private static<T> List<T> toBoxedList(Iterator<T> it) {
List<T> l = new ArrayList<>();
it.forEachRemaining(toBoxingConsumer(l::add));
return l;
} |
Convert an iterator to a list using forEach with an implementation of
{@link java.util.stream.LambdaTestHelpers.OmnivorousConsumer}.
This ensures equality comparisons for test results do not trip
the boxing trip-wires.
| LambdaTestHelpers::toBoxedList | java | Reginer/aosp-android-jar | android-32/src/java/util/stream/LambdaTestHelpers.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/java/util/stream/LambdaTestHelpers.java | MIT |
public static<T> List<T> toBoxedList(Spliterator<T> sp) {
List<T> l = new ArrayList<>();
sp.forEachRemaining(toBoxingConsumer(l::add));
return l;
} |
Convert a spliterator to a list using forEach with an implementation of
{@link java.util.stream.LambdaTestHelpers.OmnivorousConsumer}.
This ensures equality comparisons for test results do not trip
the boxing trip-wires.
| LambdaTestHelpers::toBoxedList | java | Reginer/aosp-android-jar | android-32/src/java/util/stream/LambdaTestHelpers.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/java/util/stream/LambdaTestHelpers.java | MIT |
public AttestationProfile(@AttestationProfileId int attestationProfileId) {
this(attestationProfileId, null, null);
if (attestationProfileId == PROFILE_APP_DEFINED) {
throw new IllegalArgumentException("App-defined profiles must be specified with the "
+ "constructor AttestationProfile#constructor(String, String)");
}
} |
Create a profile with the given id.
<p>This constructor is for specifying a profile which is defined by the system. These are
available as constants in the {@link AttestationVerificationManager} class prefixed with
{@code PROFILE_}.
@param attestationProfileId the ID of the system-defined profile
@throws IllegalArgumentException when called with
{@link AttestationVerificationManager#PROFILE_APP_DEFINED}
(use {@link #AttestationProfile(String, String)})
| AttestationProfile::AttestationProfile | java | Reginer/aosp-android-jar | android-35/src/android/security/attestationverification/AttestationProfile.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/security/attestationverification/AttestationProfile.java | MIT |
public AttestationProfile(@NonNull String packageName, @NonNull String profileName) {
this(PROFILE_APP_DEFINED, packageName, profileName);
if (packageName == null || profileName == null) {
throw new IllegalArgumentException("Both packageName and profileName must be non-null");
}
} |
Create a profile with the given package name and profile name.
<p>This constructor is for specifying a profile defined by an app. The packageName must
match the package name of the app that defines the profile (as specified in the {@code
package} attribute of the {@code
<manifest>} tag in the app's manifest. The profile name matches the {@code name} attribute
of the {@code <attestation-profile>} tag.
<p>Apps must declare profiles in their manifest as an {@code <attestation-profile>} element.
However, this constructor does not verify that such a profile exists. If the profile does not
exist, verifications will fail.
@param packageName the package name of the app defining the profile
@param profileName the name of the profile
| AttestationProfile::AttestationProfile | java | Reginer/aosp-android-jar | android-35/src/android/security/attestationverification/AttestationProfile.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/security/attestationverification/AttestationProfile.java | MIT |
public Paint() {
this(ANTI_ALIAS_FLAG);
} |
Create a new paint with default settings.
<p>On devices running {@link Build.VERSION_CODES#O} and below, hardware
accelerated drawing always acts as if {@link #FILTER_BITMAP_FLAG} is set.
On devices running {@link Build.VERSION_CODES#Q} and above,
{@code FILTER_BITMAP_FLAG} is set by this constructor, and it can be
cleared with {@link #setFlags} or {@link #setFilterBitmap}.
On devices running {@link Build.VERSION_CODES#S} and above, {@code ANTI_ALIAS_FLAG}
is set by this constructor, and it can be cleared with {@link #setFlags} or
{@link #setAntiAlias}.</p>
| Align::Paint | java | Reginer/aosp-android-jar | android-32/src/android/graphics/Paint.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/graphics/Paint.java | MIT |
public Paint(int flags) {
mNativePaint = nInit();
NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativePaint);
setFlags(flags | HIDDEN_DEFAULT_PAINT_FLAGS);
// TODO: Turning off hinting has undesirable side effects, we need to
// revisit hinting once we add support for subpixel positioning
// setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
// ? HINTING_OFF : HINTING_ON);
mCompatScaling = mInvCompatScaling = 1;
setTextLocales(LocaleList.getAdjustedDefault());
mColor = Color.pack(Color.BLACK);
} |
Create a new paint with the specified flags. Use setFlags() to change
these after the paint is created.
<p>On devices running {@link Build.VERSION_CODES#O} and below, hardware
accelerated drawing always acts as if {@link #FILTER_BITMAP_FLAG} is set.
On devices running {@link Build.VERSION_CODES#Q} and above,
{@code FILTER_BITMAP_FLAG} is always set by this constructor, regardless
of the value of {@code flags}. It can be cleared with {@link #setFlags} or
{@link #setFilterBitmap}.</p>
@param flags initial flag bits, as if they were passed via setFlags().
| Align::Paint | java | Reginer/aosp-android-jar | android-32/src/android/graphics/Paint.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/graphics/Paint.java | MIT |
public Paint(Paint paint) {
mNativePaint = nInitWithPaint(paint.getNativeInstance());
NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativePaint);
setClassVariablesFrom(paint);
} |
Create a new paint, initialized with the attributes in the specified
paint parameter.
@param paint Existing paint used to initialized the attributes of the
new paint.
| Align::Paint | java | Reginer/aosp-android-jar | android-32/src/android/graphics/Paint.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/graphics/Paint.java | MIT |
public void reset() {
nReset(mNativePaint);
setFlags(HIDDEN_DEFAULT_PAINT_FLAGS | ANTI_ALIAS_FLAG);
// TODO: Turning off hinting has undesirable side effects, we need to
// revisit hinting once we add support for subpixel positioning
// setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
// ? HINTING_OFF : HINTING_ON);
mColor = Color.pack(Color.BLACK);
mColorFilter = null;
mMaskFilter = null;
mPathEffect = null;
mShader = null;
mNativeShader = 0;
mTypeface = null;
mXfermode = null;
mHasCompatScaling = false;
mCompatScaling = 1;
mInvCompatScaling = 1;
mBidiFlags = BIDI_DEFAULT_LTR;
setTextLocales(LocaleList.getAdjustedDefault());
setElegantTextHeight(false);
mFontFeatureSettings = null;
mFontVariationSettings = null;
mShadowLayerRadius = 0.0f;
mShadowLayerDx = 0.0f;
mShadowLayerDy = 0.0f;
mShadowLayerColor = Color.pack(0);
} |
Create a new paint, initialized with the attributes in the specified
paint parameter.
@param paint Existing paint used to initialized the attributes of the
new paint.
public Paint(Paint paint) {
mNativePaint = nInitWithPaint(paint.getNativeInstance());
NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativePaint);
setClassVariablesFrom(paint);
}
/** Restores the paint to its default settings. | Align::reset | java | Reginer/aosp-android-jar | android-32/src/android/graphics/Paint.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/graphics/Paint.java | MIT |
public void set(Paint src) {
if (this != src) {
// copy over the native settings
nSet(mNativePaint, src.mNativePaint);
setClassVariablesFrom(src);
}
} |
Copy the fields from src into this paint. This is equivalent to calling
get() on all of the src fields, and calling the corresponding set()
methods on this.
| Align::set | java | Reginer/aosp-android-jar | android-32/src/android/graphics/Paint.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/graphics/Paint.java | MIT |
private void setClassVariablesFrom(Paint paint) {
mColor = paint.mColor;
mColorFilter = paint.mColorFilter;
mMaskFilter = paint.mMaskFilter;
mPathEffect = paint.mPathEffect;
mShader = paint.mShader;
mNativeShader = paint.mNativeShader;
mTypeface = paint.mTypeface;
mXfermode = paint.mXfermode;
mHasCompatScaling = paint.mHasCompatScaling;
mCompatScaling = paint.mCompatScaling;
mInvCompatScaling = paint.mInvCompatScaling;
mBidiFlags = paint.mBidiFlags;
mLocales = paint.mLocales;
mFontFeatureSettings = paint.mFontFeatureSettings;
mFontVariationSettings = paint.mFontVariationSettings;
mShadowLayerRadius = paint.mShadowLayerRadius;
mShadowLayerDx = paint.mShadowLayerDx;
mShadowLayerDy = paint.mShadowLayerDy;
mShadowLayerColor = paint.mShadowLayerColor;
} |
Set all class variables using current values from the given
{@link Paint}.
| Align::setClassVariablesFrom | java | Reginer/aosp-android-jar | android-32/src/android/graphics/Paint.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/graphics/Paint.java | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.