Skip to content

Commit

Permalink
more overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
clipperhouse committed Jul 19, 2024
1 parent 1c518db commit 236014c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
51 changes: 51 additions & 0 deletions Split/Extensions/SpanExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Buffers;

namespace Split.Extensions;

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

public static SplitEnumerator<char> SplitOn(this string source, string 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);

public static SplitEnumerator<char> SplitOnAny(this string source, ReadOnlySpan<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, string separators) =>
Span.SplitAny(source, separators);

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


public static SplitEnumerator<byte> SplitOn(this 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 ReadOnlySpan<byte> source, ReadOnlySpan<byte> separator) =>
Span.Split(source, separator);


public static SplitEnumerator<byte> SplitOnAny(this byte[] source, ReadOnlySpan<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);

}
18 changes: 0 additions & 18 deletions Split/SpanExtensions.cs

This file was deleted.

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

namespace Split;

public static class Span
{
public static SplitEnumerator<char> Split(ReadOnlySpan<char> source, char separator) =>
new SplitEnumerator<char>(source, separator);

public static SplitEnumerator<char> Split(ReadOnlySpan<char> source, ReadOnlySpan<char> separator) =>
new SplitEnumerator<char>(source, separator, true);

public static SplitEnumerator<char> SplitAny(ReadOnlySpan<char> source, ReadOnlySpan<char> separators) =>
new SplitEnumerator<char>(source, separators);

public static SplitEnumerator<char> SplitAny(ReadOnlySpan<char> source, SearchValues<char> separators) =>
new SplitEnumerator<char>(source, separators);

public static SplitEnumerator<byte> Split(ReadOnlySpan<byte> source, byte separator) =>
new SplitEnumerator<byte>(source, separator);

public static SplitEnumerator<byte> Split(ReadOnlySpan<byte> source, ReadOnlySpan<byte> separator) =>
new SplitEnumerator<byte>(source, separator, true);

public static SplitEnumerator<byte> SplitAny(ReadOnlySpan<byte> source, ReadOnlySpan<byte> separators) =>
new SplitEnumerator<byte>(source, separators);

public static SplitEnumerator<byte> SplitAny(ReadOnlySpan<byte> source, SearchValues<byte> separators) =>
new SplitEnumerator<byte>(source, separators);

}
5 changes: 3 additions & 2 deletions Tests/Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Text;
using Split;
using Split.Extensions;

public class BasicTests
{
Expand Down Expand Up @@ -53,11 +54,11 @@ public void Readme()

Console.WriteLine("Mine:");

var words2 = example.AsSpan().SplitOnAny(" .");
var words2 = bytes.SplitOnAny(". "u8); ;

foreach (var word in words2)
{
Console.WriteLine("\"" + word.ToString() + "\"");
Console.WriteLine("\"" + Encoding.UTF8.GetString(word) + "\"");
}
}
}

0 comments on commit 236014c

Please sign in to comment.