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 ;
@@ -40,16 +41,6 @@ internal static string GetTypeAttrInObject(string typeAttr)
40
41
return string . Format ( "{{\" {0}\" :" , typeAttr ) ;
41
42
}
42
43
43
- public static readonly bool [ ] WhiteSpaceFlags = new bool [ ' ' + 1 ] ;
44
-
45
- static JsonTypeSerializer ( )
46
- {
47
- foreach ( var c in JsonUtils . WhiteSpaceChars )
48
- {
49
- WhiteSpaceFlags [ c ] = true ;
50
- }
51
- }
52
-
53
44
public WriteObjectDelegate GetWriteFn < T > ( )
54
45
{
55
46
return JsonWriter < T > . WriteFn ( ) ;
@@ -365,7 +356,7 @@ public string ParseString(string value)
365
356
366
357
public static bool IsEmptyMap ( StringSegment value , int i = 1 )
367
358
{
368
- for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
359
+ for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
369
360
if ( value . Length == i ) return true ;
370
361
return value . GetChar ( i ++ ) == JsWriter . MapEndChar ;
371
362
}
@@ -430,7 +421,7 @@ public StringSegment UnescapeSafeString(StringSegment value)
430
421
431
422
internal static StringSegment ParseJsonString ( StringSegment json , ref int index )
432
423
{
433
- for ( ; index < json . Length ; index ++ ) { var ch = json . GetChar ( index ) ; if ( ch >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ ch ] ) break ; } //Whitespace inline
424
+ for ( ; index < json . Length ; index ++ ) { var ch = json . GetChar ( index ) ; if ( ! JsonUtils . IsWhiteSpace ( ch ) ) break ; } //Whitespace inline
434
425
435
426
return UnEscapeJsonString ( json , ref index ) ;
436
427
}
@@ -611,7 +602,7 @@ public StringSegment EatTypeValue(StringSegment value, ref int i)
611
602
612
603
public bool EatMapStartChar ( StringSegment value , ref int i )
613
604
{
614
- for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
605
+ for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
615
606
return value . GetChar ( i ++ ) == JsWriter . MapStartChar ;
616
607
}
617
608
@@ -620,7 +611,7 @@ public bool EatMapStartChar(StringSegment value, ref int i)
620
611
public StringSegment EatMapKey ( StringSegment value , ref int i )
621
612
{
622
613
var valueLength = value . Length ;
623
- for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
614
+ for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
624
615
625
616
var tokenStartPos = i ;
626
617
var valueChar = value . GetChar ( i ) ;
@@ -644,7 +635,7 @@ public StringSegment EatMapKey(StringSegment value, ref int i)
644
635
645
636
if ( valueChar == JsWriter . ItemSeperator
646
637
//If it doesn't have quotes it's either a keyword or number so also has a ws boundary
647
- || ( valueChar < WhiteSpaceFlags . Length && WhiteSpaceFlags [ valueChar ] )
638
+ || ( JsonUtils . IsWhiteSpace ( valueChar ) )
648
639
)
649
640
{
650
641
break ;
@@ -659,7 +650,7 @@ public StringSegment EatMapKey(StringSegment value, ref int i)
659
650
660
651
public bool EatMapKeySeperator ( StringSegment value , ref int i )
661
652
{
662
- for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
653
+ for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
663
654
if ( value . Length == i ) return false ;
664
655
return value . GetChar ( i ++ ) == JsWriter . MapKeySeperator ;
665
656
}
@@ -671,7 +662,7 @@ public bool EatItemSeperatorOrMapEndChar(string value, ref int i)
671
662
672
663
public bool EatItemSeperatorOrMapEndChar ( StringSegment value , ref int i )
673
664
{
674
- for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
665
+ for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
675
666
676
667
if ( i == value . Length ) return false ;
677
668
@@ -682,20 +673,20 @@ public bool EatItemSeperatorOrMapEndChar(StringSegment value, ref int i)
682
673
683
674
if ( success )
684
675
{
685
- for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
676
+ for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
686
677
}
687
678
688
679
return success ;
689
680
}
690
681
691
682
public void EatWhitespace ( StringSegment value , ref int i )
692
683
{
693
- for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
684
+ for ( ; i < value . Length ; i ++ ) { var c = value . GetChar ( i ) ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
694
685
}
695
686
696
687
public void EatWhitespace ( string value , ref int i )
697
688
{
698
- for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
689
+ for ( ; i < value . Length ; i ++ ) { var c = value [ i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
699
690
}
700
691
701
692
public string EatValue ( string value , ref int i )
@@ -710,7 +701,7 @@ public StringSegment EatValue(StringSegment value, ref int i)
710
701
var offset = value . Offset ;
711
702
if ( i == valueLength ) return default ( StringSegment ) ;
712
703
713
- for ( ; i < valueLength ; i ++ ) { var c = buf [ offset + i ] ; if ( c >= WhiteSpaceFlags . Length || ! WhiteSpaceFlags [ c ] ) break ; } //Whitespace inline
704
+ for ( ; i < value . Length ; i ++ ) { var c = buf [ offset + i ] ; if ( ! JsonUtils . IsWhiteSpace ( c ) ) break ; } //Whitespace inline
714
705
if ( i == valueLength ) return default ( StringSegment ) ;
715
706
716
707
var tokenStartPos = i ;
@@ -790,7 +781,7 @@ public StringSegment EatValue(StringSegment value, ref int i)
790
781
if ( valueChar == JsWriter . ItemSeperator
791
782
|| valueChar == JsWriter . MapEndChar
792
783
//If it doesn't have quotes it's either a keyword or number so also has a ws boundary
793
- || ( valueChar < WhiteSpaceFlags . Length && WhiteSpaceFlags [ valueChar ] )
784
+ || JsonUtils . IsWhiteSpace ( valueChar )
794
785
)
795
786
{
796
787
break ;
0 commit comments