File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
spring-core/src/main/java/org/springframework/util Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -209,14 +209,18 @@ public static String trimWhitespace(String str) {
209
209
return str ;
210
210
}
211
211
212
- StringBuilder sb = new StringBuilder (str );
213
- while (sb .length () > 0 && Character .isWhitespace (sb .charAt (0 ))) {
214
- sb .deleteCharAt (0 );
212
+ int beginIndex = 0 ;
213
+ int endIndex = str .length () - 1 ;
214
+
215
+ while (beginIndex <= endIndex && Character .isWhitespace (str .charAt (beginIndex ))) {
216
+ beginIndex ++;
215
217
}
216
- while (sb .length () > 0 && Character .isWhitespace (sb .charAt (sb .length () - 1 ))) {
217
- sb .deleteCharAt (sb .length () - 1 );
218
+
219
+ while (endIndex > beginIndex && Character .isWhitespace (str .charAt (endIndex ))) {
220
+ endIndex --;
218
221
}
219
- return sb .toString ();
222
+
223
+ return str .substring (beginIndex , endIndex + 1 );
220
224
}
221
225
222
226
/**
You can’t perform that action at this time.
0 commit comments