You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/08/09 16:47:15 UTC

[GitHub] [commons-lang] sebbASF commented on a change in pull request #565: [LANG-1576] refine StringUtils.chomp

sebbASF commented on a change in pull request #565:
URL: https://github.com/apache/commons-lang/pull/565#discussion_r467604598



##########
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) {

Review comment:
       The changes would be clearer if the original condition had been kept.




----------------------------------------------------------------
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:
users@infra.apache.org