| File: _generated\0\RegexGenerator.g.cs | Web Access |
| Project: src\runtime\src\libraries\System.Text.Json\src\System.Text.Json.csproj (System.Text.Json) |
// <auto-generated/> #nullable enable #pragma warning disable namespace System.Text.Json { partial class JsonHelpers { /// <remarks> /// Pattern:<br/> /// <code>^\s*(?:\+|\-)?[0-9]+\s*$</code><br/> /// Explanation:<br/> /// <code> /// ○ Match if at the beginning of the string.<br/> /// ○ Match a whitespace character atomically any number of times.<br/> /// ○ Match a character in the set [+\-] atomically, optionally.<br/> /// ○ Match a character in the set [0-9] atomically at least once.<br/> /// ○ Match a whitespace character greedily any number of times.<br/> /// ○ Match if at the end of the string or if before an ending newline.<br/> /// </code> /// </remarks> [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "11.0.14.37215")] public static partial global::System.Text.RegularExpressions.Regex IntegerRegex => global::System.Text.RegularExpressions.Generated.IntegerRegex_0.Instance; } } namespace System.Text.RegularExpressions.Generated { using System; using System.Buffers; using System.CodeDom.Compiler; using System.Collections; using System.ComponentModel; using System.Globalization; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using System.Threading; /// <summary>Custom <see cref="Regex"/>-derived type for the IntegerRegex method.</summary> [GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "11.0.14.37215")] [SkipLocalsInit] file sealed class IntegerRegex_0 : Regex { /// <summary>Cached, thread-safe singleton instance.</summary> internal static readonly IntegerRegex_0 Instance = new(); /// <summary>Initializes the instance.</summary> private IntegerRegex_0() { base.pattern = "^\\s*(?:\\+|\\-)?[0-9]+\\s*$"; base.roptions = RegexOptions.None; base.internalMatchTimeout = TimeSpan.FromMilliseconds(200); base.factory = new RunnerFactory(); base.capsize = 1; } /// <summary>Provides a factory for creating <see cref="RegexRunner"/> instances to be used by methods on <see cref="Regex"/>.</summary> private sealed class RunnerFactory : RegexRunnerFactory { /// <summary>Creates an instance of a <see cref="RegexRunner"/> used by methods on <see cref="Regex"/>.</summary> protected override RegexRunner CreateInstance() => new Runner(); /// <summary>Provides the runner that contains the custom logic implementing the specified regular expression.</summary> private sealed class Runner : RegexRunner { /// <summary>Scan the <paramref name="inputSpan"/> starting from base.runtextstart for the next match.</summary> /// <param name="inputSpan">The text being scanned by the regular expression.</param> protected override void Scan(ReadOnlySpan<char> inputSpan) { // The pattern is anchored. Validate the current position and try to match at it only. if (TryFindNextPossibleStartingPosition(inputSpan) && !TryMatchAtCurrentPosition(inputSpan)) { base.runtextpos = inputSpan.Length; } } /// <summary>Search <paramref name="inputSpan"/> starting from base.runtextpos for the next location a match could possibly start.</summary> /// <param name="inputSpan">The text being scanned by the regular expression.</param> /// <returns>true if a possible match was found; false if no more matches are possible.</returns> private bool TryFindNextPossibleStartingPosition(ReadOnlySpan<char> inputSpan) { int pos = base.runtextpos; // Empty matches aren't possible. if ((uint)pos < (uint)inputSpan.Length) { // The pattern leads with a beginning (\A) anchor. if (pos == 0) { return true; } } // No match found. base.runtextpos = inputSpan.Length; return false; } /// <summary>Determine whether <paramref name="inputSpan"/> at base.runtextpos is a match for the regular expression.</summary> /// <param name="inputSpan">The text being scanned by the regular expression.</param> /// <returns>true if the regular expression matches at the current position; otherwise, false.</returns> private bool TryMatchAtCurrentPosition(ReadOnlySpan<char> inputSpan) { int pos = base.runtextpos; int matchStart = pos; char ch; int charloop_starting_pos = 0, charloop_ending_pos = 0; ReadOnlySpan<char> slice = inputSpan.Slice(pos); // Match if at the beginning of the string. if (pos != 0) { return false; // The input didn't match. } // Match a whitespace character atomically any number of times. { int iteration = 0; while ((uint)iteration < (uint)slice.Length && char.IsWhiteSpace(slice[iteration])) { iteration++; } slice = slice.Slice(iteration); pos += iteration; } // Match a character in the set [+\-] atomically, optionally. { if (!slice.IsEmpty && (((ch = slice[0]) == '+') | (ch == '-'))) { slice = slice.Slice(1); pos++; } } // Match a character in the set [0-9] atomically at least once. { int iteration1 = slice.IndexOfAnyExceptInRange('0', '9'); if (iteration1 < 0) { iteration1 = slice.Length; } if (iteration1 == 0) { return false; // The input didn't match. } slice = slice.Slice(iteration1); pos += iteration1; } // Match a whitespace character greedily any number of times. //{ charloop_starting_pos = pos; int iteration2 = 0; while ((uint)iteration2 < (uint)slice.Length && char.IsWhiteSpace(slice[iteration2])) { iteration2++; } slice = slice.Slice(iteration2); pos += iteration2; charloop_ending_pos = pos; goto CharLoopEnd; CharLoopBacktrack: base.CheckTimeout(); if (charloop_starting_pos >= charloop_ending_pos) { return false; // The input didn't match. } pos = --charloop_ending_pos; slice = inputSpan.Slice(pos); CharLoopEnd: //} // Match if at the end of the string or if before an ending newline. if (pos < inputSpan.Length - 1 || ((uint)pos < (uint)inputSpan.Length && inputSpan[pos] != '\n')) { goto CharLoopBacktrack; } // The input matched. base.runtextpos = pos; base.Capture(0, matchStart, pos); return true; } } } } }