64 public static int codePointBefore(byte[] value, int index) {
65 return value[index - 1] & 0xff;
66 }
67
68 public static int codePointCount(byte[] value, int beginIndex, int endIndex) {
69 return endIndex - beginIndex;
70 }
71
72 public static char[] toChars(byte[] value) {
73 char[] dst = new char[value.length];
74 inflate(value, 0, dst, 0, value.length);
75 return dst;
76 }
77
78 public static byte[] inflate(byte[] value, int off, int len) {
79 byte[] ret = StringUTF16.newBytesFor(len);
80 inflate(value, off, ret, 0, len);
81 return ret;
82 }
83
84 public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
85 inflate(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
86 }
87
88 public static void getBytes(byte[] value, int srcBegin, int srcEnd, byte dst[], int dstBegin) {
89 System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
90 }
91
92 @HotSpotIntrinsicCandidate
93 public static boolean equals(byte[] value, byte[] other) {
94 if (value.length == other.length) {
95 for (int i = 0; i < value.length; i++) {
96 if (value[i] != other[i]) {
97 return false;
98 }
99 }
100 return true;
101 }
102 return false;
103 }
104
105 @HotSpotIntrinsicCandidate
106 public static int compareTo(byte[] value, byte[] other) {
107 int len1 = value.length;
108 int len2 = other.length;
287 int off = Math.min(fromIndex, value.length - 1);
288 for (; off >= 0; off--) {
289 if (value[off] == (byte)ch) {
290 return off;
291 }
292 }
293 return -1;
294 }
295
296 public static String replace(byte[] value, char oldChar, char newChar) {
297 if (canEncode(oldChar)) {
298 int len = value.length;
299 int i = -1;
300 while (++i < len) {
301 if (value[i] == (byte)oldChar) {
302 break;
303 }
304 }
305 if (i < len) {
306 if (canEncode(newChar)) {
307 byte buf[] = new byte[len];
308 for (int j = 0; j < i; j++) { // TBD arraycopy?
309 buf[j] = value[j];
310 }
311 while (i < len) {
312 byte c = value[i];
313 buf[i] = (c == (byte)oldChar) ? (byte)newChar : c;
314 i++;
315 }
316 return new String(buf, LATIN1);
317 } else {
318 byte[] buf = StringUTF16.newBytesFor(len);
319 // inflate from latin1 to UTF16
320 inflate(value, 0, buf, 0, i);
321 while (i < len) {
322 char c = (char)(value[i] & 0xff);
323 StringUTF16.putChar(buf, i, (c == oldChar) ? newChar : c);
324 i++;
325 }
326 return new String(buf, UTF16);
327 }
|
64 public static int codePointBefore(byte[] value, int index) {
65 return value[index - 1] & 0xff;
66 }
67
68 public static int codePointCount(byte[] value, int beginIndex, int endIndex) {
69 return endIndex - beginIndex;
70 }
71
72 public static char[] toChars(byte[] value) {
73 char[] dst = new char[value.length];
74 inflate(value, 0, dst, 0, value.length);
75 return dst;
76 }
77
78 public static byte[] inflate(byte[] value, int off, int len) {
79 byte[] ret = StringUTF16.newBytesFor(len);
80 inflate(value, off, ret, 0, len);
81 return ret;
82 }
83
84 public static void getChars(byte[] value, int srcBegin, int srcEnd, char[] dst, int dstBegin) {
85 inflate(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
86 }
87
88 public static void getBytes(byte[] value, int srcBegin, int srcEnd, byte[] dst, int dstBegin) {
89 System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
90 }
91
92 @HotSpotIntrinsicCandidate
93 public static boolean equals(byte[] value, byte[] other) {
94 if (value.length == other.length) {
95 for (int i = 0; i < value.length; i++) {
96 if (value[i] != other[i]) {
97 return false;
98 }
99 }
100 return true;
101 }
102 return false;
103 }
104
105 @HotSpotIntrinsicCandidate
106 public static int compareTo(byte[] value, byte[] other) {
107 int len1 = value.length;
108 int len2 = other.length;
287 int off = Math.min(fromIndex, value.length - 1);
288 for (; off >= 0; off--) {
289 if (value[off] == (byte)ch) {
290 return off;
291 }
292 }
293 return -1;
294 }
295
296 public static String replace(byte[] value, char oldChar, char newChar) {
297 if (canEncode(oldChar)) {
298 int len = value.length;
299 int i = -1;
300 while (++i < len) {
301 if (value[i] == (byte)oldChar) {
302 break;
303 }
304 }
305 if (i < len) {
306 if (canEncode(newChar)) {
307 byte[] buf = new byte[len];
308 for (int j = 0; j < i; j++) { // TBD arraycopy?
309 buf[j] = value[j];
310 }
311 while (i < len) {
312 byte c = value[i];
313 buf[i] = (c == (byte)oldChar) ? (byte)newChar : c;
314 i++;
315 }
316 return new String(buf, LATIN1);
317 } else {
318 byte[] buf = StringUTF16.newBytesFor(len);
319 // inflate from latin1 to UTF16
320 inflate(value, 0, buf, 0, i);
321 while (i < len) {
322 char c = (char)(value[i] & 0xff);
323 StringUTF16.putChar(buf, i, (c == oldChar) ? newChar : c);
324 i++;
325 }
326 return new String(buf, UTF16);
327 }
|