Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ public static void CompileToAssembly(System.Text.RegularExpressions.RegexCompila
[System.ObsoleteAttribute("Regex.CompileToAssembly is obsolete and not supported. Use the RegexGeneratorAttribute with the regular expression source generator instead.", DiagnosticId = "SYSLIB0036", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static void CompileToAssembly(System.Text.RegularExpressions.RegexCompilationInfo[] regexinfos, System.Reflection.AssemblyName assemblyname, System.Reflection.Emit.CustomAttributeBuilder[]? attributes, string? resourceFile) { }
public int Count(string input) { throw null; }
public int Count(System.ReadOnlySpan<char> input) { throw null; }
public static int Count(string input, [System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex)] string pattern) { throw null; }
public static int Count(string input, [System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, "options")] string pattern, System.Text.RegularExpressions.RegexOptions options) { throw null; }
public static int Count(string input, [System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, "options")] string pattern, System.Text.RegularExpressions.RegexOptions options, System.TimeSpan matchTimeout) { throw null; }
public static int Count(System.ReadOnlySpan<char> input, [System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex)] string pattern) { throw null; }
public static int Count(System.ReadOnlySpan<char> input, [System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, "options")] string pattern, System.Text.RegularExpressions.RegexOptions options) { throw null; }
public static int Count(System.ReadOnlySpan<char> input, [System.Diagnostics.CodeAnalysis.StringSyntax(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, "options")] string pattern, System.Text.RegularExpressions.RegexOptions options, System.TimeSpan matchTimeout) { throw null; }
public static string Escape(string str) { throw null; }
public string[] GetGroupNames() { throw null; }
public int[] GetGroupNumbers() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Match NextMatch()
Regex? r = _regex;
Debug.Assert(Text != null);
return r != null ?
r.Run(false, Length, Text, _textbeg, _textend - _textbeg, _textpos)! :
r.RunSingleMatch(false, Length, Text, _textbeg, _textend - _textbeg, _textpos)! :
this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public virtual Match this[int i]
Match match;
do
{
match = _regex.Run(false, _prevlen, _input, 0, _input.Length, _startat)!;
match = _regex.RunSingleMatch(false, _prevlen, _input, 0, _input.Length, _startat)!;
if (!match.Success)
{
_done = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,25 @@ public int Count(string input)

int count = 0;

Run(input, 0, ref count, static (ref int count, Match match) =>
RunAllMatchesWithCallback(input, 0, ref count, static (ref int count, Match match) =>
{
count++;
return true;
}, reuseMatchObject: true);

return count;
}

/// <summary>
/// Searches an input span for all occurrences of a regular expression and returns the number of matches.
/// </summary>
/// <param name="input">The span to search for a match.</param>
/// <returns>The number of matches.</returns>
public int Count(ReadOnlySpan<char> input)
{
int count = 0;

RunAllMatchesWithCallback(input, 0, ref count, static (ref int count, Match match) =>
{
count++;
return true;
Expand Down Expand Up @@ -60,5 +78,40 @@ public static int Count(string input, [StringSyntax(StringSyntaxAttribute.Regex,
/// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
public static int Count(string input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options, TimeSpan matchTimeout) =>
RegexCache.GetOrAdd(pattern, options, matchTimeout).Count(input);

/// <summary>
/// Searches an input span for all occurrences of a regular expression and returns the number of matches.
/// </summary>
/// <param name="input">The span to search for a match.</param>
/// <param name="pattern">The regular expression pattern to match.</param>
/// <returns>The number of matches.</returns>
/// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
public static int Count(ReadOnlySpan<char> input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern) =>
RegexCache.GetOrAdd(pattern).Count(input);

/// <summary>
/// Searches an input span for all occurrences of a regular expression and returns the number of matches.
/// </summary>
/// <param name="input">The span to search for a match.</param>
/// <param name="pattern">The regular expression pattern to match.</param>
/// <param name="options">A bitwise combination of the enumeration values that specify options for matching.</param>
/// <returns>The number of matches.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="options"/> is not a valid bitwise combination of RegexOptions values.</exception>
/// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
public static int Count(ReadOnlySpan<char> input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options) =>
RegexCache.GetOrAdd(pattern, options, s_defaultMatchTimeout).Count(input);

/// <summary>
/// Searches an input span for all occurrences of a regular expression and returns the number of matches.
/// </summary>
/// <param name="input">The span to search for a match.</param>
/// <param name="pattern">The regular expression pattern to match.</param>
/// <param name="options">A bitwise combination of the enumeration values that specify options for matching.</param>
/// <param name="matchTimeout">A time-out interval, or <see cref="InfiniteMatchTimeout"/> to indicate that the method should not time out.</param>
/// <returns>The number of matches.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="options"/> is not a valid bitwise combination of RegexOptions values, or <paramref name="matchTimeout"/> is negative, zero, or greater than approximately 24 days.</exception>
/// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
public static int Count(ReadOnlySpan<char> input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options, TimeSpan matchTimeout) =>
RegexCache.GetOrAdd(pattern, options, matchTimeout).Count(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public bool IsMatch(string input)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
}

return Run(quick: true, -1, input, 0, input.Length, RightToLeft ? input.Length : 0) is null;
return RunSingleMatch(quick: true, -1, input, 0, input.Length, RightToLeft ? input.Length : 0) is null;
}

/// <summary>
Expand All @@ -87,7 +87,7 @@ public bool IsMatch(string input)
/// <returns><see langword="true"/> if the regular expression finds a match; otherwise, <see langword="false"/>.</returns>
/// <exception cref="RegexMatchTimeoutException">A time-out ocurred.</exception>
public bool IsMatch(ReadOnlySpan<char> input) =>
Run(input, RightToLeft ? input.Length : 0) is null;
RunSingleMatch(input, RightToLeft ? input.Length : 0) is null;

/// <summary>
/// Searches the input string for one or more matches using the previous pattern and options,
Expand All @@ -100,7 +100,7 @@ public bool IsMatch(string input, int startat)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
}

return Run(quick: true, -1, input, 0, input.Length, startat) is null;
return RunSingleMatch(quick: true, -1, input, 0, input.Length, startat) is null;
}

/// <summary>
Expand Down Expand Up @@ -132,7 +132,7 @@ public Match Match(string input)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
}

return Run(quick: false, -1, input, 0, input.Length, RightToLeft ? input.Length : 0)!;
return RunSingleMatch(quick: false, -1, input, 0, input.Length, RightToLeft ? input.Length : 0)!;
}

/// <summary>
Expand All @@ -146,7 +146,7 @@ public Match Match(string input, int startat)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
}

return Run(quick: false, -1, input, 0, input.Length, startat)!;
return RunSingleMatch(quick: false, -1, input, 0, input.Length, startat)!;
}

/// <summary>
Expand All @@ -159,7 +159,7 @@ public Match Match(string input, int beginning, int length)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
}

