Return the matching search value in a multi-string search (i.e. IndexOfAny with SearchValues<string>)
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- csharp
- Domain
- backend-api-design
Research direction
Start by reading the SearchValues and IndexOfAny API discussion linked from the issue, then compare the proposed return forms with the existing Regex alternative. Determine whether exposing the matching search value is a suitable API change and define how callers would identify the match. Done means reaching agreement on the API shape and its expected behavior.
Written by the indexing model from the issue text.
Description
Discussed in https://github.com/dotnet/runtime/discussions/110663
Originally posted by f2bo December 12, 2024
.NET 9 introduced multi-string search with IndexOfAny(this ReadOnlySpan<char> span, SearchValues<string> values), which is great if you need to find a set of matching strings. However, and I would say more often than not, in addition to the location, you also need to know which of the search values was found, for example, to count instances for each of the search values or even just to advance a pointer past the match and continue processing.
Until now, when searching for single characters, this was trivial since the matching search value had length 1 and could be directly retrieved from the location returned by IndexOfAny. When searching for strings, however, it now becomes necessary to execute an additional comparison at the match location to determine which of the search values was found.
I'm aware that you could get this information by using a Regex instead, but it seems odd given that IndexOfAny has already determined the matching search value. Wouldn't it be possible to also return it, even if it's in the form of an index into the ReadOnlySpan<string> that was originally used to create the SearchValues instance. This could be provided either as an additional output parameter or by returning a tuple that also includes the location.
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·