File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
main/java/com/github/vertical_blank/sqlformatter/core/util
test/groovy/com/github/vertical_blank/sqlformatter/core/util Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,12 @@ public static <T> List<T> nullToEmpty(List<T> ts) {
19
19
}
20
20
21
21
public static String trimEnd (String s ) {
22
- return s .replaceAll ("[ |\\ n|\\ r]*$" , "" );
22
+ int endIndex = s .length ();
23
+ char [] chars = s .toCharArray ();
24
+ while (endIndex > 0 && (chars [endIndex - 1 ] == ' ' || chars [endIndex - 1 ] == '\n' || chars [endIndex - 1 ] == '\r' )) {
25
+ endIndex --;
26
+ }
27
+ return new String (chars , 0 , endIndex );
23
28
}
24
29
25
30
public static String escapeRegExp (String s ) {
Original file line number Diff line number Diff line change @@ -9,5 +9,17 @@ class UtilTest {
9
9
def escaped = Util . escapeRegExp(' [lodash](https://lodash.com/)' )
10
10
assert escaped == ''' \\ [lodash\\ ]\\ (https://lodash\\ .com/\\ )'''
11
11
}
12
+ @Test
13
+ void testTrimEnd () {
14
+ assert " " == Util . trimEnd(" " );
15
+ assert " " == Util . trimEnd(" " );
16
+ assert " \r\n abc" == Util . trimEnd(" \r\n abc" );
17
+ assert " \r\n abc" == Util . trimEnd(" \r\n abc " );
18
+ assert " \r\n abc" == Util . trimEnd(" \r\n abc\n " );
19
+ assert " \r\n abc" == Util . trimEnd(" \r\n abc\r " );
20
+ assert " \r\n abc" == Util . trimEnd(" \r\n abc\r\n " );
21
+ assert " \r\n abc" == Util . trimEnd(" \r\n abc\r\n " );
22
+ assert " \r\n abc" == Util . trimEnd(" \r\n abc \r\n \n " );
23
+ }
12
24
13
25
}
You can’t perform that action at this time.
0 commit comments