33
44namespace Irihi . Rough . NET . Dependencies . PathDataParser ;
55
6- internal partial class RegexHelper
6+ internal static class RegexHelper
77{
8- [ GeneratedRegex ( @"^([ \t\r\n,]+)" ) ]
9- internal static partial Regex WhiteSpaceRegex ( ) ;
10-
11- [ GeneratedRegex ( @"^([aAcChHlLmMqQsStTvVzZ])" ) ]
12- internal static partial Regex CommandRegex ( ) ;
13-
14- [ GeneratedRegex ( @"^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)" ) ]
15- internal static partial Regex NumberRegex ( ) ;
8+ internal static readonly Regex WhiteSpaceRegex = new ( @"^([ \t\r\n,]+)" , RegexOptions . Compiled ) ;
9+ internal static readonly Regex CommandRegex = new ( @"^([aAcChHlLmMqQsStTvVzZ])" , RegexOptions . Compiled ) ;
10+ internal static readonly Regex NumberRegex = new ( @"^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)" , RegexOptions . Compiled ) ;
1611}
1712
1813public static class PathDataParserFunctions
@@ -30,33 +25,31 @@ internal static List<PathToken> Tokenize(string d)
3025
3126 while ( span . Length > 0 )
3227 {
33- if ( RegexHelper . WhiteSpaceRegex ( ) . IsMatch ( span ) )
28+ var spanStr = span . ToString ( ) ;
29+ if ( RegexHelper . WhiteSpaceRegex . IsMatch ( spanStr ) )
3430 {
35- foreach ( var match in RegexHelper . WhiteSpaceRegex ( ) . EnumerateMatches ( span ) )
31+ var match = RegexHelper . WhiteSpaceRegex . Match ( spanStr ) ;
32+ if ( match . Length > 0 )
3633 {
37- if ( match . Length == 0 ) continue ;
3834 span = span [ match . Length ..] ;
39- break ;
4035 }
4136 }
42- else if ( RegexHelper . CommandRegex ( ) . IsMatch ( span ) )
37+ else if ( RegexHelper . CommandRegex . IsMatch ( spanStr ) )
4338 {
44- foreach ( var match in RegexHelper . CommandRegex ( ) . EnumerateMatches ( span ) )
39+ var match = RegexHelper . CommandRegex . Match ( spanStr ) ;
40+ if ( match . Length > 0 )
4541 {
46- if ( match . Length == 0 ) continue ;
4742 tokens . Add ( new PathToken ( TokenType . Command , span . Slice ( match . Index , match . Length ) . ToString ( ) ) ) ;
4843 span = span [ match . Length ..] ;
49- break ;
5044 }
5145 }
52- else if ( RegexHelper . NumberRegex ( ) . IsMatch ( span ) )
46+ else if ( RegexHelper . NumberRegex . IsMatch ( spanStr ) )
5347 {
54- foreach ( var match in RegexHelper . NumberRegex ( ) . EnumerateMatches ( span ) )
48+ var match = RegexHelper . NumberRegex . Match ( spanStr ) ;
49+ if ( match . Length > 0 )
5550 {
56- if ( match . Length == 0 ) continue ;
5751 tokens . Add ( new PathToken ( TokenType . Number , span . Slice ( match . Index , match . Length ) . ToString ( ) ) ) ;
5852 span = span [ match . Length ..] ;
59- break ;
6053 }
6154 }
6255 else
0 commit comments