Class TextSanitizer
- Namespace
- SharpConsoleUI.Helpers
- Assembly
- SharpConsoleUI.dll
Provides sanitization for text entering the character buffer. Prevents terminal escape injection by filtering control characters, BiDi overrides, and other unsafe runes before they reach cells.
public static class TextSanitizer
- Inheritance
-
TextSanitizer
- Inherited Members
Fields
ReplacementCharacter
The replacement character used when an unsafe rune is encountered.
public static readonly Rune ReplacementCharacter
Field Value
Methods
FlattenNewlines(string)
Collapses embedded line breaks (\r\n, \r, \n) to single spaces.
Single-line controls (buttons, rules, labels) route text through this before
MarkupParser.Parse so an embedded newline renders as a space instead of the
U+FFFD (◆) replacement glyph IsUnsafeRune(Rune) would otherwise emit for U+000A/U+000D.
Multi-line controls should split on newlines instead of flattening.
public static string FlattenNewlines(string text)
Parameters
textstringThe text to flatten. May be null.
Returns
- string
The text with line breaks replaced by spaces, or the input unchanged when it contains none.
IsSafeCombiner(Rune)
Returns true only for runes that are legitimately zero-width and safe to attach as combiners. This includes Unicode categories Mn (nonspacing mark), Me (enclosing mark), Mc (spacing combining mark), and Cf (format) minus BiDi overrides, plus VS1-VS16, ZWJ (U+200D), ZWNJ (U+200C), emoji skin tone modifiers (U+1F3FB-U+1F3FF), and regional indicator symbols (U+1F1E6-U+1F1FF).
public static bool IsSafeCombiner(Rune r)
Parameters
rRune
Returns
IsUnsafeRune(Rune)
Returns true if the rune must never reach a cell in the character buffer. This includes C0/C1 control characters, DEL, BiDi overrides, surrogates, and noncharacters.
public static bool IsUnsafeRune(Rune r)
Parameters
rRune
Returns
SanitizeRune(Rune)
Returns the rune unchanged if safe, or U+FFFD if it is unsafe.
public static Rune SanitizeRune(Rune r)
Parameters
rRune