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_r238055382
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9109,6 +9162,56 @@ public static String prependIfMissingIgnoreCase(final String str,
final CharSequ
             return prependIfMissing(str, prefix, true, prefixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.prependIfNotEmpty(null, " ")     = ""
    +     * StringUtils.prependIfNotEmpty(null, "pre-")  = ""
    +     * StringUtils.prependIfNotEmpty("", "pre-")    = ""
    +     * StringUtils.prependIfNotEmpty(" ", " ")      = "  "
    +     * StringUtils.prependIfNotEmpty(" ", "pre-")   = "pre- "
    +     * StringUtils.prependIfNotEmpty("abc", null)   = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", "")     = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", " ")    = " abc"
    +     * StringUtils.prependIfNotEmpty("abc", "pre-") = "pre-abc"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if 'str' is not blank. Null will be converted
to empty string.
    +     * @return the passed in String with prefix added, or empty string
    +     */
    +    public static String prependIfNotEmpty(final String str, final String prefix) {
    +        return isEmpty(str) ? EMPTY : defaultString(prefix) + str;
    --- End diff --
    
    ```suggestion
            return isEmpty(str) ? str : defaultString(prefix) + str;
    ```


---

Mime
View raw message