Crate whitespace_sifter

source ·
Expand description

Sift duplicate whitespaces away in just one function call. This crate helps you remove duplicate whitespaces within the &str.
Other than that, it naturally removes the whitespaces at the start and end of the &str using str::trim().

§Examples

use whitespace_sifter::*;
// This prints `1.. 2.. 3.. 4.. 5..`.
println!(
    "{}",
    sift("1.. \n2..  \n\r\n\n3..   \n\n\n4..    \n\n\r\n\n\n5..     \n\n\n\n\n")
);

// This prints `1..\n2..\n3..\n4..\r\n5..`.
println!(
    "{}",
    sift_preserve_newlines(
        "1.. \n2..  \n\r\n3..   \n\n\n4..    \r\n\n\r\n\n5..     \n\n\n\n\n"
    )
);

Functions§

  • This remove duplicate whitespaces within the &str.
    This treats carriage-returns as just one char in the &str.
  • This remove duplicate whitespaces within the &str while preserving deduplicated newlines.
    This treats carriage-returns as just one char in the &str.