Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change StringUtils trimWhitespace to String.strip() #27703

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,7 @@ public static String trimWhitespace(String str) {
return str;
}

int beginIndex = 0;
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);
return str.strip();
}

/**
Expand Down Expand Up @@ -272,11 +261,7 @@ public static String trimLeadingWhitespace(String str) {
return str;
}

int beginIdx = 0;
while (beginIdx < str.length() && Character.isWhitespace(str.charAt(beginIdx))) {
beginIdx++;
}
return str.substring(beginIdx);
return str.stripLeading();
}

/**
Expand All @@ -290,11 +275,7 @@ public static String trimTrailingWhitespace(String str) {
return str;
}

int endIdx = str.length() - 1;
while (endIdx >= 0 && Character.isWhitespace(str.charAt(endIdx))) {
endIdx--;
}
return str.substring(0, endIdx + 1);
return str.stripTrailing();
}

/**
Expand Down