diff --git a/source/Nuke.Utilities/Text/String.Emptiness.cs b/source/Nuke.Utilities/Text/String.Emptiness.cs
index d25cfca3c..f48cfe61c 100644
--- a/source/Nuke.Utilities/Text/String.Emptiness.cs
+++ b/source/Nuke.Utilities/Text/String.Emptiness.cs
@@ -19,7 +19,7 @@ public static bool IsNullOrEmpty(this string str)
}
///
- /// Indicates whether a specified string is null, empty, or consists only of white-space characters.
+ /// Indicates whether a specified string is null, empty, or only white-space.
///
[Pure]
[ContractAnnotation("null => halt")]
@@ -27,4 +27,24 @@ public static bool IsNullOrWhiteSpace(this string str)
{
return string.IsNullOrWhiteSpace(str);
}
+
+ ///
+ /// Returns null if the specified string is empty.
+ ///
+ [Pure]
+ [ContractAnnotation("null => null")]
+ public static string ToNullIfEmpty(this string str)
+ {
+ return str.IsNullOrEmpty() ? null : str;
+ }
+
+ ///
+ /// Returns null if the specified string is empty or only white-space.
+ ///
+ [Pure]
+ [ContractAnnotation("null => null")]
+ public static string ToNullIfWhiteSpace(this string str)
+ {
+ return str.IsNullOrWhiteSpace() ? null : str;
+ }
}
diff --git a/source/Nuke.Utilities/Text/String.Split.cs b/source/Nuke.Utilities/Text/String.Split.cs
index 602e64121..3c1f72758 100644
--- a/source/Nuke.Utilities/Text/String.Split.cs
+++ b/source/Nuke.Utilities/Text/String.Split.cs
@@ -64,9 +64,18 @@ public static IEnumerable SplitCamelHumps(this string str, params string
/// Splits a given string by new-lines with empty entries preserved.
///
[Pure]
- public static string[] SplitLineBreaks(this string str)
+ public static string[] SplitLineBreaks(this string str, StringSplitOptions options = StringSplitOptions.None)
{
- return str.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
+ return str.Split(new[] { "\r\n", "\n" }, options);
+ }
+
+ ///
+ /// Splits a given string by paragraphs (double new-line) with empty entries preserved.
+ ///
+ [Pure]
+ public static string[] SplitParagraphs(this string str, StringSplitOptions options = StringSplitOptions.None)
+ {
+ return str.Split(new[] { "\r\n\r\n", "\n\n" }, options);
}
///