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
|
@ -147,6 +147,16 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
|
|||
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) {
|
||||
if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > length() || dstBegin < 0
|
||||
|| dstBegin + (srcEnd - srcBegin) > dst.length) {
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.classlib.java.lang;
|
|||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -311,4 +312,12 @@ public class StringTest {
|
|||
assertEquals(0, str.length());
|
||||
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