Skip to content

indent

Prefixes every non-blank line of s with prefix.

Blank lines (empty or whitespace only) are left untouched, so no trailing whitespace is introduced. Lines are split on '\n' only, and a trailing newline is preserved. It is the inverse of dedent for text indented with a fixed prefix.

use helpers4::string::indent;

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 indent(s: &str, prefix: &str) -> String
ParameterTypeDescription
s&strThe text to indent.
prefix&strThe text to prepend to every non-blank line.

String

use helpers4::string::indent;

assert_eq!(indent("a\n\nb", "  "), "  a\n\n  b");
assert_eq!(indent("line\n", "> "), "> line\n");

src/string/indent.rs