Skip to content

squish

Trims s and collapses every run of whitespace into a single space.

Tabs and line breaks count as whitespace, so a multi-line text becomes one line.

use helpers4::string::squish;

Cargo feature string (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features string

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["string"] }
pub fn squish(s: &str) -> String
ParameterTypeDescription
s&strThe text to normalize.

String

use helpers4::string::squish;

assert_eq!(squish("  hello   \n\t world  "), "hello world");
assert_eq!(squish("   "), "");

src/string/squish.rs