Skip to content

Commit

Permalink
more extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
clipperhouse committed Jul 19, 2024
1 parent a75d145 commit ffa77d6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 60 deletions.
59 changes: 0 additions & 59 deletions Split/Extensions/SpanExtensions.cs

This file was deleted.

16 changes: 16 additions & 0 deletions Split/Extensions/SplitOn.Byte.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Split.Extensions;

public static partial class SpanExtensions
{
public static SplitEnumerator<byte> SplitOn(this byte[] source, byte separator) => Span.Split(source, separator);

public static SplitEnumerator<byte> SplitOn(this Span<byte> source, byte separator) => Span.Split(source, separator);

public static SplitEnumerator<byte> SplitOn(this ReadOnlySpan<byte> source, byte separator) => Span.Split(source, separator);

public static SplitEnumerator<byte> SplitOn(this byte[] source, ReadOnlySpan<byte> separator) => Span.Split(source, separator);

public static SplitEnumerator<byte> SplitOn(this Span<byte> source, ReadOnlySpan<byte> separator) => Span.Split(source, separator);

public static SplitEnumerator<byte> SplitOn(this ReadOnlySpan<byte> source, ReadOnlySpan<byte> separator) => Span.Split(source, separator);
}
13 changes: 13 additions & 0 deletions Split/Extensions/SplitOn.Char.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Split.Extensions;

public static partial class SpanExtensions
{
public static SplitEnumerator<char> SplitOn(this string source, char separator) => Span.Split(source, separator);

public static SplitEnumerator<char> SplitOn(this string source, ReadOnlySpan<char> separator) => Span.Split(source, separator);

public static SplitEnumerator<char> SplitOn(this ReadOnlySpan<char> source, char separator) => Span.Split(source, separator);

public static SplitEnumerator<char> SplitOn(this ReadOnlySpan<char> source, ReadOnlySpan<char> separator) => Span.Split(source, separator);

}
14 changes: 14 additions & 0 deletions Split/Extensions/SplitOnAny.Byte.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Buffers;

namespace Split.Extensions;

public static partial class SpanExtensions
{
public static SplitEnumerator<byte> SplitOnAny(this byte[] source, ReadOnlySpan<byte> separators) => Span.SplitAny(source, separators);

public static SplitEnumerator<byte> SplitOnAny(this byte[] source, SearchValues<byte> separators) => Span.SplitAny(source, separators);

public static SplitEnumerator<byte> SplitOnAny(this ReadOnlySpan<byte> source, ReadOnlySpan<byte> separators) => Span.SplitAny(source, separators);

public static SplitEnumerator<byte> SplitOnAny(this ReadOnlySpan<byte> source, SearchValues<byte> separators) => Span.SplitAny(source, separators);
}
14 changes: 14 additions & 0 deletions Split/Extensions/SplitOnAny.Char.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Buffers;

namespace Split.Extensions;

public static partial class SpanExtensions
{
public static SplitEnumerator<char> SplitOnAny(this string source, ReadOnlySpan<char> separators) => Span.SplitAny(source, separators);

public static SplitEnumerator<char> SplitOnAny(this string source, SearchValues<char> separators) => Span.SplitAny(source, separators);

public static SplitEnumerator<char> SplitOnAny(this ReadOnlySpan<char> source, ReadOnlySpan<char> separators) => Span.SplitAny(source, separators);

public static SplitEnumerator<char> SplitOnAny(this ReadOnlySpan<char> source, SearchValues<char> separators) => Span.SplitAny(source, separators);
}
14 changes: 13 additions & 1 deletion Tests/Basic.cs → Tests/APIs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,34 @@ public void Extensions()
{
char separator = ' ';
example.SplitOn(separator);
example.AsSpan().SplitOn(separator);

var separators = ". ";
example.SplitOn(separators);
example.SplitOn(separators.AsSpan());
example.AsSpan().SplitOn(separators);
example.AsSpan().SplitOn(separators.AsSpan());

example.SplitOnAny(separators);
example.SplitOnAny(separators.AsSpan());
example.AsSpan().SplitOnAny(separators);
example.AsSpan().SplitOnAny(separators.AsSpan());

var search = SearchValues.Create(separators);
example.SplitOnAny(search);
example.AsSpan().SplitOnAny(search);
}

var bytes = Encoding.UTF8.GetBytes(example);
{
byte separator = (byte)' ';
bytes.SplitOn(separator);
bytes.AsSpan().SplitOn(separator);
ReadOnlySpan<byte> rbytes = bytes.AsSpan();
rbytes.SplitOn(separator);

var separators = ". "u8;
bytes.SplitOn(separators);
bytes.AsSpan().SplitOn(separators);
bytes.SplitOnAny(separators);

var search = SearchValues.Create(separators);
Expand Down

0 comments on commit ffa77d6

Please sign in to comment.