Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit eccabd3

Browse files
committed
Fix merge conflicts
2 parents 791309f + 3323314 commit eccabd3

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

src/ServiceStack.Text/Common/DeserializeTypeRefJson.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal static object StringToType(
7373
return null;
7474

7575
//if (!Serializer.EatMapStartChar(strType, ref index))
76-
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (c >= JsonTypeSerializer.WhiteSpaceFlags.Length || !JsonTypeSerializer.WhiteSpaceFlags[c]) break; } //Whitespace inline
76+
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (!JsonUtils.IsWhiteSpace(c)) break; } //Whitespace inline
7777
if (strType.GetChar(index++) != JsWriter.MapStartChar)
7878
throw DeserializeTypeRef.CreateSerializationError(type, strType.Value);
7979

@@ -91,7 +91,7 @@ internal static object StringToType(
9191
var propertyName = JsonTypeSerializer.ParseJsonString(strType, ref index);
9292

9393
//Serializer.EatMapKeySeperator(strType, ref index);
94-
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (c >= JsonTypeSerializer.WhiteSpaceFlags.Length || !JsonTypeSerializer.WhiteSpaceFlags[c]) break; } //Whitespace inline
94+
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (!JsonUtils.IsWhiteSpace(c)) break; } //Whitespace inline
9595
if (strType.Length != index) index++;
9696

9797
var propertyValueStr = Serializer.EatValue(strType, ref index);
@@ -165,13 +165,13 @@ internal static object StringToType(
165165
}
166166

167167
//Serializer.EatItemSeperatorOrMapEndChar(strType, ref index);
168-
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (c >= JsonTypeSerializer.WhiteSpaceFlags.Length || !JsonTypeSerializer.WhiteSpaceFlags[c]) break; } //Whitespace inline
168+
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (!JsonUtils.IsWhiteSpace(c)) break; } //Whitespace inline
169169
if (index != strType.Length)
170170
{
171171
var success = strType.GetChar(index) == JsWriter.ItemSeperator || strType.GetChar(index) == JsWriter.MapEndChar;
172172
index++;
173173
if (success)
174-
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (c >= JsonTypeSerializer.WhiteSpaceFlags.Length || !JsonTypeSerializer.WhiteSpaceFlags[c]) break; } //Whitespace inline
174+
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (!JsonUtils.IsWhiteSpace(c)) break; } //Whitespace inline
175175
}
176176

177177
continue;
@@ -208,13 +208,13 @@ internal static object StringToType(
208208
}
209209

210210
//Serializer.EatItemSeperatorOrMapEndChar(strType, ref index);
211-
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (c >= JsonTypeSerializer.WhiteSpaceFlags.Length || !JsonTypeSerializer.WhiteSpaceFlags[c]) break; } //Whitespace inline
211+
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (!JsonUtils.IsWhiteSpace(c)) break; } //Whitespace inline
212212
if (index != strType.Length)
213213
{
214214
var success = strType.GetChar(index) == JsWriter.ItemSeperator || strType.GetChar(index) == JsWriter.MapEndChar;
215215
index++;
216216
if (success)
217-
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (c >= JsonTypeSerializer.WhiteSpaceFlags.Length || !JsonTypeSerializer.WhiteSpaceFlags[c]) break; } //Whitespace inline
217+
for (; index < strType.Length; index++) { var c = strType.GetChar(index); if (!JsonUtils.IsWhiteSpace(c)) break; } //Whitespace inline
218218
}
219219

220220
}

