From 7b137978cda583867bcfb7b72e730c6b8d311eb8 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 19 Feb 2024 20:01:50 +1100 Subject: [PATCH 1/5] . --- src/Polyfill/Regex/RegexPolyfill.cs | 4 +- src/Polyfill/Regex/ValueMatch.cs | 52 ++++++++++++++ src/Polyfill/Regex/ValueMatchEnumerator.cs | 81 ++++++++++++++++++++++ 3 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/Polyfill/Regex/ValueMatch.cs create mode 100644 src/Polyfill/Regex/ValueMatchEnumerator.cs diff --git a/src/Polyfill/Regex/RegexPolyfill.cs b/src/Polyfill/Regex/RegexPolyfill.cs index d2373ad2..05667fdc 100644 --- a/src/Polyfill/Regex/RegexPolyfill.cs +++ b/src/Polyfill/Regex/RegexPolyfill.cs @@ -1,7 +1,6 @@ // #pragma warning disable -#if MEMORYREFERENCED using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -14,6 +13,7 @@ #endif static partial class RegexPolyfill { +#if MEMORYREFERENCED /// /// Indicates whether the specified regular expression finds a match in the specified input span, using the specified matching options and time-out interval. /// @@ -55,5 +55,5 @@ public static bool IsMatch(ReadOnlySpan input, string pattern) return Regex.IsMatch(input.ToString(), pattern); #endif } -} #endif +} diff --git a/src/Polyfill/Regex/ValueMatch.cs b/src/Polyfill/Regex/ValueMatch.cs new file mode 100644 index 00000000..4e6d75a5 --- /dev/null +++ b/src/Polyfill/Regex/ValueMatch.cs @@ -0,0 +1,52 @@ +// + +#pragma warning disable + +#if !NET7_0_OR_GREATER && (MEMORYREFERENCED || NET6_0 || NET5_0) + +using System; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Link = System.ComponentModel.DescriptionAttribute; + +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace System.Text.RegularExpressions; + +/// +/// Represents the results from a single regular expression match. +/// +/// +/// The type is immutable and has no public constructor. An instance of the struct is returned by the +/// method when iterating over the results from calling . +/// +public readonly ref struct ValueMatch +{ + private readonly int _index; + private readonly int _length; + + /// + /// Crates an instance of the type based on the passed in and . + /// + /// The position in the original span where the first character of the captured sliced span is found. + /// The length of the captured sliced span. + internal ValueMatch(int index, int length) + { + _index = index; + _length = length; + } + + /// + /// Gets the position in the original span where the first character of the captured sliced span is found. + /// + public int Index => _index; + + /// + /// Gets the length of the captured sliced span. + /// + public int Length => _length; +} + +#endif \ No newline at end of file diff --git a/src/Polyfill/Regex/ValueMatchEnumerator.cs b/src/Polyfill/Regex/ValueMatchEnumerator.cs new file mode 100644 index 00000000..a9291767 --- /dev/null +++ b/src/Polyfill/Regex/ValueMatchEnumerator.cs @@ -0,0 +1,81 @@ +// + +#pragma warning disable + +#if !NET7_0_OR_GREATER && (MEMORYREFERENCED || NET6_0 || NET5_0) + +using System; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace System.Text.RegularExpressions; + +/// +/// Represents an enumerator containing the set of successful matches found by iteratively applying a regular expression pattern to the input span. +/// +/// +/// The enumerator has no public constructor. The method returns a +/// object.The enumerator will lazily iterate over zero or more objects. If there is at least one successful match in the span, then +/// returns and will contain the first . If there are no successful matches, +/// then returns and throws an . +/// +/// This type is a ref struct since it stores the input span as a field in order to be able to lazily iterate over it. +/// +public ref struct ValueMatchEnumerator +{ + private readonly Regex _regex; + private readonly ReadOnlySpan _input; + private ValueMatch _current; + MatchCollection matchCollection; + int index = -1; + + /// + /// Creates an instance of the for the passed in which iterates over . + /// + /// The to use for finding matches. + /// The input span to iterate over. + /// The position where the engine should start looking for matches from. + internal ValueMatchEnumerator(Regex regex, ReadOnlySpan input, int startAt) + { + matchCollection = _regex.Matches(input.ToString(), startAt); + _regex = regex; + _input = input; + _current = default; + } + + /// + /// Provides an enumerator that iterates through the matches in the input span. + /// + /// A copy of this enumerator. + public readonly ValueMatchEnumerator GetEnumerator() => this; + + /// + /// Advances the enumerator to the next match in the span. + /// + /// + /// if the enumerator was successfully advanced to the next element; if the enumerator cannot find additional matches. + /// + public bool MoveNext() + { + index++; + var match = matchCollection[index]; + if (match.Success) + { + _current = new ValueMatch(match.Index, match.Length); + return true; + } + + return false; + } + + /// + /// Gets the element at the current position of the enumerator. + /// + /// Enumeration has either not started or has already finished. + public readonly ValueMatch Current => _current; +} + +#endif \ No newline at end of file From ead2435129f17c9a0f77511ce5857017cf8ee0e4 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 19 Feb 2024 20:40:24 +1100 Subject: [PATCH 2/5] . --- src/Polyfill/Regex/Polyfill_Regex.cs | 10 +++++++++- src/Polyfill/Regex/RegexPolyfill.cs | 2 +- src/Polyfill/Regex/ValueMatch.cs | 2 +- src/Tests/PolyfillTests_Regex.cs | 27 +++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/Tests/PolyfillTests_Regex.cs diff --git a/src/Polyfill/Regex/Polyfill_Regex.cs b/src/Polyfill/Regex/Polyfill_Regex.cs index 48021391..14ed6ee4 100644 --- a/src/Polyfill/Regex/Polyfill_Regex.cs +++ b/src/Polyfill/Regex/Polyfill_Regex.cs @@ -2,7 +2,7 @@ #pragma warning disable -#if (MEMORYREFERENCED && !NET7_0_OR_GREATER) +#if !NET7_0_OR_GREATER && HAS_SPAN using System; using System.IO; @@ -33,5 +33,13 @@ public static bool IsMatch(this Regex target, ReadOnlySpan input) { return target.IsMatch(input.ToString()); } + + /// + /// Searches an input span for all occurrences of a regular expression and returns a Regex.ValueMatchEnumerator to iterate over the matches. + /// + /// A Regex.ValueMatchEnumerator to iterate over the matches. + [Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char)))")] + public static ValueMatchEnumerator EnumerateMatches (this Regex target, ReadOnlySpan input) => + new(target, input, target.RightToLeft ? input.Length : 0); } #endif \ No newline at end of file diff --git a/src/Polyfill/Regex/RegexPolyfill.cs b/src/Polyfill/Regex/RegexPolyfill.cs index 05667fdc..40119464 100644 --- a/src/Polyfill/Regex/RegexPolyfill.cs +++ b/src/Polyfill/Regex/RegexPolyfill.cs @@ -13,7 +13,7 @@ #endif static partial class RegexPolyfill { -#if MEMORYREFERENCED +#if HAS_SPAN /// /// Indicates whether the specified regular expression finds a match in the specified input span, using the specified matching options and time-out interval. /// diff --git a/src/Polyfill/Regex/ValueMatch.cs b/src/Polyfill/Regex/ValueMatch.cs index 4e6d75a5..d81f57ea 100644 --- a/src/Polyfill/Regex/ValueMatch.cs +++ b/src/Polyfill/Regex/ValueMatch.cs @@ -2,7 +2,7 @@ #pragma warning disable -#if !NET7_0_OR_GREATER && (MEMORYREFERENCED || NET6_0 || NET5_0) +#if !NET7_0_OR_GREATER && HAS_SPAN using System; using System.Reflection; diff --git a/src/Tests/PolyfillTests_Regex.cs b/src/Tests/PolyfillTests_Regex.cs new file mode 100644 index 00000000..6328a5c5 --- /dev/null +++ b/src/Tests/PolyfillTests_Regex.cs @@ -0,0 +1,27 @@ +using System.Text.RegularExpressions; + +partial class PolyfillTests +{ + [Test] + public void RegexIsMatch() + { + var regex = new Regex(@"\d+"); + var match = regex.Match("a55a"); + Assert.IsTrue(match.Success); + } + + [Test] + public void EnumerateMatches() + { + var regex = new Regex(@"\d+"); + var span = "a55a".AsSpan(); + var found = false; + foreach (var match in regex.EnumerateMatches(span)) + { + found = true; + Assert.AreEqual(2,match.Index); + Assert.AreEqual(2,match.Length); + } + Assert.IsTrue(found); + } +} From b105d37a3fcc334a37ca8f031e42e373520518f5 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 19 Feb 2024 21:06:37 +1100 Subject: [PATCH 3/5] . --- src/Polyfill/Regex/ValueMatch.cs | 6 ++++- src/Polyfill/Regex/ValueMatchEnumerator.cs | 28 ++++++++++++---------- src/Tests/BuildApiTest.cs | 2 +- src/Tests/PolyfillTests_Regex.cs | 5 ++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Polyfill/Regex/ValueMatch.cs b/src/Polyfill/Regex/ValueMatch.cs index d81f57ea..f2815314 100644 --- a/src/Polyfill/Regex/ValueMatch.cs +++ b/src/Polyfill/Regex/ValueMatch.cs @@ -22,7 +22,11 @@ namespace System.Text.RegularExpressions; /// The type is immutable and has no public constructor. An instance of the struct is returned by the /// method when iterating over the results from calling . /// -public readonly ref struct ValueMatch +[ExcludeFromCodeCoverage] +#if PolyPublic +public +#endif +readonly ref struct ValueMatch { private readonly int _index; private readonly int _length; diff --git a/src/Polyfill/Regex/ValueMatchEnumerator.cs b/src/Polyfill/Regex/ValueMatchEnumerator.cs index a9291767..69f3a3c9 100644 --- a/src/Polyfill/Regex/ValueMatchEnumerator.cs +++ b/src/Polyfill/Regex/ValueMatchEnumerator.cs @@ -24,13 +24,16 @@ namespace System.Text.RegularExpressions; /// /// This type is a ref struct since it stores the input span as a field in order to be able to lazily iterate over it. /// -public ref struct ValueMatchEnumerator +[ExcludeFromCodeCoverage] +#if PolyPublic +public +#endif +ref struct ValueMatchEnumerator { - private readonly Regex _regex; - private readonly ReadOnlySpan _input; - private ValueMatch _current; + ReadOnlySpan _input; + ValueMatch _current; MatchCollection matchCollection; - int index = -1; + int index = 0; /// /// Creates an instance of the for the passed in which iterates over . @@ -40,8 +43,7 @@ public ref struct ValueMatchEnumerator /// The position where the engine should start looking for matches from. internal ValueMatchEnumerator(Regex regex, ReadOnlySpan input, int startAt) { - matchCollection = _regex.Matches(input.ToString(), startAt); - _regex = regex; + matchCollection = regex.Matches(input.ToString(), startAt); _input = input; _current = default; } @@ -60,15 +62,15 @@ internal ValueMatchEnumerator(Regex regex, ReadOnlySpan input, int startAt /// public bool MoveNext() { - index++; - var match = matchCollection[index]; - if (match.Success) + if (index == matchCollection.Count) { - _current = new ValueMatch(match.Index, match.Length); - return true; + return false; } - return false; + var match = matchCollection[index]; + _current = new ValueMatch(match.Index, match.Length); + index++; + return true; } /// diff --git a/src/Tests/BuildApiTest.cs b/src/Tests/BuildApiTest.cs index 9691521e..7169cbf5 100644 --- a/src/Tests/BuildApiTest.cs +++ b/src/Tests/BuildApiTest.cs @@ -1,7 +1,7 @@ +#if NET8_0 && DEBUG using System.Diagnostics.CodeAnalysis; using Mono.Cecil; -#if NET8_0 && DEBUG [TestFixture] class BuildApiTest { diff --git a/src/Tests/PolyfillTests_Regex.cs b/src/Tests/PolyfillTests_Regex.cs index 6328a5c5..f122740d 100644 --- a/src/Tests/PolyfillTests_Regex.cs +++ b/src/Tests/PolyfillTests_Regex.cs @@ -19,9 +19,10 @@ public void EnumerateMatches() foreach (var match in regex.EnumerateMatches(span)) { found = true; - Assert.AreEqual(2,match.Index); - Assert.AreEqual(2,match.Length); + Assert.AreEqual(1, match.Index); + Assert.AreEqual(2, match.Length); } + Assert.IsTrue(found); } } From 2cea6249a0fbc1eb21f256af71881f9d81440949 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 19 Feb 2024 21:11:25 +1100 Subject: [PATCH 4/5] . --- src/Polyfill/Regex/Polyfill_Regex.cs | 4 ---- src/Polyfill/Regex/RegexPolyfill.cs | 1 - src/Polyfill/Regex/ValueMatch.cs | 6 ------ src/Polyfill/Regex/ValueMatchEnumerator.cs | 4 ---- 4 files changed, 15 deletions(-) diff --git a/src/Polyfill/Regex/Polyfill_Regex.cs b/src/Polyfill/Regex/Polyfill_Regex.cs index 14ed6ee4..15cef81f 100644 --- a/src/Polyfill/Regex/Polyfill_Regex.cs +++ b/src/Polyfill/Regex/Polyfill_Regex.cs @@ -5,11 +5,7 @@ #if !NET7_0_OR_GREATER && HAS_SPAN using System; -using System.IO; -using System.Net.Http; using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; using Link = System.ComponentModel.DescriptionAttribute; static partial class Polyfill diff --git a/src/Polyfill/Regex/RegexPolyfill.cs b/src/Polyfill/Regex/RegexPolyfill.cs index 40119464..e618a13b 100644 --- a/src/Polyfill/Regex/RegexPolyfill.cs +++ b/src/Polyfill/Regex/RegexPolyfill.cs @@ -2,7 +2,6 @@ #pragma warning disable using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text.RegularExpressions; using Link = System.ComponentModel.DescriptionAttribute; diff --git a/src/Polyfill/Regex/ValueMatch.cs b/src/Polyfill/Regex/ValueMatch.cs index f2815314..94fd453f 100644 --- a/src/Polyfill/Regex/ValueMatch.cs +++ b/src/Polyfill/Regex/ValueMatch.cs @@ -5,12 +5,6 @@ #if !NET7_0_OR_GREATER && HAS_SPAN using System; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using Link = System.ComponentModel.DescriptionAttribute; - -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; namespace System.Text.RegularExpressions; diff --git a/src/Polyfill/Regex/ValueMatchEnumerator.cs b/src/Polyfill/Regex/ValueMatchEnumerator.cs index 69f3a3c9..26eadbf7 100644 --- a/src/Polyfill/Regex/ValueMatchEnumerator.cs +++ b/src/Polyfill/Regex/ValueMatchEnumerator.cs @@ -5,10 +5,6 @@ #if !NET7_0_OR_GREATER && (MEMORYREFERENCED || NET6_0 || NET5_0) using System; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; namespace System.Text.RegularExpressions; From e5f6926029e58f5ea0c74ba95cb11f37c263ef84 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 19 Feb 2024 21:54:08 +1100 Subject: [PATCH 5/5] . --- api_list.include.md | 8 ++++-- readme.md | 8 ++++-- src/Polyfill/Regex/Polyfill_Regex.cs | 32 ++++++++++++++++++++++ src/Polyfill/Regex/ValueMatchEnumerator.cs | 2 +- src/Tests/BuildApiTest.cs | 1 + 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/api_list.include.md b/api_list.include.md index 0582421f..f7f06628 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -214,8 +214,10 @@ * `Boolean TryCopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.trycopyto) -#### RegularExpressions.Regex +#### Regex + * `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char)))) + * `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-int32)) * `Boolean IsMatch(ReadOnlySpan, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32)) * `Boolean IsMatch(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char)))) @@ -300,8 +302,8 @@ #### RegexPolyfill - * `Boolean IsMatch(String, RegularExpressions.RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)) - * `Boolean IsMatch(String, RegularExpressions.RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)) + * `Boolean IsMatch(String, RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)) + * `Boolean IsMatch(String, RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)) * `Boolean IsMatch(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string)) diff --git a/readme.md b/readme.md index 31528d5a..76d69028 100644 --- a/readme.md +++ b/readme.md @@ -570,8 +570,10 @@ The class `Polyfill` includes the following extension methods: * `Boolean TryCopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.trycopyto) -#### RegularExpressions.Regex +#### Regex + * `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char)))) + * `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-int32)) * `Boolean IsMatch(ReadOnlySpan, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32)) * `Boolean IsMatch(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char)))) @@ -656,8 +658,8 @@ The class `Polyfill` includes the following extension methods: #### RegexPolyfill - * `Boolean IsMatch(String, RegularExpressions.RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)) - * `Boolean IsMatch(String, RegularExpressions.RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)) + * `Boolean IsMatch(String, RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)) + * `Boolean IsMatch(String, RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)) * `Boolean IsMatch(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string)) diff --git a/src/Polyfill/Regex/Polyfill_Regex.cs b/src/Polyfill/Regex/Polyfill_Regex.cs index 15cef81f..8be2f191 100644 --- a/src/Polyfill/Regex/Polyfill_Regex.cs +++ b/src/Polyfill/Regex/Polyfill_Regex.cs @@ -37,5 +37,37 @@ public static bool IsMatch(this Regex target, ReadOnlySpan input) [Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char)))")] public static ValueMatchEnumerator EnumerateMatches (this Regex target, ReadOnlySpan input) => new(target, input, target.RightToLeft ? input.Length : 0); + + /// + /// Searches an input span for all occurrences of a regular expression and returns a Regex.ValueMatchEnumerator to iterate over the matches. + /// + /// A Regex.ValueMatchEnumerator to iterate over the matches. + [Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-int32)")] + public static ValueMatchEnumerator EnumerateMatches (this Regex target, ReadOnlySpan input, int startat) => + new(target, input, startat); + // + // /// + // /// Searches an input span for all occurrences of a regular expression and returns a Regex.ValueMatchEnumerator to iterate over the matches. + // /// + // /// A Regex.ValueMatchEnumerator to iterate over the matches. + // [Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string)")] + // public static ValueMatchEnumerator EnumerateMatches (this Regex target, ReadOnlySpan input, string pattern) => + // new(target, input, target.RightToLeft ? input.Length : 0); + // + // /// + // /// Searches an input span for all occurrences of a regular expression and returns a Regex.ValueMatchEnumerator to iterate over the matches. + // /// + // /// A Regex.ValueMatchEnumerator to iterate over the matches. + // [Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)")] + // public static ValueMatchEnumerator EnumerateMatches (this Regex target, ReadOnlySpan input, string pattern, System.Text.RegularExpressions.RegexOptions options) => + // new(target, input, target.RightToLeft ? input.Length : 0); + // + // /// + // /// Searches an input span for all occurrences of a regular expression and returns a Regex.ValueMatchEnumerator to iterate over the matches. + // /// + // /// A Regex.ValueMatchEnumerator to iterate over the matches. + // [Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)")] + // public static ValueMatchEnumerator EnumerateMatches (this Regex target, ReadOnlySpan input, string pattern, System.Text.RegularExpressions.RegexOptions options, TimeSpan matchTimeout) => + // new(target, input, target.RightToLeft ? input.Length : 0); } #endif \ No newline at end of file diff --git a/src/Polyfill/Regex/ValueMatchEnumerator.cs b/src/Polyfill/Regex/ValueMatchEnumerator.cs index 26eadbf7..8c079ba3 100644 --- a/src/Polyfill/Regex/ValueMatchEnumerator.cs +++ b/src/Polyfill/Regex/ValueMatchEnumerator.cs @@ -2,7 +2,7 @@ #pragma warning disable -#if !NET7_0_OR_GREATER && (MEMORYREFERENCED || NET6_0 || NET5_0) +#if !NET7_0_OR_GREATER && HAS_SPAN using System; using System.Diagnostics.CodeAnalysis; diff --git a/src/Tests/BuildApiTest.cs b/src/Tests/BuildApiTest.cs index 7169cbf5..421915e0 100644 --- a/src/Tests/BuildApiTest.cs +++ b/src/Tests/BuildApiTest.cs @@ -7,6 +7,7 @@ class BuildApiTest { static string[] namespacesToClean = [ + "System.Text.RegularExpressions.", "System.Diagnostics.", "System.Collections.Generic.", "System.Threading.Tasks.",