🚚 Move packages
This commit is contained in:
27
DysonNetwork.Shared/Data/TextSanitizer.cs
Normal file
27
DysonNetwork.Shared/Data/TextSanitizer.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace DysonNetwork.Shared.Data;
|
||||
|
||||
public abstract partial class TextSanitizer
|
||||
{
|
||||
public static string? Sanitize(string? text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return text;
|
||||
|
||||
// List of control characters to preserve
|
||||
var preserveControlChars = new[] { '\n', '\r', '\t', ' ' };
|
||||
|
||||
var filtered = new StringBuilder();
|
||||
foreach (var ch in from ch in text
|
||||
let category = CharUnicodeInfo.GetUnicodeCategory(ch)
|
||||
where category is not UnicodeCategory.Control || preserveControlChars.Contains(ch)
|
||||
where category is not (UnicodeCategory.Format or UnicodeCategory.NonSpacingMark)
|
||||
select ch)
|
||||
{
|
||||
filtered.Append(ch);
|
||||
}
|
||||
|
||||
return filtered.ToString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user