1 //------------------------------------------------------------------------------
2 // <copyright file="HttpEncoderUtility.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
8 * Helper class for common encoding routines
10 * Copyright (c) 2009 Microsoft Corporation
13 namespace System.Web.Util {
17 internal static class HttpEncoderUtility {
19 public static int HexToInt(char h) {
20 return (h >= '0' && h <= '9') ? h - '0' :
21 (h >= 'a' && h <= 'f') ? h - 'a' + 10 :
22 (h >= 'A' && h <= 'F') ? h - 'A' + 10 :
26 public static char IntToHex(int n) {
27 Debug.Assert(n < 0x10);
30 return (char)(n + (int)'0');
32 return (char)(n - 10 + (int)'a');
35 // Set of safe chars, from RFC 1738.4 minus '+'
36 public static bool IsUrlSafeChar(char ch) {
37 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
54 // Helper to encode spaces only
55 internal static String UrlEncodeSpaces(string str) {
56 if (str != null && str.IndexOf(' ') >= 0)
57 str = str.Replace(" ", "%20");