mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Add support for String.isBlank() (#482)
This commit is contained in:
parent
a45d1e0d07
commit
c2d27fdb1a
|
@ -146,6 +146,16 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return characters.length == 0;
|
return characters.length == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBlank() {
|
||||||
|
|
||||||
|
for (int i = 0; i < characters.length; i++) {
|
||||||
|
if (characters[i] != ' ') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
|
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
|
||||||
if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > length() || dstBegin < 0
|
if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > length() || dstBegin < 0
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.classlib.java.lang;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -311,4 +312,12 @@ public class StringTest {
|
||||||
assertEquals(0, str.length());
|
assertEquals(0, str.length());
|
||||||
assertEquals("", str);
|
assertEquals("", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsBlank() {
|
||||||
|
assertTrue(new String(new char[0]).isBlank());
|
||||||
|
assertTrue(new String(new char[] { ' ', ' ' }).isBlank());
|
||||||
|
assertFalse(new String(new char[] { ' ', 'x', ' ' }).isBlank());
|
||||||
|
assertFalse(new String(new char[] { 'a', ' ' }).isBlank());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user