commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From RahulNagekar <...@git.apache.org>
Subject [GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings
Date Sat, 01 Dec 2018 07:21:59 GMT
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238055353
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9008,6 +9011,56 @@ public static String appendIfMissingIgnoreCase(final String str,
final CharSeque
             return appendIfMissing(str, suffix, true, suffixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = "  "
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = " -post"
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc "
    +     * StringUtils.appendIfNotBlank("abc", "-post") = "abc-post"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param suffix  the string to append if 'str' is not empty. Null will be converted
to empty string.
    +     * @return the passed in String with suffix added, or empty string
    +     */
    +    public static String appendIfNotEmpty(final String str, final String suffix) {
    +        return isEmpty(str) ? EMPTY : str + defaultString(suffix);
    --- End diff --
    
    ```suggestion
            return isEmpty(str) ? str : str + defaultString(suffix);
    ```


---

Mime
View raw message