5 releases

0.2.2 Apr 25, 2023
0.2.1 Apr 11, 2023
0.2.0 Dec 27, 2022
0.1.1 Dec 26, 2022
0.1.0 Dec 26, 2022

#744 in Text processing

MIT license

9KB
104 lines

whitespace-sifter

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.

Examples

use whitespace_sifter::*;

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

// This prints `A..\r\nB..\r\nC..\r\nD..\r\nE..`.
println!("{}", sift_with_carriage_return(
  "A..\r\n B..\r\n\r\n C..\r\n\r\n\r\n D..\r\n\r\n\r\n\r\n E..\r\n\r\n\r\n\r\n\r\n"
));

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

// This prints `A..\r\nB..\r\nC..\r\nD..\r\nE..`.
println!("{}", preserve_newline::sift_with_carriage_return(
  "A.. \r\n B.. \r\n\r\n C.. \r\n\r\n\r\n D.. \r\n\r\n\r\n\r\n E.. \r\n\r\n\r\n\r\n\r\n"
));

No runtime deps

Features