Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Unescape()

static void System.Text.Json.JsonReaderHelper.Unescape ( ReadOnlySpan< byte > source,
Span< byte > destination,
int idx,
out int written )
inlinestaticpackage

Definition at line 481 of file JsonReaderHelper.cs.

482 {
483 source.Slice(0, idx).CopyTo(destination);
484 written = idx;
485 while (idx < source.Length)
486 {
487 byte b = source[idx];
488 if (b == 92)
489 {
490 idx++;
491 switch (source[idx])
492 {
493 case 34:
494 destination[written++] = 34;
495 break;
496 case 110:
497 destination[written++] = 10;
498 break;
499 case 114:
500 destination[written++] = 13;
501 break;
502 case 92:
503 destination[written++] = 92;
504 break;
505 case 47:
506 destination[written++] = 47;
507 break;
508 case 116:
509 destination[written++] = 9;
510 break;
511 case 98:
512 destination[written++] = 8;
513 break;
514 case 102:
515 destination[written++] = 12;
516 break;
517 case 117:
518 {
519 bool flag = Utf8Parser.TryParse(source.Slice(idx + 1, 4), out int value, out int bytesConsumed, 'x');
521 if (JsonHelpers.IsInRangeInclusive((uint)value, 55296u, 57343u))
522 {
523 if (value >= 56320)
524 {
525 ThrowHelper.ThrowInvalidOperationException_ReadInvalidUTF16(value);
526 }
527 idx += 3;
528 if (source.Length < idx + 4 || source[idx - 2] != 92 || source[idx - 1] != 117)
529 {
530 ThrowHelper.ThrowInvalidOperationException_ReadInvalidUTF16();
531 }
532 flag = Utf8Parser.TryParse(source.Slice(idx, 4), out int value2, out bytesConsumed, 'x');
533 if (!JsonHelpers.IsInRangeInclusive((uint)value2, 56320u, 57343u))
534 {
535 ThrowHelper.ThrowInvalidOperationException_ReadInvalidUTF16(value2);
536 }
537 idx += bytesConsumed - 1;
538 value = 1024 * (value - 55296) + (value2 - 56320) + 65536;
539 }
540 int num = new Rune(value).EncodeToUtf8(destination.Slice(written));
541 written += num;
542 break;
543 }
544 }
545 }
546 else
547 {
548 destination[written++] = b;
549 }
550 idx++;
551 }
552 }
static bool TryParse(ReadOnlySpan< byte > source, out bool value, out int bytesConsumed, char standardFormat='\0')

References System.destination, System.Text.Json.Dictionary, System.Text.Rune.EncodeToUtf8(), System.Text.Json.JsonHelpers.IsInRangeInclusive(), System.source, System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ReadInvalidUTF16(), System.Buffers.Text.Utf8Parser.TryParse(), and System.value.

Referenced by System.Text.Json.Serialization.Converters.TimeSpanConverter.Read(), System.Text.Json.JsonDocument.TryGetNamedPropertyValue(), and System.Text.Json.JsonDocument.UnescapeString().