File tree 1 file changed +6
-2
lines changed
docs/core/whats-new/snippets/dotnet-9/csharp
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
58
58
// </ReadOnlySet>
59
59
60
60
// <AlternateLookup>
61
- private static Dictionary < string , int > CountWords ( ReadOnlySpan < char > input )
61
+ static Dictionary < string , int > CountWords ( ReadOnlySpan < char > input )
62
62
{
63
63
Dictionary < string , int > wordCounts = new ( StringComparer . OrdinalIgnoreCase ) ;
64
64
Dictionary < string , int > . AlternateLookup < ReadOnlySpan < char > > spanLookup =
65
65
wordCounts . GetAlternateLookup < ReadOnlySpan < char > > ( ) ;
66
66
67
- foreach ( Range wordRange in Regex . EnumerateSplits ( input , @"\b\w+\b " ) )
67
+ foreach ( Range wordRange in Regex . EnumerateSplits ( input , @"\b\W+ " ) )
68
68
{
69
+ if ( wordRange . Start . Value == wordRange . End . Value )
70
+ {
71
+ continue ; // Skip empty ranges.
72
+ }
69
73
ReadOnlySpan < char > word = input [ wordRange ] ;
70
74
spanLookup [ word ] = spanLookup . TryGetValue ( word , out int count ) ? count + 1 : 1 ;
71
75
}
You can’t perform that action at this time.
0 commit comments