Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UriHeaderParser.cs
Go to the documentation of this file.
2using System.Text;
3
5
6internal sealed class UriHeaderParser : HttpHeaderParser
7{
8 private readonly UriKind _uriKind;
9
10 internal static readonly UriHeaderParser RelativeOrAbsoluteUriParser = new UriHeaderParser(UriKind.RelativeOrAbsolute);
11
12 private UriHeaderParser(UriKind uriKind)
13 : base(supportsMultipleValues: false)
14 {
15 _uriKind = uriKind;
16 }
17
18 public override bool TryParseValue([NotNullWhen(true)] string value, object storeValue, ref int index, [NotNullWhen(true)] out object parsedValue)
19 {
20 parsedValue = null;
21 if (string.IsNullOrEmpty(value) || index == value.Length)
22 {
23 return false;
24 }
25 string text = value;
26 if (index > 0)
27 {
28 text = value.Substring(index);
29 }
30 if (!Uri.TryCreate(text, _uriKind, out Uri result))
31 {
33 if (!Uri.TryCreate(text, _uriKind, out result))
34 {
35 return false;
36 }
37 }
38 index = value.Length;
39 parsedValue = result;
40 return true;
41 }
42
43 internal static string DecodeUtf8FromString(string input)
44 {
45 if (string.IsNullOrWhiteSpace(input))
46 {
47 return input;
48 }
49 bool flag = false;
50 for (int i = 0; i < input.Length; i++)
51 {
52 if (input[i] > 'ÿ')
53 {
54 return input;
55 }
56 if (input[i] > '\u007f')
57 {
58 flag = true;
59 break;
60 }
61 }
62 if (flag)
63 {
64 byte[] array = new byte[input.Length];
65 for (int j = 0; j < input.Length; j++)
66 {
67 if (input[j] > 'ÿ')
68 {
69 return input;
70 }
71 array[j] = (byte)input[j];
72 }
73 try
74 {
76 return encoding.GetString(array, 0, array.Length);
77 }
78 catch (ArgumentException)
79 {
80 }
81 }
82 return input;
83 }
84
85 public override string ToString(object value)
86 {
87 Uri uri = (Uri)value;
88 if (uri.IsAbsoluteUri)
89 {
90 return uri.AbsoluteUri;
91 }
92 return uri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped);
93 }
94}
override bool TryParseValue([NotNullWhen(true)] string value, object storeValue, ref int index, [NotNullWhen(true)] out object parsedValue)
override string ToString(object value)
static readonly UriHeaderParser RelativeOrAbsoluteUriParser
static string DecodeUtf8FromString(string input)
static DecoderFallback ExceptionFallback
static EncoderFallback ExceptionFallback
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition Uri.cs:3793
string AbsoluteUri
Definition Uri.cs:266
bool IsAbsoluteUri
Definition Uri.cs:572
string GetComponents(UriComponents components, UriFormat format)
Definition Uri.cs:3883
UriKind
Definition UriKind.cs:4
UriFormat
Definition UriFormat.cs:4