Files
mono/mcs/class/referencesource/System.Web/Util/HttpEncoderUtility.cs
T
dotnet-bot adf899c629 Adding System.Data..., System.ServiceModel..., and System.Web...
Adding reference source for
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Xml
System.Xml.Linq
2016-05-03 00:07:37 +02:00

63 lines
1.7 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="HttpEncoderUtility.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Helper class for common encoding routines
*
* Copyright (c) 2009 Microsoft Corporation
*/
namespace System.Web.Util {
using System;
using System.Web;
internal static class HttpEncoderUtility {
public static int HexToInt(char h) {
return (h >= '0' && h <= '9') ? h - '0' :
(h >= 'a' && h <= 'f') ? h - 'a' + 10 :
(h >= 'A' && h <= 'F') ? h - 'A' + 10 :
-1;
}
public static char IntToHex(int n) {
Debug.Assert(n < 0x10);
if (n <= 9)
return (char)(n + (int)'0');
else
return (char)(n - 10 + (int)'a');
}
// Set of safe chars, from RFC 1738.4 minus '+'
public static bool IsUrlSafeChar(char ch) {
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
return true;
switch (ch) {
case '-':
case '_':
case '.':
case '!':
case '*':
case '(':
case ')':
return true;
}
return false;
}
// Helper to encode spaces only
internal static String UrlEncodeSpaces(string str) {
if (str != null && str.IndexOf(' ') >= 0)
str = str.Replace(" ", "%20");
return str;
}
}
}