1 unstable release

0.1.0 Dec 21, 2023

#1371 in Text processing

Download history 155/week @ 2024-06-02 47/week @ 2024-06-09 87/week @ 2024-06-16 79/week @ 2024-06-23 147/week @ 2024-06-30 150/week @ 2024-07-07 118/week @ 2024-07-14 84/week @ 2024-07-21 200/week @ 2024-07-28 129/week @ 2024-08-04 365/week @ 2024-08-11 331/week @ 2024-08-18 174/week @ 2024-08-25 170/week @ 2024-09-01 114/week @ 2024-09-08 154/week @ 2024-09-15

638 downloads per month

BlueOak-1.0.0

12KB
328 lines

detect-indent-rs Test

rust port of sindresorhus/detect-indent All attribution goes to that project.

Detect the indentation of code

Pass in a string of any kind of text and get the indentation.

Use cases

  • Persisting the indentation when modifying a file.
  • Have new content match the existing indentation.
  • Setting the right indentation in your editor.

Usage

Add this to your Cargo.toml

[dependencies]
detect-indent = "0.1"

and this to your crate root

extern crate detect_indent;
use detect_indent::detect_indent;

fn main() {
  println!("{:?}", detect_indent(""));
}

Algorithm

The current algorithm looks for the most common difference between two consecutive non-empty lines. More Details

Dependencies

~2–3MB
~53K SLoC