diff --git a/Split/Extensions/SpanExtensions.cs b/Split/Extensions/SpanExtensions.cs new file mode 100644 index 0000000..fe4b416 --- /dev/null +++ b/Split/Extensions/SpanExtensions.cs @@ -0,0 +1,51 @@ +using System.Buffers; + +namespace Split.Extensions; + +public static class SpanExtensions +{ + public static SplitEnumerator SplitOn(this string source, char separator) => + Span.Split(source, separator); + + public static SplitEnumerator SplitOn(this string source, string separator) => + Span.Split(source, separator); + + public static SplitEnumerator SplitOn(this ReadOnlySpan source, char separator) => + Span.Split(source, separator); + + public static SplitEnumerator SplitOn(this ReadOnlySpan source, ReadOnlySpan separator) => + Span.Split(source, separator); + + public static SplitEnumerator SplitOnAny(this string source, ReadOnlySpan separators) => + Span.SplitAny(source, separators); + + public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, ReadOnlySpan separators) => + Span.SplitAny(source, separators); + + public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, string separators) => + Span.SplitAny(source, separators); + + public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, SearchValues separators) => + Span.SplitAny(source, separators); + + + public static SplitEnumerator SplitOn(this byte[] source, byte separator) => + Span.Split(source, separator); + + public static SplitEnumerator SplitOn(this ReadOnlySpan source, byte separator) => + Span.Split(source, separator); + + public static SplitEnumerator SplitOn(this ReadOnlySpan source, ReadOnlySpan separator) => + Span.Split(source, separator); + + + public static SplitEnumerator SplitOnAny(this byte[] source, ReadOnlySpan separators) => + Span.SplitAny(source, separators); + + public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, ReadOnlySpan separators) => + Span.SplitAny(source, separators); + + public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, SearchValues separators) => + Span.SplitAny(source, separators); + +} diff --git a/Split/SpanExtensions.cs b/Split/SpanExtensions.cs deleted file mode 100644 index da97d51..0000000 --- a/Split/SpanExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Buffers; - -namespace Split; - -public static class SpanExtensions -{ - public static SplitEnumerator SplitOn(this ReadOnlySpan source, T separator) where T : IEquatable => - new SplitEnumerator(source, separator); - - public static SplitEnumerator SplitOn(this ReadOnlySpan source, ReadOnlySpan separator) where T : IEquatable => - new SplitEnumerator(source, separator, true); - - public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, ReadOnlySpan separators) where T : IEquatable => - new SplitEnumerator(source, separators); - - public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, SearchValues separators) where T : IEquatable => - new SplitEnumerator(source, separators); -} diff --git a/Split/Split.cs b/Split/Split.cs new file mode 100644 index 0000000..23420d2 --- /dev/null +++ b/Split/Split.cs @@ -0,0 +1,31 @@ +using System.Buffers; + +namespace Split; + +public static class Span +{ + public static SplitEnumerator Split(ReadOnlySpan source, char separator) => + new SplitEnumerator(source, separator); + + public static SplitEnumerator Split(ReadOnlySpan source, ReadOnlySpan separator) => + new SplitEnumerator(source, separator, true); + + public static SplitEnumerator SplitAny(ReadOnlySpan source, ReadOnlySpan separators) => + new SplitEnumerator(source, separators); + + public static SplitEnumerator SplitAny(ReadOnlySpan source, SearchValues separators) => + new SplitEnumerator(source, separators); + + public static SplitEnumerator Split(ReadOnlySpan source, byte separator) => + new SplitEnumerator(source, separator); + + public static SplitEnumerator Split(ReadOnlySpan source, ReadOnlySpan separator) => + new SplitEnumerator(source, separator, true); + + public static SplitEnumerator SplitAny(ReadOnlySpan source, ReadOnlySpan separators) => + new SplitEnumerator(source, separators); + + public static SplitEnumerator SplitAny(ReadOnlySpan source, SearchValues separators) => + new SplitEnumerator(source, separators); + +} diff --git a/Tests/Basic.cs b/Tests/Basic.cs index d90c5d4..6200392 100644 --- a/Tests/Basic.cs +++ b/Tests/Basic.cs @@ -2,6 +2,7 @@ using System.Text; using Split; +using Split.Extensions; public class BasicTests { @@ -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) + "\""); } } }