mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Style] Add ConvertXMLUnsafeCharacters for future use
This commit is contained in:
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
|
||||
namespace SabreTools.Helper
|
||||
{
|
||||
@@ -440,6 +441,25 @@ namespace SabreTools.Helper
|
||||
return new string(s.Where(c => !invalidPath.Contains(c)).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert all characters that are not considered XML-safe
|
||||
/// </summary>
|
||||
/// <param name="s">Input string to clean</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
public static string ConvertXMLUnsafeCharacters(string s)
|
||||
{
|
||||
return new String(s.Select(c =>
|
||||
(c == 0x9
|
||||
|| c == 0xA
|
||||
|| c == 0xD
|
||||
|| (c >= 0x20 && c <= 0xD77F)
|
||||
|| (c >= 0xE000 && c <= 0xFFFD)
|
||||
|| (c >= 0x10000 && c <= 0x10FFFF)
|
||||
? c
|
||||
: HttpUtility.HtmlEncode(c)[0]))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Externally sourced methods
|
||||
|
||||
Reference in New Issue
Block a user