[
https://issues.apache.org/jira/browse/LANG-1576?focusedWorklogId=468339&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-468339
]
ASF GitHub Bot logged work on LANG-1576:
----------------------------------------
Author: ASF GitHub Bot
Created on: 09/Aug/20 16:49
Start Date: 09/Aug/20 16:49
Worklog Time Spent: 10m
Work Description: sebbASF commented on a change in pull request #565:
URL: https://github.com/apache/commons-lang/pull/565#discussion_r467604760
##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -697,27 +697,29 @@ public static String center(String str, final int size,
String padStr) {
* @return String without newline, {@code null} if null String input
*/
public static String chomp(final String str) {
- if (isEmpty(str)) {
+ final int length = length(str);
+
+ if (length == 0) {
return str;
}
- if (str.length() == 1) {
+ if (length == 1) {
final char ch = str.charAt(0);
if (ch == CharUtils.CR || ch == CharUtils.LF) {
return EMPTY;
}
return str;
}
- int lastIdx = str.length() - 1;
+ int lastIdx = length - 1;
final char last = str.charAt(lastIdx);
- if (last == CharUtils.LF) {
- if (str.charAt(lastIdx - 1) == CharUtils.CR) {
- lastIdx--;
+ if (last != CharUtils.LF) {
+ if (last != CharUtils.CR) {
+ return str;
}
- } else if (last != CharUtils.CR) {
- lastIdx++;
+ } else if (str.charAt(lastIdx - 1) == CharUtils.CR) {
+ --lastIdx;
Review comment:
Better to use lastIdx-- here - don't make unnecessary changes
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 468339)
Time Spent: 4h 50m (was: 4h 40m)
> refine StringUtils.chomp
> ------------------------
>
> Key: LANG-1576
> URL: https://issues.apache.org/jira/browse/LANG-1576
> Project: Commons Lang
> Issue Type: Sub-task
> Reporter: Jin Xu
> Priority: Minor
> Time Spent: 4h 50m
> Remaining Estimate: 0h
>
> [https://github.com/apache/commons-lang/pull/565]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)