Browse Source

Merge pull request #27703 from xixingya:feat/stringstrip

* gh-27703:
  Use String::strip in StringUtils::trimWhitespace
pull/27779/head
Arjen Poutsma 4 years ago
parent
commit
982ba0e86d
  1. 25
      spring-core/src/main/java/org/springframework/util/StringUtils.java

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

@ -224,18 +224,7 @@ public abstract class StringUtils {
return str; return str;
} }
int beginIndex = 0; return str.strip();
int endIndex = str.length() - 1;
while (beginIndex <= endIndex && Character.isWhitespace(str.charAt(beginIndex))) {
beginIndex++;
}
while (endIndex > beginIndex && Character.isWhitespace(str.charAt(endIndex))) {
endIndex--;
}
return str.substring(beginIndex, endIndex + 1);
} }
/** /**
@ -272,11 +261,7 @@ public abstract class StringUtils {
return str; return str;
} }
int beginIdx = 0; return str.stripLeading();
while (beginIdx < str.length() && Character.isWhitespace(str.charAt(beginIdx))) {
beginIdx++;
}
return str.substring(beginIdx);
} }
/** /**
@ -290,11 +275,7 @@ public abstract class StringUtils {
return str; return str;
} }
int endIdx = str.length() - 1; return str.stripTrailing();
while (endIdx >= 0 && Character.isWhitespace(str.charAt(endIdx))) {
endIdx--;
}
return str.substring(0, endIdx + 1);
} }
/** /**

Loading…
Cancel
Save