@@ -34,9 +34,28 @@ private static Option<SplitResult> SplitOnCasing(string identifier, int startInd
3434 : ExtractByCasing ( identifier , startIndex ) ;
3535
3636 private static Option < SplitResult > ExtractByCasing ( string identifier , int startIndex )
37- => NextIsAbbreviation ( identifier , startIndex )
38- ? ExtractAbbreviation ( identifier , startIndex )
39- : ExtractNextWord ( identifier , startIndex ) ;
37+ => identifier switch
38+ {
39+ _ when NextIsAbbreviation ( identifier , startIndex ) => ExtractUntil ( identifier , startIndex , c => char . IsLower ( c . Value ) ) ,
40+ _ when NextIsNumber ( identifier , startIndex ) => ExtractUntil ( identifier , startIndex , c => ! char . IsDigit ( c . Value ) ) ,
41+ _ => ExtractNextWord ( identifier , startIndex ) ,
42+ } ;
43+
44+ private static Option < SplitResult > ExtractUntil ( string identifier , int startIndex , Func < ValueWithIndex < char > , bool > isEndPredicate )
45+ => identifier
46+ . WithIndex ( )
47+ . Skip ( startIndex )
48+ . FirstOrNone ( isEndPredicate )
49+ . AndThen ( GetIndex )
50+ . Match (
51+ none : ExtractLastElement ( identifier , startIndex ) ,
52+ some : index => ExtractNextElement ( identifier , startIndex , EmptySeparatorLength ) ( index - 1 ) ) ;
53+
54+ private static bool NextIsNumber ( string identifier , int startIndex )
55+ => identifier
56+ . Skip ( startIndex )
57+ . TakeWhile ( char . IsDigit )
58+ . Count ( ) > 1 ;
4059
4160 private static SplitResult ExtractNextWord ( string identifier , int startIndex )
4261 => identifier
@@ -51,16 +70,6 @@ private static SplitResult ExtractNextWord(string identifier, int startIndex)
5170 private static bool IsSeparatorCase ( ValueWithIndex < char > c )
5271 => char . IsUpper ( c . Value ) || char . IsDigit ( c . Value ) ;
5372
54- private static Option < SplitResult > ExtractAbbreviation ( string identifier , int startIndex )
55- => identifier
56- . WithIndex ( )
57- . Skip ( startIndex )
58- . FirstOrNone ( c => char . IsLower ( c . Value ) )
59- . AndThen ( GetIndex )
60- . Match (
61- none : ExtractLastElement ( identifier , startIndex ) ,
62- some : index => ExtractNextElement ( identifier , startIndex , EmptySeparatorLength ) ( index - 1 ) ) ;
63-
6473 private static bool NextIsAbbreviation ( string identifier , int startIndex )
6574 => identifier
6675 . Skip ( startIndex )
0 commit comments