Skip to main content

Crate indent_string

Crate indent_string 

Source
Expand description

§indent-string — indent each line of a multi-line string

Prepend an indentation to every line of a string — foo\nbar foo\n bar. A faithful Rust port of the widely-used indent-string npm package.

use indent_string::indent_string;

assert_eq!(indent_string("foo\nbar"), " foo\n bar");

Use indent_string_with for a repeat count, a custom indent, or to also indent empty lines:

use indent_string::indent_string_with;

assert_eq!(indent_string_with("foo\nbar", 2, "\t", false), "\t\tfoo\n\t\tbar");
assert_eq!(indent_string_with("a\n\nb", 1, " ", true), " a\n \n b");

By default, empty and whitespace-only lines are left untouched (matching the reference’s /^(?!\s*$)/gm); pass include_empty_lines = true to indent every line.

Zero dependencies and #![no_std].

Functions§

indent_string
Indent each line of string by a single space.
indent_string_with
Indent each line of string with count repetitions of indent.