Skip to main content

Crate strip_indent

Crate strip_indent 

Source
Expand description

§strip-indent — remove leading indentation from a multi-line string

Strip the leading whitespace from every line of a string, based on the least-indented line — handy for normalizing indented template/heredoc text. A faithful Rust port of the widely-used strip-indent npm package (which also bundles min-indent).

use strip_indent::strip_indent;

assert_eq!(strip_indent("    foo\n      bar"), "foo\n  bar");
assert_eq!(strip_indent("\tfoo\n\t\tbar"), "foo\n\tbar");

Indentation is counted in characters (a tab counts as one), and lines that are empty or contain only whitespace are ignored when computing the common indent.

Zero dependencies and #![no_std].

Functions§

dedent
Like strip_indent, but first removes leading and trailing whitespace-only lines.
min_indent
The smallest indentation (in leading spaces/tabs) of any non-blank line.
strip_indent
Strip the common leading indentation from every line of string.