Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ProductHeaderValue.cs
Go to the documentation of this file.
2
4
6{
7 private readonly string _name;
8
9 private readonly string _version;
10
11 public string Name => _name;
12
13 public string? Version => _version;
14
15 public ProductHeaderValue(string name)
16 : this(name, null)
17 {
18 }
19
20 public ProductHeaderValue(string name, string? version)
21 {
22 HeaderUtilities.CheckValidToken(name, "name");
23 if (!string.IsNullOrEmpty(version))
24 {
25 HeaderUtilities.CheckValidToken(version, "version");
26 _version = version;
27 }
28 _name = name;
29 }
30
32 {
33 _name = source._name;
34 _version = source._version;
35 }
36
37 public override string ToString()
38 {
39 if (string.IsNullOrEmpty(_version))
40 {
41 return _name;
42 }
43 return _name + "/" + _version;
44 }
45
46 public override bool Equals([NotNullWhen(true)] object? obj)
47 {
48 if (!(obj is ProductHeaderValue productHeaderValue))
49 {
50 return false;
51 }
52 if (string.Equals(_name, productHeaderValue._name, StringComparison.OrdinalIgnoreCase))
53 {
54 return string.Equals(_version, productHeaderValue._version, StringComparison.OrdinalIgnoreCase);
55 }
56 return false;
57 }
58
59 public override int GetHashCode()
60 {
61 int num = StringComparer.OrdinalIgnoreCase.GetHashCode(_name);
62 if (!string.IsNullOrEmpty(_version))
63 {
64 num ^= StringComparer.OrdinalIgnoreCase.GetHashCode(_version);
65 }
66 return num;
67 }
68
69 public static ProductHeaderValue Parse(string? input)
70 {
71 int index = 0;
73 }
74
75 public static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out ProductHeaderValue? parsedValue)
76 {
77 int index = 0;
78 parsedValue = null;
79 if (GenericHeaderParser.SingleValueProductParser.TryParseValue(input, null, ref index, out var parsedValue2))
80 {
81 parsedValue = (ProductHeaderValue)parsedValue2;
82 return true;
83 }
84 return false;
85 }
86
87 internal static int GetProductLength(string input, int startIndex, out ProductHeaderValue parsedValue)
88 {
89 parsedValue = null;
90 if (string.IsNullOrEmpty(input) || startIndex >= input.Length)
91 {
92 return 0;
93 }
95 if (tokenLength == 0)
96 {
97 return 0;
98 }
99 string name = input.Substring(startIndex, tokenLength);
100 int num = startIndex + tokenLength;
102 if (num == input.Length || input[num] != '/')
103 {
104 parsedValue = new ProductHeaderValue(name);
105 return num - startIndex;
106 }
107 num++;
109 int tokenLength2 = HttpRuleParser.GetTokenLength(input, num);
110 if (tokenLength2 == 0)
111 {
112 return 0;
113 }
114 string version = input.Substring(num, tokenLength2);
115 num += tokenLength2;
117 parsedValue = new ProductHeaderValue(name, version);
118 return num - startIndex;
119 }
120
122 {
123 return new ProductHeaderValue(this);
124 }
125}
static readonly GenericHeaderParser SingleValueProductParser
static void CheckValidToken(string value, string parameterName)
override bool Equals([NotNullWhen(true)] object? obj)
static int GetProductLength(string input, int startIndex, out ProductHeaderValue parsedValue)
static ProductHeaderValue Parse(string? input)
ProductHeaderValue(string name, string? version)
static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out ProductHeaderValue? parsedValue)
static int GetTokenLength(string input, int startIndex)
static int GetWhitespaceLength(string input, int startIndex)
static StringComparer OrdinalIgnoreCase