commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From garydgregory <...@git.apache.org>
Subject [GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings
Date Fri, 12 Jan 2018 17:15:35 GMT
Github user garydgregory commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r161277512
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7429,6 +7429,55 @@ public static String defaultString(final String str, final String
defaultStr) {
             return isEmpty(str) ? defaultStr : str;
         }
     
    +    // Extensions
    +    //-----------------------------------------------------------------------
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix and suffix
attached,
    +     * or if the String is whitespace, empty ("") or {@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.extendIfNotBlank(null, "pre-", "-post")  = ""
    +     * StringUtils.extendIfNotBlank("", "pre-", "-post")    = ""
    +     * StringUtils.extendIfNotBlank(" ", "pre-", "-post")   = ""
    +     * StringUtils.extendIfNotBlank("bat", "pre-", "-post") = "pre-bat-bost"
    +     * StringUtils.extendIfNotBlank("bat", null, "-post")      = "bat-post"
    +     * StringUtils.extendIfNotBlank("bat", "pre-", null)      = "pre-bat"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if not blank. Null will be converted to empty
string.
    +     * @param suffix  the string to append if not blank. Null will be converted to empty
string.
    +     * @return the passed in String with prefix and suffix added, or empty string
    +     * @see StringUtils#defaultString(String, String)
    +     */
    +    public static String extendIfNotBlank(final String str, final String prefix, final
String suffix) {
    +        return isBlank(str) ? "" : defaultString(prefix) + str + defaultString(suffix);
    --- End diff --
    
    Reuse the EMPTY constant.


---

Mime
View raw message