SpanHelper
This commit is contained in:
parent
eec2ec60be
commit
a9c0e1172f
39
DTLib/Extensions/SpanHelper.cs
Normal file
39
DTLib/Extensions/SpanHelper.cs
Normal file
@ -0,0 +1,39 @@
|
||||
namespace DTLib.Extensions;
|
||||
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET2_1_OR_GREATER
|
||||
public static class SpanHelper
|
||||
{
|
||||
public static ReadOnlySpan<char> After(this ReadOnlySpan<char> span, char c)
|
||||
{
|
||||
var index = span.IndexOf(c);
|
||||
if (index == -1)
|
||||
throw new Exception($"char <{c}> not found in span <{span}>");
|
||||
return span.Slice(index+1);
|
||||
}
|
||||
|
||||
public static ReadOnlySpan<char> After(this ReadOnlySpan<char> span, ReadOnlySpan<char> s)
|
||||
{
|
||||
var index = span.IndexOf(s);
|
||||
if (index == -1)
|
||||
throw new Exception($"span <{s}> not found in span <{span}>");
|
||||
return span.Slice(index+s.Length);
|
||||
}
|
||||
|
||||
|
||||
public static ReadOnlySpan<char> Before(this ReadOnlySpan<char> span, char c)
|
||||
{
|
||||
var index = span.IndexOf(c);
|
||||
if (index == -1)
|
||||
throw new Exception($"char <{c}> not found in span <{span}>");
|
||||
return span.Slice(0,index);
|
||||
}
|
||||
|
||||
public static ReadOnlySpan<char> Before(this ReadOnlySpan<char> span, ReadOnlySpan<char> s)
|
||||
{
|
||||
var index = span.IndexOf(s);
|
||||
if (index == -1)
|
||||
throw new Exception($"span <{s}> not found in span <{span}>");
|
||||
return span.Slice(0,index);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user