src/ServiceStack.Text/Json/JsonTypeSerializer.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Globalization;
66
using System.IO;
7+
using System.Runtime.CompilerServices;
78
using System.Text;
89
using ServiceStack.Text.Common;
910
using ServiceStack.Text.Pools;
@@ -40,16 +41,6 @@ internal static string GetTypeAttrInObject(string typeAttr)
4041
return string.Format("{{\"{0}\":", typeAttr);
4142
}
4243

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-
5344
public WriteObjectDelegate GetWriteFn<T>()
5445
{
5546
return JsonWriter<T>.WriteFn();
@@ -365,7 +356,7 @@ public string ParseString(string value)
365356

366357
public static bool IsEmptyMap(StringSegment value, int i = 1)
367358
{
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
369360
if (value.Length == i) return true;
370361
return value.GetChar(i++) == JsWriter.MapEndChar;
371362
}
@@ -430,7 +421,7 @@ public StringSegment UnescapeSafeString(StringSegment value)
430421

431422
internal static StringSegment ParseJsonString(StringSegment json, ref int index)
432423
{
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
434425

435426
return UnEscapeJsonString(json, ref index);
436427
}
@@ -611,7 +602,7 @@ public StringSegment EatTypeValue(StringSegment value, ref int i)
611602

612603
public bool EatMapStartChar(StringSegment value, ref int i)
613604
{
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
615606
return value.GetChar(i++) == JsWriter.MapStartChar;
616607
}
617608

@@ -620,7 +611,7 @@ public bool EatMapStartChar(StringSegment value, ref int i)
620611
public StringSegment EatMapKey(StringSegment value, ref int i)
621612
{
622613
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
624615

625616
var tokenStartPos = i;
626617
var valueChar = value.GetChar(i);
@@ -644,7 +635,7 @@ public StringSegment EatMapKey(StringSegment value, ref int i)
644635

645636
if (valueChar == JsWriter.ItemSeperator
646637
//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))
648639
)
649640
{
650641
break;
@@ -659,7 +650,7 @@ public StringSegment EatMapKey(StringSegment value, ref int i)
659650

660651
public bool EatMapKeySeperator(StringSegment value, ref int i)
661652
{
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
663654
if (value.Length == i) return false;
664655
return value.GetChar(i++) == JsWriter.MapKeySeperator;
665656
}
@@ -671,7 +662,7 @@ public bool EatItemSeperatorOrMapEndChar(string value, ref int i)
671662

672663
public bool EatItemSeperatorOrMapEndChar(StringSegment value, ref int i)
673664
{
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
675666

676667
if (i == value.Length) return false;
677668

@@ -682,20 +673,20 @@ public bool EatItemSeperatorOrMapEndChar(StringSegment value, ref int i)
682673

683674
if (success)
684675
{
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
686677
}
687678

688679
return success;
689680
}
690681

691682
public void EatWhitespace(StringSegment value, ref int i)
692683
{
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
694685
}
695686

696687
public void EatWhitespace(string value, ref int i)
697688
{
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
699690
}
700691

701692
public string EatValue(string value, ref int i)
@@ -710,7 +701,7 @@ public StringSegment EatValue(StringSegment value, ref int i)
710701
var offset = value.Offset;
711702
if (i == valueLength) return default(StringSegment);
712703

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
714705
if (i == valueLength) return default(StringSegment);
715706

716707
var tokenStartPos = i;
@@ -790,7 +781,7 @@ public StringSegment EatValue(StringSegment value, ref int i)
790781
if (valueChar == JsWriter.ItemSeperator
791782
|| valueChar == JsWriter.MapEndChar
792783
//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)
794785
)
795786
{
796787
break;

src/ServiceStack.Text/Json/JsonUtils.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//Copyright (c) Service Stack LLC. All Rights Reserved.
22
//License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
33

4+
using System;
45
using System.IO;
56
using System.Runtime.CompilerServices;
67
#if NETSTANDARD1_1
@@ -23,11 +24,12 @@ public static class JsonUtils
2324
public const string True = "true";
2425
public const string False = "false";
2526

26-
private const char TabChar = '\t';
27-
private const char CarriageReturnChar = '\r';
28-
private const char LineFeedChar = '\n';
29-
private const char FormFeedChar = '\f';
30-
private const char BackspaceChar = '\b';
27+
public const char SpaceChar = ' ';
28+
public const char TabChar = '\t';
29+
public const char CarriageReturnChar = '\r';
30+
public const char LineFeedChar = '\n';
31+
public const char FormFeedChar = '\f';
32+
public const char BackspaceChar = '\b';
3133

3234
/// <summary>
3335
/// Micro-optimization keep pre-built char arrays saving a .ToCharArray() + function call (see .net implementation of .Write(string))
@@ -42,6 +44,12 @@ public static class JsonUtils
4244

4345
public static readonly char[] WhiteSpaceChars = { ' ', TabChar, CarriageReturnChar, LineFeedChar };
4446

47+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
48+
public static bool IsWhiteSpace(char c)
49+
{
50+
return c == ' ' || (c >= '\x0009' && c <= '\x000d') || c == '\x00a0' || c == '\x0085';
51+
}
52+
4553
public static void WriteString(TextWriter writer, string value)
4654
{
4755
if (value == null)

0 commit comments

Comments
 (0)