@@ -40,11 +40,11 @@ public void Add<TCollection>(TCollection keys, Func<TKey, TValue> valueFunc) whe
40
40
foreach ( var key in keys ) Add ( key , valueFunc ( key ) ) ;
41
41
}
42
42
}
43
- class DescendingStringLengthIComparer < TValue > : IComparer < Tuple < string , TValue > > {
44
- int IComparer < Tuple < string , TValue > > . Compare ( Tuple < string , TValue > x , Tuple < string , TValue > y ) {
45
- if ( x . Item1 . Length > y . Item1 . Length ) { return - 1 ; }
46
- else if ( x . Item1 . Length < y . Item1 . Length ) { return 1 ; }
47
- else { return string . CompareOrdinal ( x . Item1 , y . Item1 ) ; }
43
+ class DescendingStringLengthIComparer < TValue > : IComparer < ( string NonCommand , TValue Value ) > {
44
+ public int Compare ( ( string NonCommand , TValue Value ) x , ( string NonCommand , TValue Value ) y ) {
45
+ if ( x . NonCommand . Length > y . NonCommand . Length ) { return - 1 ; }
46
+ else if ( x . NonCommand . Length < y . NonCommand . Length ) { return 1 ; }
47
+ else { return string . CompareOrdinal ( x . NonCommand , y . NonCommand ) ; }
48
48
}
49
49
}
50
50
@@ -69,18 +69,18 @@ public LaTeXCommandDictionary(DefaultDelegate defaultParser,
69
69
if ( SplitCommand ( key . AsSpan ( ) ) != key . Length - 1 )
70
70
commands . Add ( key , value ) ;
71
71
else throw new ArgumentException ( "Key is unreachable: " + key , nameof ( key ) ) ;
72
- else nonCommands . Add ( new Tuple < string , TValue > ( key , value ) ) ;
72
+ else nonCommands . Add ( ( key , value ) ) ;
73
73
} ;
74
74
}
75
75
readonly DefaultDelegate defaultParser ;
76
76
readonly DefaultDelegate defaultParserForCommands ;
77
77
78
- readonly SortedSet < Tuple < string , TValue > > nonCommands =
79
- new SortedSet < Tuple < string , TValue > > ( new DescendingStringLengthIComparer < TValue > ( ) ) ;
78
+ readonly SortedSet < ( string NonCommand , TValue Value ) > nonCommands =
79
+ new SortedSet < ( string NonCommand , TValue Value ) > ( new DescendingStringLengthIComparer < TValue > ( ) ) ;
80
80
readonly Dictionary < string , TValue > commands = new Dictionary < string , TValue > ( ) ;
81
81
82
82
public IEnumerator < KeyValuePair < string , TValue > > GetEnumerator ( ) =>
83
- nonCommands . Select ( t => new KeyValuePair < string , TValue > ( t . Item1 , t . Item2 ) )
83
+ nonCommands . Select ( t => new KeyValuePair < string , TValue > ( t . NonCommand , t . Value ) )
84
84
. Concat ( commands ) . GetEnumerator ( ) ;
85
85
IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
86
86
@@ -120,9 +120,9 @@ static int SplitCommand(ReadOnlySpan<char> chars) {
120
120
return TryLookupNonCommand ( chars ) ;
121
121
}
122
122
Result < ( TValue Result , int SplitIndex ) > TryLookupNonCommand ( ReadOnlySpan < char > chars ) {
123
- foreach ( Tuple < string , TValue > t in nonCommands ) {
124
- if ( chars . StartsWith ( t . Item1 . AsSpan ( ) , StringComparison . Ordinal ) ) {
125
- return Result . Ok ( ( t . Item2 , t . Item1 . Length ) ) ; }
123
+ foreach ( ( string NonCommand , TValue Value ) t in nonCommands ) {
124
+ if ( chars . StartsWith ( t . NonCommand . AsSpan ( ) , StringComparison . Ordinal ) ) {
125
+ return Result . Ok ( ( t . Value , t . NonCommand . Length ) ) ; }
126
126
}
127
127
return defaultParser ( chars ) ;
128
128
}
0 commit comments