File tree Expand file tree Collapse file tree 2 files changed +5
-19
lines changed
main/java/org/hamcrest/text
test/java/org/hamcrest/text Expand file tree Collapse file tree 2 files changed +5
-19
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ public IsEqualCompressingWhiteSpace(String string) {
25
25
26
26
@ Override
27
27
public boolean matchesSafely (String item ) {
28
- return stripSpace (string ).equals (stripSpace (item ));
28
+ return stripSpaces (string ).equals (stripSpaces (item ));
29
29
}
30
30
31
31
@ Override
@@ -40,22 +40,8 @@ public void describeTo(Description description) {
40
40
.appendText (" compressing white space" );
41
41
}
42
42
43
- public String stripSpace (String toBeStripped ) {
44
- final StringBuilder result = new StringBuilder ();
45
- boolean lastWasSpace = true ;
46
- for (int i = 0 ; i < toBeStripped .length (); i ++) {
47
- char c = toBeStripped .charAt (i );
48
- if (isWhitespace (c )) {
49
- if (!lastWasSpace ) {
50
- result .append (' ' );
51
- }
52
- lastWasSpace = true ;
53
- } else {
54
- result .append (c );
55
- lastWasSpace = false ;
56
- }
57
- }
58
- return result .toString ().trim ();
43
+ public String stripSpaces (String toBeStripped ) {
44
+ return toBeStripped .replaceAll ("\\ s+" , " " ).trim ();
59
45
}
60
46
61
47
/**
Original file line number Diff line number Diff line change 7
7
8
8
public class IsEqualCompressingWhiteSpaceTest extends AbstractMatcherTest {
9
9
10
- private final Matcher <String > matcher = equalToCompressingWhiteSpace ("Hello World how\n are we? " );
10
+ private final Matcher <String > matcher = equalToCompressingWhiteSpace (" Hello World how\n are we? " );
11
11
12
12
@ Override
13
13
protected Matcher <?> createMatcher () {
@@ -38,7 +38,7 @@ public void testFailsIfMatchingAgainstNull() {
38
38
}
39
39
40
40
public void testHasAReadableDescription () {
41
- assertDescription ("a string equal to \" Hello World how\\ n are we? \" compressing white space" ,
41
+ assertDescription ("a string equal to \" Hello World how\\ n are we? \" compressing white space" ,
42
42
matcher );
43
43
}
44
44
}
You can’t perform that action at this time.
0 commit comments