@@ -18,14 +18,15 @@ public static SPToken[] Tokenize(string source)
1818
1919 #region Newline
2020
21- if ( c == ' \n '
22- ) //just fetch \n. \r will be killed by the whitestrip but it's reintroduced in Environment.NewLine
21+ //just fetch \n. \r will be killed by the whitestrip but it's reintroduced in Environment.NewLine
22+ if ( c == ' \n ' )
2323 {
24+ //add them before the whitestrip-killer will get them ^^
2425 token . Add ( new SPToken ( )
2526 {
2627 Kind = SPTokenKind . Newline ,
2728 Value = Environment . NewLine
28- } ) ; //add them before the whitestrip-killer will get them ^^
29+ } ) ;
2930 continue ;
3031 }
3132
@@ -42,17 +43,49 @@ public static SPToken[] Tokenize(string source)
4243
4344 #region Quotes
4445
45- if ( c == '"' ) //sigh...
46+ if ( c == '"' )
4647 {
4748 var startIndex = i ;
48- var
49- foundOccurence =
50- false ; //these suckers are here because we want to continue the main- for-loop but cannot do it from the for-loop in the nextline
49+ var foundOccurence = false ;
50+
51+ // keep searching for next quote
5152 for ( var j = i + 1 ; j < length ; ++ j )
5253 {
54+ // if found, search for an escape slash before it
5355 if ( buffer [ j ] == '"' )
5456 {
55- if ( buffer [ j - 1 ] != '\\ ' ) //is the quote not escaped?
57+ if ( buffer [ j - 1 ] == '\\ ' )
58+ {
59+ // if found, count the amount of them
60+ var slashAmount = 0 ;
61+ for ( int k = j - 1 ; k >= 0 ; k -- )
62+ {
63+ if ( buffer [ k - 1 ] == '\\ ' )
64+ {
65+ slashAmount ++ ;
66+ continue ;
67+ }
68+ break ;
69+ }
70+ // if amount is even (slashAmout + 1 already counted = it's even)
71+ // quote is not escaped and counts as closing quote, we add it as token
72+ if ( slashAmount % 2 != 0 )
73+ {
74+ token . Add ( new SPToken ( )
75+ {
76+ Kind = SPTokenKind . Quote ,
77+ Value = source . Substring ( startIndex , j - startIndex + 1 )
78+ } ) ;
79+ foundOccurence = true ;
80+ i = j ; //skip it in the main loop
81+ break ;
82+ }
83+ else
84+ {
85+ continue ;
86+ }
87+ }
88+ else
5689 {
5790 token . Add ( new SPToken ( )
5891 {
@@ -124,8 +157,8 @@ public static SPToken[] Tokenize(string source)
124157 ++ i ;
125158 for ( var j = i ; j < length ; ++ j )
126159 {
127- if ( buffer [ j ] == ' \r ' || buffer [ j ] == ' \n '
128- ) //different line ending specifications...horribly...
160+ //different line ending specifications...horribly...
161+ if ( buffer [ j ] == ' \r ' || buffer [ j ] == ' \n ' )
129162 {
130163 break ;
131164 }
@@ -259,8 +292,7 @@ public static SPToken[] Tokenize(string source)
259292 }
260293 }
261294
262- if ( c == '<' || c == '>' || c == '!' || c == '|' || c == '&' || c == '+' || c == '-' || c == '*' ||
263- c == '/' || c == '^' || c == '%' )
295+ if ( c is '<' or '>' or '!' or '|' or '&' or '+' or '-' or '*' or '/' or '^' or '%' )
264296 {
265297 if ( ( i + 1 ) < length )
266298 {
@@ -272,8 +304,8 @@ public static SPToken[] Tokenize(string source)
272304 }
273305 }
274306
275- if ( c != '!' && c != '|' && c != '&' && c != '+' && c != '-' && c != '<' && c != '>'
276- ) //they can have another meaning so they are handled on their own
307+ //they can have another meaning so they are handled on their own
308+ if ( c is not '!' and not '|' and not '&' and not '+' and not '-' and not '<' and not '>' )
277309 {
278310 token . Add ( new SPToken ( ) { Kind = SPTokenKind . Operator , Value = source . Substring ( i , 1 ) } ) ;
279311 continue ;
@@ -342,8 +374,8 @@ public static SPToken[] Tokenize(string source)
342374 }
343375 }
344376
345- if ( c == '&'
346- ) //the & operator is a little bit problematic. It can mean bitwise AND or address of variable. This is not easy to determinate
377+ //the & operator is a little bit problematic. It can mean bitwise AND or address of variable. This is not easy to determinate
378+ if ( c == '&' )
347379 {
348380 var canMatchSingle = true ;
349381 if ( ( i + 1 ) < length )
0 commit comments