return Run(quick: false, -1, input, beginning, length, RightToLeft ? beginning + length : beginning)!;
return RunSingleMatch(quick: false, -1, input, beginning, length, RightToLeft ? beginning + length : beginning)!;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static string Replace(MatchEvaluator evaluator, Regex regex, string inpu

if (!regex.RightToLeft)
{
regex.Run(input, startat, ref state, static (ref (SegmentStringBuilder segments, MatchEvaluator evaluator, int prevat, string input, int count) state, Match match) =>
regex.RunAllMatchesWithCallback(input, startat, ref state, static (ref (SegmentStringBuilder segments, MatchEvaluator evaluator, int prevat, string input, int count) state, Match match) =>
{
state.segments.Add(state.input.AsMemory(state.prevat, match.Index - state.prevat));
state.prevat = match.Index + match.Length;
Expand All @@ -195,7 +195,7 @@ private static string Replace(MatchEvaluator evaluator, Regex regex, string inpu
{
state.prevat = input.Length;

regex.Run(input, startat, ref state, static (ref (SegmentStringBuilder segments, MatchEvaluator evaluator, int prevat, string input, int count) state, Match match) =>
regex.RunAllMatchesWithCallback(input, startat, ref state, static (ref (SegmentStringBuilder segments, MatchEvaluator evaluator, int prevat, string input, int count) state, Match match) =>
{
state.segments.Add(state.input.AsMemory(match.Index + match.Length, state.prevat - match.Index - match.Length));
state.prevat = match.Index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static string[] Split(Regex regex, string input, int count, int startat)

if (!regex.RightToLeft)
{
regex.Run(input, startat, ref state, static (ref (List<string> results, int prevat, string input, int count) state, Match match) =>
regex.RunAllMatchesWithCallback(input, startat, ref state, static (ref (List<string> results, int prevat, string input, int count) state, Match match) =>
{
state.results.Add(state.input.Substring(state.prevat, match.Index - state.prevat));
state.prevat = match.Index + match.Length;
Expand Down Expand Up @@ -118,7 +118,7 @@ private static string[] Split(Regex regex, string input, int count, int startat)
{
state.prevat = input.Length;

regex.Run(input, startat, ref state, static (ref (List<string> results, int prevat, string input, int count) state, Match match) =>
regex.RunAllMatchesWithCallback(input, startat, ref state, static (ref (List<string> results, int prevat, string input, int count) state, Match match) =>
{
state.results.Add(state.input.Substring(match.Index + match.Length, state.prevat - match.Index - match.Length));
state.prevat = match.Index;
Expand Down
Loading