private static byte[] UrlEncodeBytesToBytesInternalNonAscii(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue) { int num = 0; for (int i = 0; i < count; i++) { if (UrlUtility.IsNonAsciiByte(bytes[offset + i])) { num++; } } if (alwaysCreateReturnValue || num != 0) { byte[] hex = new byte[count + num * 2]; int num1 = 0; for (int j = 0; j < count; j++) { byte num2 = bytes[offset + j]; if (!UrlUtility.IsNonAsciiByte(num2)) { int num3 = num1; num1 = num3 + 1; hex[num3] = num2; } else { int num4 = num1; num1 = num4 + 1; hex[num4] = 37; int num5 = num1; num1 = num5 + 1; hex[num5] = (byte)UrlUtility.IntToHex(num2 >> 4 & 15); int num6 = num1; num1 = num6 + 1; hex[num6] = (byte)UrlUtility.IntToHex(num2 & 15); } } return(hex); } else { return(bytes); } }
private static string UrlEncodeUnicodeStringToStringInternal(string s, bool ignoreAscii) { int length = s.Length; StringBuilder stringBuilder = new StringBuilder(length); for (int i = 0; i < length; i++) { char chr = s[i]; if ((chr & '\uFF80') != 0) { stringBuilder.Append("%u"); stringBuilder.Append(UrlUtility.IntToHex(chr >> '\f' & 15)); stringBuilder.Append(UrlUtility.IntToHex(chr >> '\b' & 15)); stringBuilder.Append(UrlUtility.IntToHex(chr >> '\u0004' & 15)); stringBuilder.Append(UrlUtility.IntToHex(chr & '\u000F')); } else { if (ignoreAscii || UrlUtility.IsSafe(chr)) { stringBuilder.Append(chr); } else { if (chr != ' ') { stringBuilder.Append('%'); stringBuilder.Append(UrlUtility.IntToHex(chr >> '\u0004' & 15)); stringBuilder.Append(UrlUtility.IntToHex(chr & '\u000F')); } else { stringBuilder.Append('+'); } } } } return(stringBuilder.ToString()); }
private static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue) { int num = 0; int num1 = 0; for (int i = 0; i < count; i++) { char chr = (char)bytes[offset + i]; if (chr != ' ') { if (!UrlUtility.IsSafe(chr)) { num1++; } } else { num++; } } if (alwaysCreateReturnValue || num != 0 || num1 != 0) { byte[] hex = new byte[count + num1 * 2]; int num2 = 0; for (int j = 0; j < count; j++) { byte num3 = bytes[offset + j]; char chr1 = (char)num3; if (!UrlUtility.IsSafe(chr1)) { if (chr1 != ' ') { int num4 = num2; num2 = num4 + 1; hex[num4] = 37; int num5 = num2; num2 = num5 + 1; hex[num5] = (byte)UrlUtility.IntToHex(num3 >> 4 & 15); int num6 = num2; num2 = num6 + 1; hex[num6] = (byte)UrlUtility.IntToHex(num3 & 15); } else { int num7 = num2; num2 = num7 + 1; hex[num7] = 43; } } else { int num8 = num2; num2 = num8 + 1; hex[num8] = num3; } } return(hex); } else { return(bytes); } }