Fix beginning fixups of captures after Regex span support (#66713)
authorStephen Toub <stoub@microsoft.com>
Wed, 16 Mar 2022 21:18:38 +0000 (17:18 -0400)
committerGitHub <noreply@github.com>
Wed, 16 Mar 2022 21:18:38 +0000 (17:18 -0400)
commitbe9c5287512858aa57675328945a5e189f29d0dd
treefc619e09fb2d740e8612a16d8edaf653bd6bdb4e
parentac20efd2a26202d272604cb353d0d365a3f69c2d
Fix beginning fixups of captures after Regex span support (#66713)

The Regex span support changed the scanning infrastructure to always be based on spans.  That means that when a string is passed in by the caller, internally we still operate on it as a span.  That also means we can take advantage of slicing, and if the caller has specified via a beginning/length set of arguments that we should only process a substring, we can just slice to that substring.  That, however, then means that all offsets computed by the scanning implementation are 0-based rather than beginning-based.  The span change included a fixup for the overall match position, but not for the position of each individual capture, and that then meant that captures were providing the wrong values.  We unfortunately didn't have any tests for validating groups that also involved non-0 beginnings with string inputs.
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Capture.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Match.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Groups.Tests.cs