Skip to content

Commit 32df079

Browse files
J-unStiNsbrannen
authored andcommitted
Polish use of constants in StringUtils
The hardcoded '.' and '\\' literals have been replaced by the use of EXTENSION_SEPARATOR and WINDOWS_FOLDER_SEPARATOR_CHAR. Closes gh-33654
1 parent d89983d commit 32df079

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public abstract class StringUtils {
7272

7373
private static final String WINDOWS_FOLDER_SEPARATOR = "\\";
7474

75+
private static final char WINDOWS_FOLDER_SEPARATOR_CHAR = '\\';
76+
7577
private static final String DOUBLE_BACKSLASHES = "\\\\";
7678

7779
private static final String TOP_PATH = "..";
@@ -712,7 +714,7 @@ public static String cleanPath(String path) {
712714

713715
String normalizedPath;
714716
// Optimize when there is no backslash
715-
if (path.indexOf('\\') != -1) {
717+
if (path.indexOf(WINDOWS_FOLDER_SEPARATOR_CHAR) != -1) {
716718
normalizedPath = replace(path, DOUBLE_BACKSLASHES, FOLDER_SEPARATOR);
717719
normalizedPath = replace(normalizedPath, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);
718720
}
@@ -722,7 +724,7 @@ public static String cleanPath(String path) {
722724
String pathToUse = normalizedPath;
723725

724726
// Shortcut if there is no work to do
725-
if (pathToUse.indexOf('.') == -1) {
727+
if (pathToUse.indexOf(EXTENSION_SEPARATOR) == -1) {
726728
return pathToUse;
727729
}
728730

0 commit comments

Comments
 (0)