Skip to content

Commit 2407bbb

Browse files
authored
Merge branch 'main' into Parallel.ForEachAsync
2 parents 70e2419 + c3c4f45 commit 2407bbb

60 files changed

Lines changed: 1100 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api_list.include.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@
301301
* `ProcessPath` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.environment.processpath?view=net-11.0#system-environment-processpath)
302302

303303

304+
#### EqualityComparer
305+
306+
* `EqualityComparer<T> Create(Func<T?, T?, bool>, Func<T, int>?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.equalitycomparer-1.create?view=net-11.0)
307+
308+
304309
#### EventInfo
305310

306311
* `NullabilityState GetNullability()`
@@ -793,13 +798,17 @@
793798

794799
#### Regex
795800

801+
* `int Count(string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string))
796802
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-int32))
797803
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))))
798804
* `ValueSplitEnumerator EnumerateSplits(ReadOnlySpan<char>, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratesplits?view=net-11.0#system-text-regularexpressions-regex-enumeratesplits(system-readonlyspan((system-char))-system-int32-system-int32))
799805
* `ValueSplitEnumerator EnumerateSplits(ReadOnlySpan<char>, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratesplits?view=net-11.0#system-text-regularexpressions-regex-enumeratesplits(system-readonlyspan((system-char))-system-int32))
800806
* `ValueSplitEnumerator EnumerateSplits(ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratesplits?view=net-11.0#system-text-regularexpressions-regex-enumeratesplits(system-readonlyspan((system-char))))
801807
* `bool IsMatch(ReadOnlySpan<char>, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch?view=net-11.0#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32))
802808
* `bool IsMatch(ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch?view=net-11.0#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))))
809+
* `int Count(string, string, RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string-system-text-regularexpressions-regexoptions-system-timespan))
810+
* `int Count(string, string, RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string-system-text-regularexpressions-regexoptions))
811+
* `int Count(string, string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string))
803812
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, string, RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan))
804813
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, string, RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions))
805814
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string))

readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
1313
* `uap10`
1414

1515

16-
**API count: 897**<!-- include: apiCount. path: /apiCount.include.md -->
16+
**API count: 892**<!-- include: apiCount. path: /apiCount.include.md -->
1717

1818
### Per Target Framework
1919

@@ -832,6 +832,11 @@ The class `Polyfill` includes the following extension methods:
832832
* `ProcessPath` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.environment.processpath?view=net-11.0#system-environment-processpath)
833833

834834

