#![no_std]
#![doc(html_root_url = "https://docs.rs/indentkit/0.1.0")]
extern crate alloc;
use alloc::string::String;
use core::fmt;
mod detect;
mod reindent;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IndentStyle {
Tabs,
Spaces(usize),
Unknown,
}
impl IndentStyle {
#[must_use]
pub fn unit(self) -> String {
match self {
IndentStyle::Tabs => String::from("\t"),
IndentStyle::Spaces(n) => " ".repeat(n),
IndentStyle::Unknown => String::new(),
}
}
}
impl fmt::Display for IndentStyle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
IndentStyle::Tabs => f.write_str("tab"),
IndentStyle::Spaces(1) => f.write_str("1 space"),
IndentStyle::Spaces(n) => write!(f, "{n} spaces"),
IndentStyle::Unknown => f.write_str("unknown"),
}
}
}
#[must_use]
pub fn detect(text: &str) -> IndentStyle {
detect::detect(text)
}
#[must_use]
pub fn reindent(text: &str, to: IndentStyle) -> String {
reindent::reindent(text, to)
}
#[must_use]
pub fn indent(level: usize, style: IndentStyle) -> String {
style.unit().repeat(level)
}