ThrawnCA commented on a change in pull request #278:
URL: https://github.com/apache/commons-lang/pull/278#discussion_r414263210
##########
File path: 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);
+ }
+
+ /**
+ * <p>Returns either the passed in String with the specified suffix
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.appendIfNotBlank(null, " ") = ""
+ * StringUtils.appendIfNotBlank(null, "-post") = ""
+ * StringUtils.appendIfNotBlank("", "-post") = ""
+ * StringUtils.appendIfNotBlank(" ", " ") = ""
Review comment:
Original string is now preserved.
----------------------------------------------------------------
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]