private static byte[] UrlEncode(byte[] bytes, int offset, int count) { if (!XmlaHttpUtility.ValidateUrlEncodingParameters(bytes, offset, count)) { return(null); } int num = 0; int num2 = 0; for (int i = 0; i < count; i++) { char c = (char)bytes[offset + i]; if (c == ' ') { num++; } else if (!XmlaHttpUtility.IsUrlSafeChar(c)) { num2++; } } if (num == 0 && num2 == 0) { return(bytes); } byte[] array = new byte[count + num2 * 2]; int num3 = 0; for (int j = 0; j < count; j++) { byte b = bytes[offset + j]; char c2 = (char)b; if (XmlaHttpUtility.IsUrlSafeChar(c2)) { array[num3++] = b; } else if (c2 == ' ') { array[num3++] = 43; } else { array[num3++] = 37; array[num3++] = (byte)XmlaHttpUtility.IntToHex(b >> 4 & 15); array[num3++] = (byte)XmlaHttpUtility.IntToHex((int)(b & 15)); } } return(array); }
public static string UrlEncodeUnicode(string value) { if (value == null) { return(null); } int length = value.Length; StringBuilder stringBuilder = new StringBuilder(length); for (int i = 0; i < length; i++) { char c = value[i]; if ((c & 'タ') == '\0') { if (XmlaHttpUtility.IsUrlSafeChar(c)) { stringBuilder.Append(c); } else if (c == ' ') { stringBuilder.Append('+'); } else { stringBuilder.Append('%'); stringBuilder.Append(XmlaHttpUtility.IntToHex((int)(c >> 4 & '\u000f'))); stringBuilder.Append(XmlaHttpUtility.IntToHex((int)(c & '\u000f'))); } } else { stringBuilder.Append("%u"); stringBuilder.Append(XmlaHttpUtility.IntToHex((int)(c >> 12 & '\u000f'))); stringBuilder.Append(XmlaHttpUtility.IntToHex((int)(c >> 8 & '\u000f'))); stringBuilder.Append(XmlaHttpUtility.IntToHex((int)(c >> 4 & '\u000f'))); stringBuilder.Append(XmlaHttpUtility.IntToHex((int)(c & '\u000f'))); } } return(stringBuilder.ToString()); }
private static byte[] UrlEncodeNonAscii(byte[] bytes, int offset, int count, bool alwaysCreateNewReturnValue) { if (!XmlaHttpUtility.ValidateUrlEncodingParameters(bytes, offset, count)) { return(null); } int num = 0; for (int i = 0; i < count; i++) { if (XmlaHttpUtility.IsNonAsciiByte(bytes[offset + i])) { num++; } } if (!alwaysCreateNewReturnValue && num == 0) { return(bytes); } byte[] array = new byte[count + num * 2]; int num2 = 0; for (int j = 0; j < count; j++) { byte b = bytes[offset + j]; if (XmlaHttpUtility.IsNonAsciiByte(b)) { array[num2++] = 37; array[num2++] = (byte)XmlaHttpUtility.IntToHex(b >> 4 & 15); array[num2++] = (byte)XmlaHttpUtility.IntToHex((int)(b & 15)); } else { array[num2++] = b; } } return(array); }