12 releases (6 stable)

2.3.0 Jul 15, 2024
2.2.0 Jul 14, 2024
1.0.2 Jun 20, 2024
1.0.1 May 2, 2024
0.1.1 Dec 26, 2022

#316 in Text processing

Download history 5/week @ 2024-06-25 7/week @ 2024-07-02 397/week @ 2024-07-09 67/week @ 2024-07-16 1/week @ 2024-07-30 11/week @ 2024-09-10 2/week @ 2024-09-17 41/week @ 2024-09-24 22/week @ 2024-10-01

76 downloads per month

MIT license

30KB
246 lines

whitespace-sifter

crates.io version github.com forks github.com stars crates.io downloads


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

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

✨ Sift Duplicate Whitespaces In One Function Call

This crate helps you remove duplicate whitespaces within a string.
It naturally removes the whitespaces at the start and end of the string.


⚡️Benchmarks

Performance is a priority; Most updates are performance improvements.
The benchmark uses a transcript of the Bee Movie.

Execute these commands to benchmark:

$ git clone https://github.com/JumperBot/whitespace-sifter.git
$ cd whitespace-sifter
$ cargo bench

You should only look for results that look like the following:

Sift/Sift               time:   [159.31 µs 159.60 µs 159.95 µs]
Sift Preserved/Sift Preserved
                        time:   [198.11 µs 198.21 µs 198.32 µs]

In just 0.0001 seconds; Pretty impressive, no?

Go try it on a better machine, I guess. Benchmark specifications:
  • Processor: Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz 1.90 GHz
  • Memory: RAM 16.0 GB (15.8 GB usable)
  • System: GNU/Linux 5.15.153.1-microsoft-standard-WSL2 x86_64

📄 Licensing

whitespace-sifter is licensed under the MIT LICENSE; This is the summarization.

No runtime deps