diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index a55e7a179b..0000000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/user/super/com/google/gwt/emul/java/lang/Character.java b/user/super/com/google/gwt/emul/java/lang/Character.java index 4b01e4d43d..d675b1719e 100644 --- a/user/super/com/google/gwt/emul/java/lang/Character.java +++ b/user/super/com/google/gwt/emul/java/lang/Character.java @@ -322,7 +322,7 @@ private static boolean isWhitespace(String ch) { // the Java definition includes separators. whitespaceRegex = new NativeRegExp( - "[\\u1680\\u180E\\u2000-\\u2006\\u2008-\\u200A\\u2028\\u2029\\u205F\\u3000\\uFEFF]" + "[\\u1680\\u2000-\\u2006\\u2008-\\u200A\\u2028\\u2029\\u205F\\u3000]" + "|[\\t-\\r ]" + "|[\\x1C-\\x1F]"); } diff --git a/user/super/com/google/gwt/emul/java/lang/String.java b/user/super/com/google/gwt/emul/java/lang/String.java index ff166b3a32..e0d6ffda72 100644 --- a/user/super/com/google/gwt/emul/java/lang/String.java +++ b/user/super/com/google/gwt/emul/java/lang/String.java @@ -16,6 +16,7 @@ package java.lang; +import static javaemul.internal.InternalPreconditions.checkArgument; import static javaemul.internal.InternalPreconditions.checkCriticalStringBounds; import static javaemul.internal.InternalPreconditions.checkNotNull; import static javaemul.internal.InternalPreconditions.checkStringBounds; @@ -782,13 +783,11 @@ public boolean isBlank() { } public Stream lines() { - return StreamSupport.stream(new LinesSpliterator(this), false); + return StreamSupport.stream(new LinesSpliterator(), false); } public String repeat(int count) { - if (count < 0) { - throw new IllegalArgumentException("count is negative: " + count); - } + checkArgument(count >= 0, "count is negative: " + count); return asNativeString().repeat(count); } @@ -812,15 +811,13 @@ private int getTrailingWhitespaceLength() { return length; } - private static class LinesSpliterator extends Spliterators.AbstractSpliterator { + private class LinesSpliterator extends Spliterators.AbstractSpliterator { private int nextIndex = 0; - private String content; - int rPosition = -2; - int nPosition = -2; + private int rPosition = -1; + private int nPosition = -1; - private LinesSpliterator(String content) { + private LinesSpliterator() { super(Long.MAX_VALUE, Spliterator.IMMUTABLE | Spliterator.ORDERED); - this.content = content; } @Override @@ -832,17 +829,17 @@ public boolean tryAdvance(Consumer action) { nPosition = cappedIndexOf('\n'); } int lineEnd = Math.min(nPosition, rPosition); - action.accept(content.substring(nextIndex, lineEnd)); + action.accept(substring(nextIndex, lineEnd)); nextIndex = lineEnd + 1; if (nPosition == rPosition + 1) { nextIndex++; } - return nextIndex < content.length(); + return nextIndex < length(); } private int cappedIndexOf(char c) { - int index = content.indexOf(c); - return index == -1 ? content.length() : index; + int index = indexOf(c); + return index == -1 ? length() : index; } } diff --git a/user/test/com/google/gwt/emultest/java/lang/CharacterTest.java b/user/test/com/google/gwt/emultest/java/lang/CharacterTest.java index 41c6f247ec..a2ccc9e6ad 100644 --- a/user/test/com/google/gwt/emultest/java/lang/CharacterTest.java +++ b/user/test/com/google/gwt/emultest/java/lang/CharacterTest.java @@ -360,7 +360,8 @@ public void testIsWhitepace() { char[] nonBreakingSpaceSeparators = { '\u00A0', // NO-BREAK SPACE. '\u2007', // FIGURE SPACE. - '\u202F' // NARROW NO-BREAK SPACE. + '\u202F', // NARROW NO-BREAK SPACE. + '\uFFEF' // ZERO WIDTH NO-BREAK SPACE. }; char[] specialCases = { @@ -379,7 +380,8 @@ public void testIsWhitepace() { 'a', // LATIN SMALL LETTER A. 'B', // LATIN CAPITAL LETTER B. '_', // LOW LINE. - '\u2500' // BOX DRAWINGS LIGHT HORIZONTAL. + '\u2500', // BOX DRAWINGS LIGHT HORIZONTAL. + '\u180E', // MONGOLIAN VOWEL SEPARATOR, was considered whitespace in Java 8. }; int[] supplementaryCounterExamples = { diff --git a/user/test/com/google/gwt/emultest/java/lang/StringTest.java b/user/test/com/google/gwt/emultest/java/lang/StringTest.java index 4b08a45eee..1600f8568a 100644 --- a/user/test/com/google/gwt/emultest/java/lang/StringTest.java +++ b/user/test/com/google/gwt/emultest/java/lang/StringTest.java @@ -895,6 +895,7 @@ public void testTrim() { // JavaScript would trim \u2029 and other unicode whitespace type characters; but Java wont trimRightAssertEquals("\u2029abc\u00a0","\u2029abc\u00a0"); + trimRightAssertEquals("\uffefx\u180e", "\uffefx\u180e "); } public void testUpperCase() { diff --git a/user/test/com/google/gwt/emultest/java11/lang/StringTest.java b/user/test/com/google/gwt/emultest/java11/lang/StringTest.java index 34544e402a..af2e44abdc 100644 --- a/user/test/com/google/gwt/emultest/java11/lang/StringTest.java +++ b/user/test/com/google/gwt/emultest/java11/lang/StringTest.java @@ -33,27 +33,40 @@ public void testIsBlank() { } public void testStrip() { - assertEquals("", "".strip()); - assertEquals("", " ".strip()); - assertEquals("x", " x ".strip()); - assertEquals("x", "\u001cx\u001c".strip()); - assertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 ".strip()); + stripRightAsssertEquals("", ""); + stripRightAsssertEquals("", " "); + stripRightAsssertEquals("x", " x "); + stripRightAsssertEquals("x", "\u001cx\u001c"); + stripRightAsssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 "); + stripRightAsssertEquals("\uffefx\u180e", "\uffefx\u180e "); } public void testStripLeading() { - assertEquals("", "".stripLeading()); - assertEquals("", " ".stripLeading()); - assertEquals("x ", " x ".stripLeading()); - assertEquals("x\u001c", "\u001cx\u001c".stripLeading()); - assertEquals("\u00a0x\u00a0", "\u00a0x\u00a0".stripLeading()); + stripRightLeadingAsssertEquals("", ""); + stripRightLeadingAsssertEquals("", " "); + stripRightLeadingAsssertEquals("x ", " x "); + stripRightLeadingAsssertEquals("x\u001c", "\u001cx\u001c"); + stripRightLeadingAsssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0"); } public void testStripTrailing() { - assertEquals("", "".stripTrailing()); - assertEquals("", " ".stripTrailing()); - assertEquals(" x", " x ".stripTrailing()); - assertEquals("\u001cx", "\u001cx\u001c".stripTrailing()); - assertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 ".stripTrailing()); + stripRightTrailingAsssertEquals("", ""); + stripRightTrailingAsssertEquals("", " "); + stripRightTrailingAsssertEquals(" x", " x "); + stripRightTrailingAsssertEquals("\u001cx", "\u001cx\u001c"); + stripRightTrailingAsssertEquals("\u00a0x\u00a0", "\u00a0x\u00a0 "); + } + + private void stripRightAsssertEquals(String expected, String arg) { + assertEquals(expected, arg.strip()) + } + + private void stripRightLeadingAsssertEquals(String expected, String arg) { + assertEquals(expected, arg.stripLeading()) + } + + private void stripRightTrailingAsssertEquals(String expected, String arg) { + assertEquals(expected, arg.stripTrailing()) } public void testRepeat() {