RemoveInvisibleCharacters

Trait RemoveInvisibleCharacters 

Source
pub trait RemoveInvisibleCharacters<'a> {
    // Required method
    fn remove_all_invisible_characters(self) -> Cow<'a, str>;
}
Available on crate feature alloc only.
Expand description

To extend str and Cow<str> to have remove_all_invisible_characters method.

Required Methods§

Source

fn remove_all_invisible_characters(self) -> Cow<'a, str>

Removes all invisible or non-printable characters from a given string.

This function filters out a comprehensive set of Unicode characters that are typically invisible or used for control or formatting purposes. This includes:

  • ASCII control characters (U+0000 to U+001F and U+007F), exclude \t and \n
  • Zero-width characters and format controls:
    • U+200B (Zero Width Space)
    • U+200C (Zero Width Non-Joiner)
    • U+200D (Zero Width Joiner)
    • U+200E to U+200F (Directional marks)
    • U+202A to U+202E (Directional formatting)
    • U+2060 to U+2064 (Word Joiner and Invisible Math Symbols)
    • U+2066 to U+2069 (Bidi Isolates)
    • U+FEFF (Byte Order Mark / Zero Width No-Break Space)

These characters can interfere with text rendering, parsing, and display, and are often used in text-based attacks (e.g., for spoofing).

Implementations on Foreign Types§

Source§

impl<'a> RemoveInvisibleCharacters<'a> for &'a str

Source§

impl<'a> RemoveInvisibleCharacters<'a> for Cow<'a, str>

Implementors§