mirror of
https://github.com/corda/corda.git
synced 2025-01-09 22:42:40 +00:00
add a few String methods
This commit is contained in:
parent
4fed24270b
commit
17a42c5611
@ -11,6 +11,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class String implements Comparable<String>, CharSequence {
|
public final class String implements Comparable<String>, CharSequence {
|
||||||
private Object data;
|
private Object data;
|
||||||
@ -199,14 +200,8 @@ public final class String implements Comparable<String>, CharSequence {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int lastIndexOf(int c) {
|
public int lastIndexOf(int ch) {
|
||||||
for (int i = length - 1; i >= 0; --i) {
|
return lastIndexOf(ch, length-1);
|
||||||
if (charAt(i) == c) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int indexOf(String s) {
|
public int indexOf(String s) {
|
||||||
@ -303,6 +298,14 @@ public final class String implements Comparable<String>, CharSequence {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean startsWith(String s, int start) {
|
||||||
|
if (length >= s.length + start) {
|
||||||
|
return substring(start, s.length).compareTo(s) == 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean endsWith(String s) {
|
public boolean endsWith(String s) {
|
||||||
if (length >= s.length) {
|
if (length >= s.length) {
|
||||||
return substring(length - s.length).compareTo(s) == 0;
|
return substring(length - s.length).compareTo(s) == 0;
|
||||||
@ -429,6 +432,10 @@ public final class String implements Comparable<String>, CharSequence {
|
|||||||
return substring(start, end);
|
return substring(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean matches(String regex) {
|
||||||
|
return Pattern.matches(regex, this);
|
||||||
|
}
|
||||||
|
|
||||||
public native String intern();
|
public native String intern();
|
||||||
|
|
||||||
public static String valueOf(Object s) {
|
public static String valueOf(Object s) {
|
||||||
@ -466,4 +473,14 @@ public final class String implements Comparable<String>, CharSequence {
|
|||||||
public static String valueOf(double v) {
|
public static String valueOf(double v) {
|
||||||
return Double.toString(v);
|
return Double.toString(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int lastIndexOf(int ch, int lastIndex) {
|
||||||
|
for (int i = lastIndex ; i >= 0; --i) {
|
||||||
|
if (charAt(i) == ch) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user