lampac/Shared/Engine/Rex/RxSplit.cs
lampac-talks f843f04fd4 chore: initial commit 154.3
Signed-off-by: lampac-talks <lampac-talks@users.noreply.github.com>
2026-01-30 16:23:09 +03:00

41 lines
1.1 KiB
C#

using System.Text.RegularExpressions;
namespace Shared.Engine.RxEnumerate
{
public ref struct RxSplit
{
private readonly ReadOnlySpan<char> _html;
private readonly List<Range> _ranges = new List<Range>(100);
private readonly string _pattern;
public RxSplit(string pattern, ReadOnlySpan<char> html, int skip, RegexOptions options = RegexOptions.CultureInvariant)
{
_html = html;
_pattern = pattern;
int i = 0;
foreach (Range r in Regex.EnumerateSplits(html, pattern, options))
{
if (i++ < skip)
continue;
_ranges.Add(r);
}
}
public int Count => _ranges.Count;
public RowEnumerable Rows() => new RowEnumerable(_html, _ranges, _pattern);
public RxRow this[int index]
{
get
{
if ((uint)index >= (uint)_ranges.Count)
throw new ArgumentOutOfRangeException(nameof(index));
return new RxRow(_html, _ranges[index], _pattern);
}
}
}
}