ThrawnCA commented on a change in pull request #278:
URL: https://github.com/apache/commons-lang/pull/278#discussion_r414263302
##########
File path: 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;
+ }
+
+ /**
+ * <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.prependIfNotBlank(null, " ") = ""
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]