/wasSharp/Web.cs |
@@ -6,6 +6,7 @@ |
|
using System; |
using System.Linq; |
using System.Linq.Expressions; |
using System.Net; |
|
namespace wasSharp |
@@ -16,29 +17,30 @@ |
// Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary>RFC3986 URI Escapes a string</summary> |
/// <param name="data">a string to escape</param> |
/// <remarks> |
/// data - a string to escape |
/// </remarks> |
/// <returns>an RFC3986 escaped string</returns> |
public static string URIEscapeDataString(string data) |
{ |
// Uri.EscapeDataString can only handle 32766 characters at a time |
return string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766) |
.Select(o => Uri.EscapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - (o*32766))))) |
.ToArray()); |
} |
public static Func<string, string> URIEscapeDataString = |
((Expression<Func<string, string>>) |
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766) |
.Select(o => Uri.EscapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - (o*32766))))) |
.ToArray()))).Compile(); |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary>URI unescapes an RFC3986 URI escaped string</summary> |
/// <param name="data">a string to unescape</param> |
/// <remarks> |
/// data - a string to unescape |
/// </remarks> |
/// <returns>the resulting string</returns> |
public static string URIUnescapeDataString(string data) |
{ |
// Uri.UnescapeDataString can only handle 32766 characters at a time |
return string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766) |
.Select(o => Uri.UnescapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - (o*32766))))) |
.ToArray()); |
} |
public static Func<string, string> URIUnescapeDataString = |
((Expression<Func<string, string>>) |
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766) |
.Select( |
o => Uri.UnescapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - (o*32766))))) |
.ToArray()))).Compile(); |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |