< prev index next >
src/java.base/share/classes/java/lang/StringLatin1.java
Print this page
rev 51519 : 8200434: String::align, String::indent
Reviewed-by: smarks
*** 543,553 ****
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length;
int left = 0;
while (left < length) {
! char ch = (char)(value[left] & 0xff);
if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
break;
}
left++;
}
--- 543,553 ----
public static int indexOfNonWhitespace(byte[] value) {
int length = value.length;
int left = 0;
while (left < length) {
! char ch = getChar(value, left);
if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
break;
}
left++;
}
*** 556,566 ****
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length;
int right = length;
while (0 < right) {
! char ch = (char)(value[right - 1] & 0xff);
if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
break;
}
right--;
}
--- 556,566 ----
public static int lastIndexOfNonWhitespace(byte[] value) {
int length = value.length;
int right = length;
while (0 < right) {
! char ch = getChar(value, right - 1);
if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
break;
}
right--;
}
*** 571,581 ****
int left = indexOfNonWhitespace(value);
if (left == value.length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
! return ((left > 0) || (right < value.length)) ? newString(value, left, right - left) : null;
}
public static String stripLeading(byte[] value) {
int left = indexOfNonWhitespace(value);
if (left == value.length) {
--- 571,582 ----
int left = indexOfNonWhitespace(value);
if (left == value.length) {
return "";
}
int right = lastIndexOfNonWhitespace(value);
! boolean ifChanged = (left > 0) || (right < value.length);
! return ifChanged ? newString(value, left, right - left) : null;
}
public static String stripLeading(byte[] value) {
int left = indexOfNonWhitespace(value);
if (left == value.length) {
*** 595,629 ****
private final static class LinesSpliterator implements Spliterator<String> {
private byte[] value;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
! LinesSpliterator(byte[] value) {
! this(value, 0, value.length);
! }
!
! LinesSpliterator(byte[] value, int start, int length) {
this.value = value;
this.index = start;
this.fence = start + length;
}
private int indexOfLineSeparator(int start) {
for (int current = start; current < fence; current++) {
! byte ch = value[current];
if (ch == '\n' || ch == '\r') {
return current;
}
}
return fence;
}
private int skipLineSeparator(int start) {
if (start < fence) {
! if (value[start] == '\r') {
int next = start + 1;
! if (next < fence && value[next] == '\n') {
return next + 1;
}
}
return start + 1;
}
--- 596,626 ----
private final static class LinesSpliterator implements Spliterator<String> {
private byte[] value;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
! private LinesSpliterator(byte[] value, int start, int length) {
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;
}
*** 678,691 ****
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
}
! static Stream<String> lines(byte[] value) {
! return StreamSupport.stream(new LinesSpliterator(value), false);
}
public static void putChar(byte[] val, int index, int c) {
//assert (canEncode(c));
val[index] = (byte)(c);
--- 675,758 ----
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
}
+
+ static LinesSpliterator spliterator(byte[] value) {
+ return new LinesSpliterator(value, 0, value.length);
}
! static LinesSpliterator spliterator(byte[] value, int leading, int trailing) {
! int length = value.length;
! int left = 0;
! int index;
! for (int l = 0; l < leading; l++) {
! index = skipBlankForward(value, left, length);
! if (index == left) {
! break;
! }
! left = index;
! }
! int right = length;
! for (int t = 0; t < trailing; t++) {
! index = skipBlankBackward(value, left, right);
! if (index == right) {
! break;
! }
! right = index;
! }
! return new LinesSpliterator(value, left, right - left);
! }
!
! private static int skipBlankForward(byte[] value, int start, int length) {
! int index = start;
! while (index < length) {
! char ch = getChar(value, index++);
! if (ch == '\n') {
! return index;
! }
! if (ch == '\r') {
! if (index < length && getChar(value, index) == '\n') {
! return index + 1;
! }
! return index;
! }
! if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
! return start;
! }
! }
! return length;
! }
!
! private static int skipBlankBackward(byte[] value, int start, int fence) {
! int index = fence;
! if (start < index && getChar(value, index - 1) == '\n') {
! index--;
! }
! if (start < index && getChar(value, index - 1) == '\r') {
! index--;
! }
! while (start < index) {
! char ch = getChar(value, --index);
! if (ch == '\r' || ch == '\n') {
! return index + 1;
! }
! if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
! return fence;
! }
! }
! return start;
! }
! }
!
! static Stream<String> lines(byte[] value, int leading, int trailing) {
! if (leading == 0 && trailing == 0) {
! return StreamSupport.stream(LinesSpliterator.spliterator(value), false);
! } else {
! return StreamSupport.stream(LinesSpliterator.spliterator(value, leading, trailing), false);
! }
}
public static void putChar(byte[] val, int index, int c) {
//assert (canEncode(c));
val[index] = (byte)(c);
< prev index next >