@@ -18,14 +18,15 @@ public static SPToken[] Tokenize(string source)
18
18
19
19
#region Newline
20
20
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 ' )
23
23
{
24
+ //add them before the whitestrip-killer will get them ^^
24
25
token . Add ( new SPToken ( )
25
26
{
26
27
Kind = SPTokenKind . Newline ,
27
28
Value = Environment . NewLine
28
- } ) ; //add them before the whitestrip-killer will get them ^^
29
+ } ) ;
29
30
continue ;
30
31
}
31
32
@@ -42,17 +43,49 @@ public static SPToken[] Tokenize(string source)
42
43
43
44
#region Quotes
44
45
45
- if ( c == '"' ) //sigh...
46
+ if ( c == '"' )
46
47
{
47
48
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
51
52
for ( var j = i + 1 ; j < length ; ++ j )
52
53
{
54
+ // if found, search for an escape slash before it
53
55
if ( buffer [ j ] == '"' )
54
56
{
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
56
89
{
57
90
token . Add ( new SPToken ( )
58
91
{
@@ -124,8 +157,8 @@ public static SPToken[] Tokenize(string source)
124
157
++ i ;
125
158
for ( var j = i ; j < length ; ++ j )
126
159
{
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 ' )
129
162
{
130
163
break ;
131
164
}
@@ -259,8 +292,7 @@ public static SPToken[] Tokenize(string source)
259
292
}
260
293
}
261
294
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 '%' )
264
296
{
265
297
if ( ( i + 1 ) < length )
266
298
{
@@ -272,8 +304,8 @@ public static SPToken[] Tokenize(string source)
272
304
}
273
305
}
274
306
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 '>' )
277
309
{
278
310
token . Add ( new SPToken ( ) { Kind = SPTokenKind . Operator , Value = source . Substring ( i , 1 ) } ) ;
279
311
continue ;
@@ -342,8 +374,8 @@ public static SPToken[] Tokenize(string source)
342
374
}
343
375
}
344
376
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 == '&' )
347
379
{
348
380
var canMatchSingle = true ;
349
381
if ( ( i + 1 ) < length )
0 commit comments