835+
#### EqualityComparer
836+
837+
* `EqualityComparer<T> Create(Func<T?, T?, bool>, Func<T, int>?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.equalitycomparer-1.create?view=net-11.0)
838+
839+
835840
#### EventInfo
836841

837842
* `NullabilityState GetNullability()`
@@ -1324,13 +1329,17 @@ The class `Polyfill` includes the following extension methods:
13241329

13251330
#### Regex
13261331

1332+
* `int Count(string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string))
13271333
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-int32))
13281334
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))))
13291335
* `ValueSplitEnumerator EnumerateSplits(ReadOnlySpan<char>, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratesplits?view=net-11.0#system-text-regularexpressions-regex-enumeratesplits(system-readonlyspan((system-char))-system-int32-system-int32))
13301336
* `ValueSplitEnumerator EnumerateSplits(ReadOnlySpan<char>, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratesplits?view=net-11.0#system-text-regularexpressions-regex-enumeratesplits(system-readonlyspan((system-char))-system-int32))
13311337
* `ValueSplitEnumerator EnumerateSplits(ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratesplits?view=net-11.0#system-text-regularexpressions-regex-enumeratesplits(system-readonlyspan((system-char))))
13321338
* `bool IsMatch(ReadOnlySpan<char>, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch?view=net-11.0#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32))
13331339
* `bool IsMatch(ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch?view=net-11.0#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))))
1340+
* `int Count(string, string, RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string-system-text-regularexpressions-regexoptions-system-timespan))
1341+
* `int Count(string, string, RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string-system-text-regularexpressions-regexoptions))
1342+
* `int Count(string, string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string))
13341343
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, string, RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan))
13351344
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, string, RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions))
13361345
* `ValueMatchEnumerator EnumerateMatches(ReadOnlySpan<char>, string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.enumeratematches?view=net-11.0#system-text-regularexpressions-regex-enumeratematches(system-readonlyspan((system-char))-system-string))

src/Consume/Consume.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,12 @@ void ExceptionDispatchInfo_Methods()
686686
ExceptionDispatchInfo.SetCurrentStackTrace(ex);
687687
}
688688

689+
void EqualityComparer_Methods()
690+
{
691+
var comparer = EqualityComparer<int>.Create((x, y) => x == y, x => x);
692+
comparer = EqualityComparer<int>.Create((x, y) => x == y);
693+
}
694+
689695
void Enum_Methods()
690696
{
691697
var values = Enum.GetValuesAsUnderlyingType(typeof(DayOfWeek));
@@ -1145,6 +1151,15 @@ void ReadOnlySpan_Methods()
11451151

11461152
#endif
11471153

1154+
void Regex_Count_Methods()
1155+
{
1156+
var regex = new Regex("a");
1157+
var count = regex.Count("aaa");
1158+
count = Regex.Count("aaa", "a");
1159+
count = Regex.Count("aaa", "a", RegexOptions.None);
1160+
count = Regex.Count("aaa", "a", RegexOptions.None, TimeSpan.FromSeconds(1));
1161+
}
1162+
11481163
#if FeatureMemory
11491164

11501165
void Regex_Methods()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#if !NET8_0_OR_GREATER
2+
3+
namespace Polyfills;
4+
5+
using System;
6+
using System.Collections.Generic;
7+
8+
static partial class Polyfill
9+
{
10+
class DelegateEqualityComparer<T>(Func<T?, T?, bool> equals, Func<T, int>? getHashCode)
11+
: EqualityComparer<T>
12+
{
13+
public override bool Equals(T? x, T? y) => equals(x, y);
14+
15+
public override int GetHashCode(T obj) =>
16+
getHashCode is not null ? getHashCode(obj) : throw new NotSupportedException();
17+
}
18+
19+
extension<T>(EqualityComparer<T>)
20+
{
21+
/// <summary>
22+
/// Creates an <see cref="EqualityComparer{T}"/> by using the specified delegates as the implementation of the comparer's <see cref="EqualityComparer{T}.Equals(T,T)"/> and <see cref="EqualityComparer{T}.GetHashCode(T)"/> methods.
23+
/// </summary>
24+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.equalitycomparer-1.create?view=net-11.0
25+
public static EqualityComparer<T> Create(
26+
Func<T?, T?, bool> equals,
27+
Func<T, int>? getHashCode = null) =>
28+
new DelegateEqualityComparer<T>(equals, getHashCode);
29+
}
30+
}
31+
32+
#endif

src/Polyfill/Regex/Polyfill_Regex.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55

66
static partial class Polyfill
77
{
8+
#if !NET7_0_OR_GREATER
9+
10+
/// <summary>
11+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
12+
/// </summary>
13+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string)
14+
public static int Count(this Regex target, string input)
15+
{
16+
var count = 0;
17+
var match = target.Match(input);
18+
while (match.Success)
19+
{
20+
count++;
21+
match = match.NextMatch();
22+
}
23+
24+
return count;
25+
}
26+
27+
#endif
28+
829
#if !NET7_0_OR_GREATER && FeatureMemory
930
/// <summary>
1031
/// Indicates whether the regular expression specified in the Regex constructor finds a match in a specified input span.

src/Polyfill/Regex/RegexPolyfill.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ static partial class Polyfill
1717
{
1818
extension(Regex)
1919
{
20+
#if !NET7_0_OR_GREATER
21+
22+
/// <summary>
23+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
24+
/// </summary>
25+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string)
26+
public static int Count(string input, string pattern) =>
27+
new Regex(pattern).Count(input);
28+
29+
/// <summary>
30+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
31+
/// </summary>
32+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string-system-text-regularexpressions-regexoptions)
33+
public static int Count(string input, string pattern, RegexOptions options) =>
34+
new Regex(pattern, options).Count(input);
35+
36+
/// <summary>
37+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
38+
/// </summary>
39+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.count?view=net-11.0#system-text-regularexpressions-regex-count(system-string-system-string-system-text-regularexpressions-regexoptions-system-timespan)
40+
public static int Count(string input, string pattern, RegexOptions options, TimeSpan matchTimeout) =>
41+
new Regex(pattern, options, matchTimeout).Count(input);
42+
43+
#endif
44+
2045
#if FeatureMemory
2146
#if !NET7_0_OR_GREATER
2247
/// <summary>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// <auto-generated />
2+
#pragma warning disable
3+
namespace Polyfills;
4+
using System;
5+
using System.Collections.Generic;
6+
static partial class Polyfill
7+
{
8+
class DelegateEqualityComparer<T>(Func<T?, T?, bool> equals, Func<T, int>? getHashCode)
9+
: EqualityComparer<T>
10+
{
11+
public override bool Equals(T? x, T? y) => equals(x, y);
12+
public override int GetHashCode(T obj) =>
13+
getHashCode is not null ? getHashCode(obj) : throw new NotSupportedException();
14+
}
15+
extension<T>(EqualityComparer<T>)
16+
{
17+
/// <summary>
18+
/// Creates an <see cref="EqualityComparer{T}"/> by using the specified delegates as the implementation of the comparer's <see cref="EqualityComparer{T}.Equals(T,T)"/> and <see cref="EqualityComparer{T}.GetHashCode(T)"/> methods.
19+
/// </summary>
20+
public static EqualityComparer<T> Create(
21+
Func<T?, T?, bool> equals,
22+
Func<T, int>? getHashCode = null) =>
23+
new DelegateEqualityComparer<T>(equals, getHashCode);
24+
}
25+
}

src/Split/net461/Regex/Polyfill_Regex.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ namespace Polyfills;
55
using System.Text.RegularExpressions;
66
static partial class Polyfill
77
{
8+
/// <summary>
9+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
10+
/// </summary>
11+
public static int Count(this Regex target, string input)
12+
{
13+
var count = 0;
14+
var match = target.Match(input);
15+
while (match.Success)
16+
{
17+
count++;
18+
match = match.NextMatch();
19+
}
20+
return count;
21+
}
822
#if FeatureMemory
923
/// <summary>
1024
/// Indicates whether the regular expression specified in the Regex constructor finds a match in a specified input span.

src/Split/net461/Regex/RegexPolyfill.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ static partial class Polyfill
1212
{
1313
extension(Regex)
1414
{
15+
/// <summary>
16+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
17+
/// </summary>
18+
public static int Count(string input, string pattern) =>
19+
new Regex(pattern).Count(input);
20+
/// <summary>
21+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
22+
/// </summary>
23+
public static int Count(string input, string pattern, RegexOptions options) =>
24+
new Regex(pattern, options).Count(input);
25+
/// <summary>
26+
/// Searches an input string for all occurrences of a regular expression and returns the number of matches.
27+
/// </summary>
28+
public static int Count(string input, string pattern, RegexOptions options, TimeSpan matchTimeout) =>
29+
new Regex(pattern, options, matchTimeout).Count(input);
1530
#if FeatureMemory
1631
/// <summary>
1732
/// Indicates whether the specified regular expression finds a match in the specified input span, using the specified matching options and time-out interval.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// <auto-generated />
2+
#pragma warning disable
3+
namespace Polyfills;
4+
using System;
5+
using System.Collections.Generic;
6+
static partial class Polyfill
7+
{
8+
class DelegateEqualityComparer<T>(Func<T?, T?, bool> equals, Func<T, int>? getHashCode)
9+
: EqualityComparer<T>
10+
{
11+
public override bool Equals(T? x, T? y) => equals(x, y);
12+
public override int GetHashCode(T obj) =>
13+
getHashCode is not null ? getHashCode(obj) : throw new NotSupportedException();
14+
}
15+
extension<T>(EqualityComparer<T>)
16+
{
17+
/// <summary>
18+
/// Creates an <see cref="EqualityComparer{T}"/> by using the specified delegates as the implementation of the comparer's <see cref="EqualityComparer{T}.Equals(T,T)"/> and <see cref="EqualityComparer{T}.GetHashCode(T)"/> methods.
19+
/// </summary>
20+
public static EqualityComparer<T> Create(
21+
Func<T?, T?, bool> equals,
22+
Func<T, int>? getHashCode = null) =>
23+
new DelegateEqualityComparer<T>(equals, getHashCode);
24+
}
25+
}

0 commit comments

Comments
 (0)