Skip to content

Commit

Permalink
Imported some recent changes from JasperFx.Core for ToDelimitedArray(…
Browse files Browse the repository at this point in the history
…) removing nulls and trimming
  • Loading branch information
jeremydmiller committed Dec 2, 2024
1 parent d9c93a3 commit 0af0b10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/CoreTests/Core/StringExtensionsTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ public void ends_with_ignore_case(string one, string suffix, bool expected)
{
one.EndsWithIgnoreCase(suffix).ShouldBe(expected);
}

[Theory]
[InlineData("", 0)]
[InlineData("foo=bar", 1)]
[InlineData("foo=bar;", 1)]
[InlineData("foo=bar;zap=42;", 2)]
[InlineData("foo=bar;zap=42", 2)]
public void removes_empty_entries_when_splitting_strings_into_array(string one, int expectedCount)
{
var array = one.ToDelimitedArray(';');

array.Length.ShouldBe(expectedCount);
array.All(x => x.IsNotEmpty()).ShouldBeTrue();
}

public struct NotAnEnum
{
Expand Down
2 changes: 1 addition & 1 deletion src/JasperFx/Core/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static string[] ToDelimitedArray(this string content)
/// <returns></returns>
public static string[] ToDelimitedArray(this string content, char delimiter)
{
var array = content.Split(delimiter);
var array = content.Split(delimiter, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
for (var i = 0; i < array.Length; i++)
{
array[i] = array[i].Trim();
Expand Down

0 comments on commit 0af0b10

Please sign in to comment.