arturobernalg commented on a change in pull request #646:
URL: https://github.com/apache/commons-lang/pull/646#discussion_r523203876



##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -7274,6 +7274,52 @@ public static String rightPad(final String str, final 
int size, String padStr) {
         }
     }
 
+    /**
+     * <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.defaultIfNotBlank(null, "pre-", "-post")  = ""
+     * StringUtils.defaultIfNotBlank("", "pre-", "-post")    = ""
+     * StringUtils.defaultIfNotBlank(" ", "pre-", "-post")   = ""
+     * StringUtils.defaultIfNotBlank("bat", "pre-", "-post") = "pre-bat-bost"
+     * StringUtils.defaultIfNotBlank("bat", null, "-post")      = "bat-post"
+     * StringUtils.defaultIfNotBlank("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 defaultIfNotBlank(final String str, final String 
prefix, final String suffix) {
+        return isBlank(str) ? "" : defaultString(prefix) + str + 
defaultString(suffix);

Review comment:
       Done




----------------------------------------------------------------
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]


Reply via email to