mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: add String.strip
This commit is contained in:
parent
697ad73762
commit
81f78fab01
|
@ -475,6 +475,18 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
|
||||||
return substring(lower, upper + 1);
|
return substring(lower, upper + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TString strip() {
|
||||||
|
var lower = 0;
|
||||||
|
var upper = length() - 1;
|
||||||
|
while (lower <= upper && Character.isWhitespace(charAt(lower))) {
|
||||||
|
++lower;
|
||||||
|
}
|
||||||
|
while (lower <= upper && Character.isWhitespace(charAt(upper))) {
|
||||||
|
--upper;
|
||||||
|
}
|
||||||
|
return substring(lower, upper + 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return (String) (Object) this;
|
return (String) (Object) this;
|
||||||
|
|
|
@ -201,6 +201,14 @@ public class StringTest {
|
||||||
assertEquals("", " ".trim());
|
assertEquals("", " ".trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stripWorks() {
|
||||||
|
assertEquals("ab", " ab ".strip());
|
||||||
|
assertEquals("ab", "ab".strip());
|
||||||
|
assertEquals("", " \t".strip());
|
||||||
|
assertEquals("ab", "\t\n \u2008ab\r\f".strip());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertedToCharArray() {
|
public void convertedToCharArray() {
|
||||||
char[] array = "123".toCharArray();
|
char[] array = "123".toCharArray();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user