@@ -229,52 +229,35 @@ private bool IsAcronymCount(string stringToCompare, int compareStringIndex)
229
229
if ( IsAcronymChar ( stringToCompare , compareStringIndex ) )
230
230
return true ;
231
231
232
- if ( char . IsNumber ( stringToCompare [ compareStringIndex ] ) || char . IsDigit ( stringToCompare [ compareStringIndex ] ) )
233
- {
234
- return compareStringIndex switch
235
- {
236
- int i when i == 0 => true ,
237
- int i when char . IsWhiteSpace ( stringToCompare [ i - 1 ] ) => true ,
238
- _ => false ,
239
- } ;
240
- }
241
-
242
- return false ;
243
- }
232
+ if ( IsAcronymNumber ( stringToCompare , compareStringIndex ) )
233
+ return compareStringIndex == 0 || char . IsWhiteSpace ( stringToCompare [ compareStringIndex - 1 ] ) ;
244
234
245
- private bool IsAcronymChar ( string stringToCompare , int compareStringIndex )
246
- {
247
- if ( char . IsUpper ( stringToCompare [ compareStringIndex ] ) ||
248
- compareStringIndex == 0 || //0 index means char is the start of the compare string, which is an acronym
249
- compareStringIndex != 0 && char . IsWhiteSpace ( stringToCompare [ compareStringIndex - 1 ] ) )
250
- return true ;
251
235
252
236
return false ;
253
237
}
254
238
255
- private bool IsAcronymNumber ( string stringToCompare , int compareStringIndex )
256
- {
257
- if ( char . IsNumber ( stringToCompare [ compareStringIndex ] ) ||
258
- char . IsDigit ( stringToCompare [ compareStringIndex ] ) )
259
- return true ;
239
+ private bool IsAcronymChar ( string stringToCompare , int compareStringIndex )
240
+ => char . IsUpper ( stringToCompare [ compareStringIndex ] ) ||
241
+ compareStringIndex == 0 || // 0 index means char is the start of the compare string, which is an acronym
242
+ char . IsWhiteSpace ( stringToCompare [ compareStringIndex - 1 ] ) ;
260
243
261
- return false ;
262
- }
244
+ private bool IsAcronymNumber ( string stringToCompare , int compareStringIndex ) => stringToCompare [ compareStringIndex ] >= 0 && stringToCompare [ compareStringIndex ] <= 9 ;
263
245
264
246
// To get the index of the closest space which preceeds the first matching index
265
247
private int CalculateClosestSpaceIndex ( List < int > spaceIndices , int firstMatchIndex )
266
248
{
267
- if ( spaceIndices . Count == 0 )
268
- {
269
- return - 1 ;
270
- }
271
- else
249
+ var closestSpaceIndex = - 1 ;
250
+
251
+ // spaceIndices should be ordered asc
252
+ foreach ( var index in spaceIndices )
272
253
{
273
- int ? ind = spaceIndices . OrderBy ( item => ( firstMatchIndex - item ) )
274
- . FirstOrDefault ( item => firstMatchIndex > item ) ;
275
- int closestSpaceIndex = ind ?? - 1 ;
276
- return closestSpaceIndex ;
254
+ if ( index < firstMatchIndex )
255
+ closestSpaceIndex = index ;
256
+ else
257
+ break ;
277
258
}
259
+
260
+ return closestSpaceIndex ;
278
261
}
279
262
280
263
private static bool AllPreviousCharsMatched ( int startIndexToVerify , int currentQuerySubstringCharacterIndex ,
0 commit comments