2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
5
+ using System . ComponentModel . Design ;
5
6
using System . Diagnostics ;
6
7
using System . Linq ;
7
8
using System . Threading ;
@@ -140,7 +141,7 @@ public bool CaptureString(out string s)
140
141
Next ( ) ;
141
142
SkipQuotePairs ( ref length ) ;
142
143
}
143
- s = Substring ( start , length ) ;
144
+ s = Substring ( start , length , ignoreDoubleQuotes : false ) ;
144
145
IsString ( ) ;
145
146
return true ;
146
147
}
@@ -215,7 +216,7 @@ private void SkipQuotePairs(ref int length)
215
216
{
216
217
while ( ! IsEscaped && Apostrophe == Current && Offset ( 1 , out var offset ) && offset == Apostrophe )
217
218
{
218
- length += 2 ;
219
+ length += 1 ;
219
220
Next ( ) ;
220
221
Next ( ) ;
221
222
}
@@ -240,20 +241,40 @@ private void UpdateCurrent(bool ignoreEscaping = false)
240
241
_Current = _Source [ _Position + _EscapeLength ] ;
241
242
}
242
243
244
+ /// <summary>
245
+ /// Count excape is used to offset a position if an escape sequence exists.
246
+ /// </summary>
243
247
private int GetEscapeCount ( int position )
244
248
{
245
- // Check for escape sequences
249
+ // Check for escape sequences.
246
250
if ( position < _Length && _Source [ position ] == Backslash )
247
251
{
248
252
var next = _Source [ position + 1 ] ;
249
253
250
- // Check against list of escapable characters
254
+ // Check against list of escapable characters.
251
255
if ( next is Backslash or BracketOpen or ParenthesesOpen or BracketClose or ParenthesesClose )
252
256
return 1 ;
253
257
}
254
258
return 0 ;
255
259
}
256
260
261
+ /// <summary>
262
+ /// Count dobule quote is used to offset a postion if double quoting exists with an apostrophe.
263
+ /// </summary>
264
+ private int GetDoubleQuoteCount ( int position )
265
+ {
266
+ // Check for apostrophe quote character.
267
+ if ( position < _Length && _Source [ position ] == Apostrophe )
268
+ {
269
+ var next = _Source [ position + 1 ] ;
270
+
271
+ // Check for secondary apostrophe quote character.
272
+ if ( next is Apostrophe )
273
+ return 1 ;
274
+ }
275
+ return 0 ;
276
+ }
277
+
257
278
public string CaptureUntil ( char [ ] c , bool ignoreEscaping = false )
258
279
{
259
280
var start = Position ;
@@ -269,7 +290,7 @@ public string CaptureUntil(char[] c, bool ignoreEscaping = false)
269
290
return Substring ( start , length , ignoreEscaping ) ;
270
291
}
271
292
272
- private string Substring ( int start , int length , bool ignoreEscaping = false )
293
+ private string Substring ( int start , int length , bool ignoreEscaping = false , bool ignoreDoubleQuotes = true )
273
294
{
274
295
if ( ignoreEscaping )
275
296
return _Source . Substring ( start , length ) ;
@@ -280,6 +301,9 @@ private string Substring(int start, int length, bool ignoreEscaping = false)
280
301
while ( i < length )
281
302
{
282
303
var offset = GetEscapeCount ( position ) ;
304
+ if ( ! ignoreDoubleQuotes && offset == 0 )
305
+ offset = GetDoubleQuoteCount ( position ) ;
306
+
283
307
buffer [ i ] = _Source [ position + offset ] ;
284
308
position += offset + 1 ;
285
309
i ++ ;
0 commit comments