< prev index next >

src/java.base/share/classes/java/lang/StringLatin1.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, 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 --- 1,7 ---- /* ! * Copyright (c) 2015, 2017, 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
*** 34,44 **** import jdk.internal.HotSpotIntrinsicCandidate; import static java.lang.String.LATIN1; import static java.lang.String.UTF16; import static java.lang.String.checkOffset; ! import static java.lang.String.checkBoundsOffCount; final class StringLatin1 { public static char charAt(byte[] value, int index) { if (index < 0 || index >= value.length) { --- 34,44 ---- import jdk.internal.HotSpotIntrinsicCandidate; import static java.lang.String.LATIN1; import static java.lang.String.UTF16; import static java.lang.String.checkOffset; ! import static java.lang.StringUTF16.checkBoundsOffCount; final class StringLatin1 { public static char charAt(byte[] value, int index) { if (index < 0 || index >= value.length) {
*** 118,128 **** int len1 = length(value); int len2 = StringUTF16.length(other); int lim = Math.min(len1, len2); for (int k = 0; k < lim; k++) { char c1 = getChar(value, k); ! char c2 = StringUTF16.getChar(other, k); if (c1 != c2) { return c1 - c2; } } return len1 - len2; --- 118,128 ---- int len1 = length(value); int len2 = StringUTF16.length(other); int lim = Math.min(len1, len2); for (int k = 0; k < lim; k++) { char c1 = getChar(value, k); ! char c2 = StringUTF16.Trusted.getChar(other, k); if (c1 != c2) { return c1 - c2; } } return len1 - len2;
*** 152,162 **** int len1 = length(value); int len2 = StringUTF16.length(other); int lim = Math.min(len1, len2); for (int k = 0; k < lim; k++) { char c1 = getChar(value, k); ! char c2 = StringUTF16.getChar(other, k); if (c1 != c2) { c1 = Character.toUpperCase(c1); c2 = Character.toUpperCase(c2); if (c1 != c2) { c1 = Character.toLowerCase(c1); --- 152,162 ---- int len1 = length(value); int len2 = StringUTF16.length(other); int lim = Math.min(len1, len2); for (int k = 0; k < lim; k++) { char c1 = getChar(value, k); ! char c2 = StringUTF16.Trusted.getChar(other, k); if (c1 != c2) { c1 = Character.toUpperCase(c1); c2 = Character.toUpperCase(c2); if (c1 != c2) { c1 = Character.toLowerCase(c1);
*** 298,308 **** byte[] buf = StringUTF16.newBytesFor(len); // inflate from latin1 to UTF16 inflate(value, 0, buf, 0, i); while (i < len) { char c = (char)(value[i] & 0xff); ! StringUTF16.putChar(buf, i, (c == oldChar) ? newChar : c); i++; } return new String(buf, UTF16); } } --- 298,308 ---- byte[] buf = StringUTF16.newBytesFor(len); // inflate from latin1 to UTF16 inflate(value, 0, buf, 0, i); while (i < len) { char c = (char)(value[i] & 0xff); ! StringUTF16.Trusted.putChar(buf, i, (c == oldChar) ? newChar : c); i++; } return new String(buf, UTF16); } }
*** 336,346 **** public static boolean regionMatchesCI_UTF16(byte[] value, int toffset, byte[] other, int ooffset, int len) { int last = toffset + len; while (toffset < last) { char c1 = (char)(value[toffset++] & 0xff); ! char c2 = StringUTF16.getChar(other, ooffset++); if (c1 == c2) { continue; } char u1 = Character.toUpperCase(c1); char u2 = Character.toUpperCase(c2); --- 336,346 ---- public static boolean regionMatchesCI_UTF16(byte[] value, int toffset, byte[] other, int ooffset, int len) { int last = toffset + len; while (toffset < last) { char c1 = (char)(value[toffset++] & 0xff); ! char c2 = StringUTF16.Trusted.getChar(other, ooffset++); if (c1 == c2) { continue; } char u1 = Character.toUpperCase(c1); char u2 = Character.toUpperCase(c2);
*** 392,402 **** int first, Locale locale, boolean localeDependent) { byte[] result = StringUTF16.newBytesFor(value.length); int resultOffset = 0; for (int i = 0; i < first; i++) { ! StringUTF16.putChar(result, resultOffset++, value[i] & 0xff); } for (int i = first; i < value.length; i++) { int srcChar = value[i] & 0xff; int lowerChar; char[] lowerCharArray; --- 392,402 ---- int first, Locale locale, boolean localeDependent) { byte[] result = StringUTF16.newBytesFor(value.length); int resultOffset = 0; for (int i = 0; i < first; i++) { ! StringUTF16.Trusted.putChar(result, resultOffset++, value[i] & 0xff); } for (int i = first; i < value.length; i++) { int srcChar = value[i] & 0xff; int lowerChar; char[] lowerCharArray;
*** 404,414 **** lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale); } else { lowerChar = Character.toLowerCase(srcChar); } if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp ! StringUTF16.putChar(result, resultOffset++, lowerChar); } else { if (lowerChar == Character.ERROR) { lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale); } else { lowerCharArray = Character.toChars(lowerChar); --- 404,414 ---- lowerChar = ConditionalSpecialCasing.toLowerCaseEx(str, i, locale); } else { lowerChar = Character.toLowerCase(srcChar); } if (Character.isBmpCodePoint(lowerChar)) { // Character.ERROR is not a bmp ! StringUTF16.Trusted.putChar(result, resultOffset++, lowerChar); } else { if (lowerChar == Character.ERROR) { lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(str, i, locale); } else { lowerCharArray = Character.toChars(lowerChar);
*** 419,429 **** byte[] result2 = StringUTF16.newBytesFor((result.length >> 1) + mapLen - 1); System.arraycopy(result, 0, result2, 0, resultOffset << 1); result = result2; } for (int x = 0; x < mapLen; ++x) { ! StringUTF16.putChar(result, resultOffset++, lowerCharArray[x]); } } } return StringUTF16.newString(result, 0, resultOffset); } --- 419,429 ---- byte[] result2 = StringUTF16.newBytesFor((result.length >> 1) + mapLen - 1); System.arraycopy(result, 0, result2, 0, resultOffset << 1); result = result2; } for (int x = 0; x < mapLen; ++x) { ! StringUTF16.Trusted.putChar(result, resultOffset++, lowerCharArray[x]); } } } return StringUTF16.newString(result, 0, resultOffset); }
*** 467,477 **** int first, Locale locale, boolean localeDependent) { byte[] result = StringUTF16.newBytesFor(value.length); int resultOffset = 0; for (int i = 0; i < first; i++) { ! StringUTF16.putChar(result, resultOffset++, value[i] & 0xff); } for (int i = first; i < value.length; i++) { int srcChar = value[i] & 0xff; int upperChar; char[] upperCharArray; --- 467,477 ---- int first, Locale locale, boolean localeDependent) { byte[] result = StringUTF16.newBytesFor(value.length); int resultOffset = 0; for (int i = 0; i < first; i++) { ! StringUTF16.Trusted.putChar(result, resultOffset++, value[i] & 0xff); } for (int i = first; i < value.length; i++) { int srcChar = value[i] & 0xff; int upperChar; char[] upperCharArray;
*** 479,489 **** upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale); } else { upperChar = Character.toUpperCaseEx(srcChar); } if (Character.isBmpCodePoint(upperChar)) { ! StringUTF16.putChar(result, resultOffset++, upperChar); } else { if (upperChar == Character.ERROR) { if (localeDependent) { upperCharArray = ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale); --- 479,489 ---- upperChar = ConditionalSpecialCasing.toUpperCaseEx(str, i, locale); } else { upperChar = Character.toUpperCaseEx(srcChar); } if (Character.isBmpCodePoint(upperChar)) { ! StringUTF16.Trusted.putChar(result, resultOffset++, upperChar); } else { if (upperChar == Character.ERROR) { if (localeDependent) { upperCharArray = ConditionalSpecialCasing.toUpperCaseCharArray(str, i, locale);
*** 499,509 **** byte[] result2 = StringUTF16.newBytesFor((result.length >> 1) + mapLen - 1); System.arraycopy(result, 0, result2, 0, resultOffset << 1); result = result2; } for (int x = 0; x < mapLen; ++x) { ! StringUTF16.putChar(result, resultOffset++, upperCharArray[x]); } } } return StringUTF16.newString(result, 0, resultOffset); } --- 499,509 ---- byte[] result2 = StringUTF16.newBytesFor((result.length >> 1) + mapLen - 1); System.arraycopy(result, 0, result2, 0, resultOffset << 1); result = result2; } for (int x = 0; x < mapLen; ++x) { ! StringUTF16.Trusted.putChar(result, resultOffset++, upperCharArray[x]); } } } return StringUTF16.newString(result, 0, resultOffset); }
*** 564,578 **** } // inflatedCopy byte[] -> byte[] @HotSpotIntrinsicCandidate public static void inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) { ! // We need a range check here because 'putChar' has no checks ! checkBoundsOffCount(dstOff << 1, len << 1, dst.length); ! for (int i = 0; i < len; i++) { ! StringUTF16.putChar(dst, dstOff++, src[srcOff++] & 0xff); ! } } static class CharsSpliterator implements Spliterator.OfInt { private final byte[] array; private int index; // current index, modified on advance/split --- 564,574 ---- } // inflatedCopy byte[] -> byte[] @HotSpotIntrinsicCandidate public static void inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) { ! StringUTF16.inflate(src, srcOff, dst, dstOff, len); } static class CharsSpliterator implements Spliterator.OfInt { private final byte[] array; private int index; // current index, modified on advance/split
< prev index next >