Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EntityTagHeaderValue.cs
Go to the documentation of this file.
2
4
6{
7 private readonly string _tag;
8
9 private readonly bool _isWeak;
10
11 public string Tag => _tag;
12
13 public bool IsWeak => _isWeak;
14
15 public static EntityTagHeaderValue Any { get; } = new EntityTagHeaderValue();
16
17
19 {
20 _tag = "*";
21 }
22
23 public EntityTagHeaderValue(string tag)
24 : this(tag, isWeak: false)
25 {
26 }
27
28 public EntityTagHeaderValue(string tag, bool isWeak)
29 {
30 if (string.IsNullOrEmpty(tag))
31 {
33 }
34 int length = 0;
35 if (HttpRuleParser.GetQuotedStringLength(tag, 0, out length) != 0 || length != tag.Length)
36 {
38 }
39 _tag = tag;
40 _isWeak = isWeak;
41 }
42
44 {
45 _tag = source._tag;
46 _isWeak = source._isWeak;
47 }
48
49 public override string ToString()
50 {
51 if (_isWeak)
52 {
53 return "W/" + _tag;
54 }
55 return _tag;
56 }
57
58 public override bool Equals([NotNullWhen(true)] object? obj)
59 {
60 if (!(obj is EntityTagHeaderValue entityTagHeaderValue))
61 {
62 return false;
63 }
64 if (_isWeak == entityTagHeaderValue._isWeak)
65 {
66 return string.Equals(_tag, entityTagHeaderValue._tag, StringComparison.Ordinal);
67 }
68 return false;
69 }
70
71 public override int GetHashCode()
72 {
73 return _tag.GetHashCode() ^ _isWeak.GetHashCode();
74 }
75
76 public static EntityTagHeaderValue Parse(string? input)
77 {
78 int index = 0;
80 }
81
82 public static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out EntityTagHeaderValue? parsedValue)
83 {
84 int index = 0;
85 parsedValue = null;
86 if (GenericHeaderParser.SingleValueEntityTagParser.TryParseValue(input, null, ref index, out var parsedValue2))
87 {
88 parsedValue = (EntityTagHeaderValue)parsedValue2;
89 return true;
90 }
91 return false;
92 }
93
94 internal static int GetEntityTagLength(string input, int startIndex, out EntityTagHeaderValue parsedValue)
95 {
96 parsedValue = null;
97 if (string.IsNullOrEmpty(input) || startIndex >= input.Length)
98 {
99 return 0;
100 }
101 bool isWeak = false;
102 int num = startIndex;
103 char c = input[startIndex];
104 if (c == '*')
105 {
106 parsedValue = Any;
107 num++;
108 }
109 else
110 {
111 if (c == 'W' || c == 'w')
112 {
113 num++;
114 if (num + 2 >= input.Length || input[num] != '/')
115 {
116 return 0;
117 }
118 isWeak = true;
119 num++;
121 }
122 int startIndex2 = num;
123 int length = 0;
125 {
126 return 0;
127 }
128 parsedValue = new EntityTagHeaderValue();
129 if (length == input.Length)
130 {
131 parsedValue = new EntityTagHeaderValue(input);
132 }
133 else
134 {
135 parsedValue = new EntityTagHeaderValue(input.Substring(startIndex2, length), isWeak);
136 }
137 num += length;
138 }
140 return num - startIndex;
141 }
142
144 {
145 if (this != Any)
146 {
147 return new EntityTagHeaderValue(this);
148 }
149 return Any;
150 }
151}
static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out EntityTagHeaderValue? parsedValue)
static int GetEntityTagLength(string input, int startIndex, out EntityTagHeaderValue parsedValue)
static EntityTagHeaderValue Parse(string? input)
override bool Equals([NotNullWhen(true)] object? obj)
static readonly GenericHeaderParser SingleValueEntityTagParser
static HttpParseResult GetQuotedStringLength(string input, int startIndex, out int length)
static int GetWhitespaceLength(string input, int startIndex)
static string net_http_headers_invalid_etag_name
Definition SR.cs:32
static string net_http_argument_empty_string
Definition SR.cs:52
Definition SR.cs:7