Skip to content

dedent

Strips the indentation shared by every non-blank line of s, and drops one leading and one trailing blank line.

Lets a multi-line string literal be indented with the surrounding code without that indentation leaking into the value. Indentation is counted in whitespace characters, and lines are split on '\n' only (a '\r' stays on its line).

use helpers4::string::dedent;

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 dedent(s: &str) -> String
ParameterTypeDescription
s&strThe text to strip the shared indentation from.

String

use helpers4::string::dedent;

assert_eq!(dedent("\n    Hello\n      World\n"), "Hello\n  World");
assert_eq!(dedent("  a\n  b"), "a\nb");

src/string/dedent.rs