mirror of
https://github.com/corda/corda.git
synced 2025-02-15 23:22:54 +00:00
add String.lastIndexOf(String,int); defer to Pattern.split in String.split
This commit is contained in:
parent
bf48f1e297
commit
dd82b58dad
@ -357,9 +357,13 @@ public final class String
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int lastIndexOf(String s) {
|
public int lastIndexOf(String s) {
|
||||||
if (s.length == 0) return length;
|
return lastIndexOf(s, length - s.length);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = length - s.length; i >= 0; --i) {
|
public int lastIndexOf(String s, int lastIndex) {
|
||||||
|
if (s.length == 0) return lastIndex;
|
||||||
|
|
||||||
|
for (int i = Math.min(length - s.length, lastIndex); i >= 0; --i) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (; j < s.length && i + j < length; ++j) {
|
for (; j < s.length && i + j < length; ++j) {
|
||||||
if (charAt(i + j) != s.charAt(j)) {
|
if (charAt(i + j) != s.charAt(j)) {
|
||||||
@ -521,44 +525,12 @@ public final class String
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] split(String s) {
|
public String[] split(String regex) {
|
||||||
String[] array = new String[(length / s.length) + 1];
|
return split(regex, 0);
|
||||||
int index = 0;
|
}
|
||||||
int last = 0;
|
|
||||||
int position = 0;
|
|
||||||
for (int i = 0; i < length - s.length + 1;) {
|
|
||||||
int j;
|
|
||||||
for (j = 0; j < s.length; ++j) {
|
|
||||||
if (charAt(i + j) != s.charAt(j)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (j == s.length) {
|
public String[] split(String regex, int limit) {
|
||||||
if (i > 0) {
|
return Pattern.compile(regex).split(this, limit);
|
||||||
if (i > position) {
|
|
||||||
last = index;
|
|
||||||
}
|
|
||||||
array[index++] = substring(position, i);
|
|
||||||
}
|
|
||||||
i = position = i + s.length;
|
|
||||||
} else {
|
|
||||||
++ i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (position < length) {
|
|
||||||
last = index;
|
|
||||||
array[index] = substring(position, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last + 1 < array.length) {
|
|
||||||
String[] a = new String[last + 1];
|
|
||||||
System.arraycopy(array, 0, a, 0, last + 1);
|
|
||||||
array = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence subSequence(int start, int end) {
|
public CharSequence subSequence(int start, int end) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user