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

◆ GetStringUsingEncoding()

string System.Net.WebClient.GetStringUsingEncoding ( WebRequest request,
byte[] data )
inlineprivate

Definition at line 1290 of file WebClient.cs.

1291 {
1292 Encoding encoding = null;
1293 int num = -1;
1294 string text;
1295 try
1296 {
1297 text = request.ContentType;
1298 }
1299 catch (Exception ex) when (ex is NotImplementedException || ex is NotSupportedException)
1300 {
1301 text = null;
1302 }
1303 if (text != null)
1304 {
1305 text = text.ToLowerInvariant();
1306 string[] array = text.Split(s_parseContentTypeSeparators);
1307 bool flag = false;
1308 string[] array2 = array;
1309 foreach (string text2 in array2)
1310 {
1311 if (text2 == "charset")
1312 {
1313 flag = true;
1314 }
1315 else if (flag)
1316 {
1317 try
1318 {
1319 encoding = System.Text.Encoding.GetEncoding(text2);
1320 }
1321 catch (ArgumentException)
1322 {
1323 break;
1324 }
1325 }
1326 }
1327 }
1328 if (encoding == null)
1329 {
1330 Encoding[] array3 = s_knownEncodings;
1331 for (int j = 0; j < array3.Length; j++)
1332 {
1333 byte[] preamble = array3[j].GetPreamble();
1334 if (ByteArrayHasPrefix(preamble, data))
1335 {
1336 encoding = array3[j];
1337 num = preamble.Length;
1338 break;
1339 }
1340 }
1341 }
1342 if (encoding == null)
1343 {
1344 encoding = Encoding;
1345 }
1346 if (num == -1)
1347 {
1348 byte[] preamble2 = encoding.GetPreamble();
1349 num = (ByteArrayHasPrefix(preamble2, data) ? preamble2.Length : 0);
1350 }
1351 return encoding.GetString(data, num, data.Length - num);
1352 }
static bool ByteArrayHasPrefix(byte[] prefix, byte[] byteArray)
static readonly char[] s_parseContentTypeSeparators
Definition WebClient.cs:120
static readonly Encoding[] s_knownEncodings
Definition WebClient.cs:122
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
virtual byte[] GetPreamble()
Definition Encoding.cs:689
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973

References System.array, System.Net.WebClient.ByteArrayHasPrefix(), System.Net.WebRequest.ContentType, System.Net.WebClient.Encoding, System.Text.Encoding.GetEncoding(), System.Text.Encoding.GetPreamble(), System.Text.Encoding.GetString(), System.Net.WebClient.s_knownEncodings, System.Net.WebClient.s_parseContentTypeSeparators, and System.text.

Referenced by System.Net.WebClient.DownloadString(), System.Net.WebClient.DownloadStringAsyncCallback(), System.Net.WebClient.UploadString(), and System.Net.WebClient.UploadStringAsync().