4
4
using System ;
5
5
using System . Globalization ;
6
6
using System . IO ;
7
+ using System . Runtime . CompilerServices ;
7
8
using System . Text ;
8
9
using ServiceStack . Text . Common ;
9
10
using ServiceStack . Text . Pools ;
@@ -35,16 +36,6 @@ internal static string GetTypeAttrInObject(string typeAttr)
35
36
return string . Format ( "{{\" {0}\" :" , typeAttr ) ;
36
37
}
37
38
38
- public static readonly bool [ ] WhiteSpaceFlags = new bool [ ' ' + 1 ] ;
39
-
40
- static JsonTypeSerializer ( )
41
- {
42
- foreach ( var c in JsonUtils . WhiteSpaceChars )
43
- {
44
- WhiteSpaceFlags [ c ] = true ;
45
- }
46
- }
47
-
48
39
public WriteObjectDelegate GetWriteFn < T > ( )
49
40
{
50
41
return JsonWriter < T > . WriteFn ( ) ;
@@ -343,7 +334,7 @@ public string ParseString(string value)
343
334
344
335
public static bool IsEmptyMap ( string value , int i = 1 )
345
336
{
346
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
337
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
347
338
if ( value . Length == i ) return true ;
348
339
return value [ i ++ ] == JsWriter . MapEndChar ;
349
340
}
@@ -393,7 +384,7 @@ public string UnescapeSafeString(string value)
393
384
394
385
internal static string ParseJsonString ( string json , ref int index )
395
386
{
396
- for ( ; index < json . Length ; index ++ ) { var ch = json [ index ] ; if ( ch >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ ch ] ) break ; } //Whitespace inline
387
+ for ( ; index < json . Length ; index ++ ) { var ch = json [ index ] ; if ( ! JsonUtils . IsWhiteSpace ( ch ) ) break ; } //Whitespace inline
397
388
398
389
return UnEscapeJsonString ( json , ref index ) ;
399
390
}
@@ -558,14 +549,14 @@ public string EatTypeValue(string value, ref int i)
558
549
559
550
public bool EatMapStartChar ( string value , ref int i )
560
551
{
561
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
552
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
562
553
return value [ i ++ ] == JsWriter . MapStartChar ;
563
554
}
564
555
565
556
public string EatMapKey ( string value , ref int i )
566
557
{
567
558
var valueLength = value . Length ;
568
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
559
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
569
560
570
561
var tokenStartPos = i ;
571
562
var valueChar = value [ i ] ;
@@ -589,7 +580,7 @@ public string EatMapKey(string value, ref int i)
589
580
590
581
if ( valueChar == JsWriter . ItemSeperator
591
582
//If it doesn't have quotes it's either a keyword or number so also has a ws boundary
592
- || ( valueChar < WhiteSpaceFlags . Length && WhiteSpaceFlags [ valueChar ] )
583
+ || ( JsonUtils . IsWhiteSpace ( valueChar ) )
593
584
)
594
585
{
595
586
break ;
@@ -601,14 +592,14 @@ public string EatMapKey(string value, ref int i)
601
592
602
593
public bool EatMapKeySeperator ( string value , ref int i )
603
594
{
604
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
595
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
605
596
if ( value . Length == i ) return false ;
606
597
return value [ i ++ ] == JsWriter . MapKeySeperator ;
607
598
}
608
599
609
600
public bool EatItemSeperatorOrMapEndChar ( string value , ref int i )
610
601
{
611
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
602
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
612
603
613
604
if ( i == value . Length ) return false ;
614
605
@@ -619,23 +610,23 @@ public bool EatItemSeperatorOrMapEndChar(string value, ref int i)
619
610
620
611
if ( success )
621
612
{
622
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
613
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
623
614
}
624
615
625
616
return success ;
626
617
}
627
618
628
619
public void EatWhitespace ( string value , ref int i )
629
620
{
630
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
621
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
631
622
}
632
623
633
624
public string EatValue ( string value , ref int i )
634
625
{
635
626
var valueLength = value . Length ;
636
627
if ( i == valueLength ) return null ;
637
628
638
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
629
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
639
630
if ( i == valueLength ) return null ;
640
631
641
632
var tokenStartPos = i ;
@@ -715,7 +706,7 @@ public string EatValue(string value, ref int i)
715
706
if ( valueChar == JsWriter . ItemSeperator
716
707
|| valueChar == JsWriter . MapEndChar
717
708
//If it doesn't have quotes it's either a keyword or number so also has a ws boundary
718
- || ( valueChar < WhiteSpaceFlags . Length && WhiteSpaceFlags [ valueChar ] )
709
+ || JsonUtils . IsWhiteSpace ( valueChar )
719
710
)
720
711
{
721
712
break ;
0 commit comments