File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
docs/core/whats-new/snippets/dotnet-9/csharp Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -58,14 +58,18 @@ internal partial class ReadOnlyCollections
5858 // </ReadOnlySet>
5959
6060 // <AlternateLookup>
61- private static Dictionary < string , int > CountWords ( ReadOnlySpan < char > input )
61+ static Dictionary < string , int > CountWords ( ReadOnlySpan < char > input )
6262 {
6363 Dictionary < string , int > wordCounts = new ( StringComparer . OrdinalIgnoreCase ) ;
6464 Dictionary < string , int > . AlternateLookup < ReadOnlySpan < char > > spanLookup =
6565 wordCounts . GetAlternateLookup < ReadOnlySpan < char > > ( ) ;
6666
67- foreach ( Range wordRange in Regex . EnumerateSplits ( input , @"\b\w+\b " ) )
67+ foreach ( Range wordRange in Regex . EnumerateSplits ( input , @"\b\W+ " ) )
6868 {
69+ if ( wordRange . Start . Value == wordRange . End . Value )
70+ {
71+ continue ; // Skip empty ranges.
72+ }
6973 ReadOnlySpan < char > word = input [ wordRange ] ;
7074 spanLookup [ word ] = spanLookup . TryGetValue ( word , out int count ) ? count + 1 : 1 ;
7175 }
You can’t perform that action at this time.
0 commit comments