-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathUtil.cs
34 lines (30 loc) · 1.18 KB
/
Util.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using FreneticUtilities.FreneticToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace DenizenMetaWebsite
{
/// <summary>Helper utilities.</summary>
public static class Util
{
public static string HeaderLine = "Denizen Meta Documentation";
/// <summary>A helper matcher for characters that need HTML escaping.</summary>
public static AsciiMatcher NeedsEscapeMatcher = new("&<>");
/// <summary>A helper matcher for characters that need general cleanup.</summary>
public static AsciiMatcher NeedsCleanupMatcher = new("\0\t\r");
/// <summary>Escapes some text to be safe to put into HTML.</summary>
public static string EscapeForHTML(string text)
{
if (NeedsCleanupMatcher.ContainsAnyMatch(text))
{
text = text.Replace("\0", " ").Replace("\t", " ").Replace("\r\n", "\n").Replace("\r", "");
}
if (NeedsEscapeMatcher.ContainsAnyMatch(text))
{
text = text.Replace("&", "&").Replace("<", "<").Replace(">", ">");
}
return text;
}
}
}