From 9de207eb2d3b058587c0de4be4dda4f4c790949f Mon Sep 17 00:00:00 2001 From: Neil MacMullen Date: Sun, 3 Mar 2024 13:56:02 +0000 Subject: [PATCH] Prepare for nuget release --- NotNullStrings/NotNullStrings.csproj | 28 +++++++++++++++++++++++++-- NotNullStrings/StringExtensions.cs | 29 +++++++++++++++------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/NotNullStrings/NotNullStrings.csproj b/NotNullStrings/NotNullStrings.csproj index fa71b7a..d9c4619 100644 --- a/NotNullStrings/NotNullStrings.csproj +++ b/NotNullStrings/NotNullStrings.csproj @@ -1,9 +1,33 @@ - + - net8.0 + net8.0 + false enable enable + NotNullStrings + Basic C# string extensions that avoid null + (C) Neil MacMullen + https://github.com/NeilMacMullen/NotNullStrings + README.md + https://github.com/NeilMacMullen/NotNullStrings + C# string + Initial release + LICENSE + True + 1.0.1 + + + True + \ + + + True + \ + + + + diff --git a/NotNullStrings/StringExtensions.cs b/NotNullStrings/StringExtensions.cs index 3673fae..e842e88 100644 --- a/NotNullStrings/StringExtensions.cs +++ b/NotNullStrings/StringExtensions.cs @@ -1,4 +1,6 @@ -namespace NotNullStrings; +// ReSharper disable UnusedMember.Global + +namespace NotNullStrings; public static class StringExtensions { @@ -24,26 +26,26 @@ public static string JoinString(this IEnumerable items, string separator, /// /// Splits string into array of non-empty tokens separated by any of the characters in separationChars /// - public static string[] Tokenise(this string input, string separationCharacters) + public static string[] Tokenize(this string? input, string separationCharacters) { - if (input == null) - return []; - return input.Split(separationCharacters.ToCharArray(), StringSplitOptions.RemoveEmptyEntries) - .Select(t => t.Trim()) - .Where(t => t.Length != 0) - .ToArray(); + return input == null + ? [] + : input.Split(separationCharacters.ToCharArray(), StringSplitOptions.RemoveEmptyEntries) + .Select(t => t.Trim()) + .Where(t => t.Length != 0) + .ToArray(); } /// - /// Tokenises all strings in input into a single array by splitting at any of separationCharacters + /// Tokenizes all strings in input into a single array by splitting at any of separationCharacters /// - public static string[] Tokenise(this IEnumerable input, string separationCharacters) - => input.SelectMany(s => s.Tokenise(separationCharacters)).ToArray(); + public static string[] Tokenize(this IEnumerable input, string separationCharacters) + => input.SelectMany(s => s.Tokenize(separationCharacters)).ToArray(); /// /// Splits string into array of non-empty tokens separated by space /// - public static string[] Tokenise(this string input) => input.Tokenise(" \t"); + public static string[] Tokenize(this string input) => input.Tokenize(" \t"); public static bool IsBlank(this string s) => string.IsNullOrWhiteSpace(s); public static bool IsNotBlank(this string s) => !s.IsBlank(); @@ -56,6 +58,7 @@ public static string OrWhenBlank(this string s, string fallback) ? fallback : s; - public static string NullToEmpty(this string s) + + public static string NullToEmpty(this string? s) => s ?? string.Empty; } \ No newline at end of file