Skip to main content

Crate indentkit

Crate indentkit 

Source
Expand description

§indentkit — detect and convert indentation

Figure out whether a string is indented with tabs or N spaces, and re-indent it from one style to another. Like Node’s detect-indent, but with conversion built in — and zero dependencies, #![no_std].

use indentkit::{detect, reindent, IndentStyle};

let code = "fn main() {\n  println!(\"hi\");\n}\n";
assert_eq!(detect(code), IndentStyle::Spaces(2));

let tabbed = reindent(code, IndentStyle::Tabs);
assert_eq!(tabbed, "fn main() {\n\tprintln!(\"hi\");\n}\n");

Great for formatters, linters, code generators, and editor tooling.

Enums§

IndentStyle
The indentation style of a block of text.

Functions§

detect
Detect the indentation style of text.
indent
Build the indentation string for level nesting levels in style.
reindent
Re-indent text to the target style to, auto-detecting the source style.