Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
JsonEncodedText.cs
Go to the documentation of this file.
4
5namespace System.Text.Json;
6
7public readonly struct JsonEncodedText : IEquatable<JsonEncodedText>
8{
9 internal readonly byte[] _utf8Value;
10
11 internal readonly string _value;
12
14
20
21 public static JsonEncodedText Encode(string value, JavaScriptEncoder? encoder = null)
22 {
23 if (value == null)
24 {
25 throw new ArgumentNullException("value");
26 }
27 return Encode(value.AsSpan(), encoder);
28 }
29
31 {
32 if (value.Length == 0)
33 {
34 return new JsonEncodedText(Array.Empty<byte>());
35 }
36 return TranscodeAndEncode(value, encoder);
37 }
38
50
52 {
53 if (utf8Value.Length == 0)
54 {
55 return new JsonEncodedText(Array.Empty<byte>());
56 }
58 return EncodeHelper(utf8Value, encoder);
59 }
60
62 {
63 int num = JsonWriterHelper.NeedsEscaping(utf8Value, encoder);
64 if (num != -1)
65 {
66 return new JsonEncodedText(JsonHelpers.EscapeValue(utf8Value, num, encoder));
67 }
68 return new JsonEncodedText(utf8Value.ToArray());
69 }
70
72 {
73 if (_value == null)
74 {
75 return other._value == null;
76 }
77 return _value.Equals(other._value);
78 }
79
80 public override bool Equals([NotNullWhen(true)] object? obj)
81 {
83 {
84 return Equals(other);
85 }
86 return false;
87 }
88
89 public override string ToString()
90 {
91 return _value ?? string.Empty;
92 }
93
94 public override int GetHashCode()
95 {
96 if (_value != null)
97 {
98 return _value.GetHashCode();
99 }
100 return 0;
101 }
102}
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static byte[] EscapeValue(ReadOnlySpan< byte > utf8Value, int firstEscapeIndexVal, JavaScriptEncoder encoder)
static int GetUtf8FromText(ReadOnlySpan< char > text, Span< byte > dest)
static string GetTextFromUtf8(ReadOnlySpan< byte > utf8Text)
static int GetUtf8ByteCount(ReadOnlySpan< char > text)
static bool NeedsEscaping(byte value)
static void ValidateValue(ReadOnlySpan< byte > value)
static JsonEncodedText Encode(string value, JavaScriptEncoder? encoder=null)
bool Equals(JsonEncodedText other)
static JsonEncodedText TranscodeAndEncode(ReadOnlySpan< char > value, JavaScriptEncoder encoder)
override bool Equals([NotNullWhen(true)] object? obj)
static JsonEncodedText EncodeHelper(ReadOnlySpan< byte > utf8Value, JavaScriptEncoder encoder)
ReadOnlySpan< byte > EncodedUtf8Bytes
static JsonEncodedText Encode(ReadOnlySpan< byte > utf8Value, JavaScriptEncoder? encoder=null)
static JsonEncodedText Encode(ReadOnlySpan< char > value, JavaScriptEncoder? encoder=null)