diff --git a/Split/Extensions/SpanExtensions.cs b/Split/Extensions/SpanExtensions.cs index fe4b416..f6da389 100644 --- a/Split/Extensions/SpanExtensions.cs +++ b/Split/Extensions/SpanExtensions.cs @@ -25,6 +25,8 @@ public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, R public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, string separators) => Span.SplitAny(source, separators); + public static SplitEnumerator SplitOnAny(this string source, SearchValues separators) => + Span.SplitAny(source, separators); public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, SearchValues separators) => Span.SplitAny(source, separators); @@ -32,6 +34,9 @@ public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, S public static SplitEnumerator SplitOn(this byte[] source, byte separator) => Span.Split(source, separator); + public static SplitEnumerator SplitOn(this byte[] source, ReadOnlySpan separator) => + Span.Split(source, separator); + public static SplitEnumerator SplitOn(this ReadOnlySpan source, byte separator) => Span.Split(source, separator); @@ -42,6 +47,9 @@ public static SplitEnumerator SplitOn(this ReadOnlySpan source, Read public static SplitEnumerator SplitOnAny(this byte[] source, ReadOnlySpan separators) => Span.SplitAny(source, separators); + public static SplitEnumerator SplitOnAny(this byte[] source, SearchValues separators) => + Span.SplitAny(source, separators); + public static SplitEnumerator SplitOnAny(this ReadOnlySpan source, ReadOnlySpan separators) => Span.SplitAny(source, separators); diff --git a/Tests/Basic.cs b/Tests/Basic.cs index 6200392..537c72d 100644 --- a/Tests/Basic.cs +++ b/Tests/Basic.cs @@ -1,5 +1,6 @@ namespace Tests; +using System.Buffers; using System.Text; using Split; using Split.Extensions; @@ -61,4 +62,68 @@ public void Readme() Console.WriteLine("\"" + Encoding.UTF8.GetString(word) + "\""); } } + + [Fact] + public void Overloads() + { + // Just to avoid breaking the API, no actual tests + + var example = "foo"; + { + char separator = ' '; + Span.Split(example, separator); + + var separators = ". "; + Span.Split(example, separators); + Span.SplitAny(example, separators); + + var search = SearchValues.Create(separators); + Span.SplitAny(example, search); + } + + var bytes = Encoding.UTF8.GetBytes(example); + { + byte separator = (byte)' '; + Span.Split(bytes, separator); + + var separators = ". "u8; + Span.Split(bytes, separators); + Span.SplitAny(bytes, separators); + + var search = SearchValues.Create(separators); + Span.SplitAny(bytes, search); + } + } + + [Fact] + public void Extensions() + { + // Just to avoid breaking the API, no actual tests + + var example = "foo"; + { + char separator = ' '; + example.SplitOn(separator); + + var separators = ". "; + example.SplitOn(separators); + example.SplitOnAny(separators); + + var search = SearchValues.Create(separators); + example.SplitOnAny(search); + } + + var bytes = Encoding.UTF8.GetBytes(example); + { + byte separator = (byte)' '; + bytes.SplitOn(separator); + + var separators = ". "u8; + bytes.SplitOn(separators); + bytes.SplitOnAny(separators); + + var search = SearchValues.Create(separators); + bytes.SplitOnAny(search); + } + } }