33
44namespace Irihi . Rough . NET . Dependencies . PathDataParser ;
55
6- internal static class RegexHelper
6+ internal partial class RegexHelper
77{
8+ #if NET6_0
89 internal static readonly Regex WhiteSpaceRegex = new ( @"^([ \t\r\n,]+)" , RegexOptions . Compiled ) ;
910 internal static readonly Regex CommandRegex = new ( @"^([aAcChHlLmMqQsStTvVzZ])" , RegexOptions . Compiled ) ;
1011 internal static readonly Regex NumberRegex = new ( @"^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)" , RegexOptions . Compiled ) ;
12+ #endif
13+
14+ #if NET8_0_OR_GREATER
15+ [ GeneratedRegex ( @"^([ \t\r\n,]+)" ) ]
16+ internal static partial Regex WhiteSpaceRegex ( ) ;
17+
18+ [ GeneratedRegex ( @"^([aAcChHlLmMqQsStTvVzZ])" ) ]
19+ internal static partial Regex CommandRegex ( ) ;
20+
21+ [ GeneratedRegex ( @"^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)" ) ]
22+ internal static partial Regex NumberRegex ( ) ;
23+ #endif
1124}
1225
1326public static class PathDataParserFunctions
@@ -25,6 +38,7 @@ internal static List<PathToken> Tokenize(string d)
2538
2639 while ( span . Length > 0 )
2740 {
41+ #if NET6_0
2842 var spanStr = span . ToString ( ) ;
2943 if ( RegexHelper . WhiteSpaceRegex . IsMatch ( spanStr ) )
3044 {
@@ -56,6 +70,43 @@ internal static List<PathToken> Tokenize(string d)
5670 {
5771 return [ ] ;
5872 }
73+ #endif
74+
75+ #if NET8_0
76+ if ( RegexHelper . WhiteSpaceRegex ( ) . IsMatch ( span ) )
77+ {
78+ foreach ( var match in RegexHelper . WhiteSpaceRegex ( ) . EnumerateMatches ( span ) )
79+ {
80+ if ( match . Length == 0 ) continue ;
81+ span = span . Slice ( match . Length ) ;
82+ break ;
83+ }
84+ }
85+ else if ( RegexHelper . CommandRegex ( ) . IsMatch ( span ) )
86+ {
87+ foreach ( var match in RegexHelper . CommandRegex ( ) . EnumerateMatches ( span ) )
88+ {
89+ if ( match . Length == 0 ) continue ;
90+ tokens . Add ( new PathToken ( TokenType . Command , span . Slice ( match . Index , match . Length ) . ToString ( ) ) ) ;
91+ span = span . Slice ( match . Length ) ;
92+ break ;
93+ }
94+ }
95+ else if ( RegexHelper . NumberRegex ( ) . IsMatch ( span ) )
96+ {
97+ foreach ( var match in RegexHelper . NumberRegex ( ) . EnumerateMatches ( span ) )
98+ {
99+ if ( match . Length == 0 ) continue ;
100+ tokens . Add ( new PathToken ( TokenType . Number , span . Slice ( match . Index , match . Length ) . ToString ( ) ) ) ;
101+ span = span . Slice ( match . Length ) ;
102+ break ;
103+ }
104+ }
105+ else
106+ {
107+ return new List < PathToken > ( ) ;
108+ }
109+ #endif
59110 }
60111
61112 tokens . Add ( PathToken . End ) ;
0 commit comments