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

Commit 1cad09d

Browse files
committed
allow opt not to strip double quotes
1 parent 24205fb commit 1cad09d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/ServiceStack.Text/Json/JsonTypeSerializer.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -476,28 +476,33 @@ private static StringSegment UnEscapeJsonString(StringSegment json, ref int inde
476476
return Unescape(json);
477477
}
478478

479-
public static string Unescape(string input)
479+
public static string Unescape(string input) => Unescape(input, true);
480+
public static string Unescape(string input, bool removeQuotes)
480481
{
481-
return Unescape(new StringSegment(input)).Value;
482+
return Unescape(new StringSegment(input), removeQuotes).Value;
482483
}
483484

484-
public static StringSegment Unescape(StringSegment input)
485+
public static StringSegment Unescape(StringSegment input) => Unescape(input, true);
486+
public static StringSegment Unescape(StringSegment input, bool removeQuotes)
485487
{
486488
var length = input.Length;
487489
int start = 0;
488490
int count = 0;
489491
var output = StringBuilderThreadStatic.Allocate();
490492
for (; count < length;)
491493
{
492-
if (input.GetChar(count) == JsonUtils.QuoteChar)
494+
if (removeQuotes)
493495
{
494-
if (start != count)
496+
if (input.GetChar(count) == JsonUtils.QuoteChar)
495497
{
496-
output.Append(input.Buffer, input.Offset + start, count - start);
498+
if (start != count)
499+
{
500+
output.Append(input.Buffer, input.Offset + start, count - start);
501+
}
502+
count++;
503+
start = count;
504+
continue;
497505
}
498-
count++;
499-
start = count;
500-
continue;
501506
}
502507

503508
if (input.GetChar(count) == JsonUtils.EscapeChar)

0 commit comments

Comments
 (0)