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/04/24 03:21:04 UTC

[GitHub] [commons-lang] ThrawnCA commented on a change in pull request #278: Lang-1345 Enhance non-empty strings

ThrawnCA commented on a change in pull request #278:
URL: https://github.com/apache/commons-lang/pull/278#discussion_r414262777



##########
File path: 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);

Review comment:
       Adjusted to return the unchanged string instead.




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