public static byte[] Encode(byte[] input, byte escapeChar, byte[] space, byte[] forbidden, bool uppercase) { byte[] result; using (MemoryStream memoryStream = new MemoryStream(input.Length * 2)) { for (int i = 0; i < input.Length; i++) { bool flag = input[i] == 32; if (flag) { memoryStream.Write(space, 0, space.Length); } else { bool flag2 = input[i] < 32 || input[i] > 126 || WWWTranscoder.ByteArrayContains(forbidden, input[i]); if (flag2) { memoryStream.WriteByte(escapeChar); memoryStream.Write(WWWTranscoder.Byte2Hex(input[i], uppercase ? WWWTranscoder.ucHexChars : WWWTranscoder.lcHexChars), 0, 2); } else { memoryStream.WriteByte(input[i]); } } } result = memoryStream.ToArray(); } return(result); }
public static byte[] Encode(byte[] input, byte escapeChar, byte space, byte[] forbidden, bool uppercase) { using (MemoryStream memoryStream = new MemoryStream(input.Length * 2)) { for (int index = 0; index < input.Length; ++index) { if ((int)input[index] == 32) { memoryStream.WriteByte(space); } else if ((int)input[index] < 32 || (int)input[index] > 126 || WWWTranscoder.ByteArrayContains(forbidden, input[index])) { memoryStream.WriteByte(escapeChar); memoryStream.Write(WWWTranscoder.Byte2Hex(input[index], !uppercase ? WWWTranscoder.lcHexChars : WWWTranscoder.ucHexChars), 0, 2); } else { memoryStream.WriteByte(input[index]); } } return(memoryStream.ToArray()); } }