| Crates.io | string-auto-indent |
| lib.rs | string-auto-indent |
| version | 0.1.2 |
| created_at | 2025-02-17 22:48:20.160594+00 |
| updated_at | 2025-03-03 19:23:24.115548+00 |
| description | Normalizes multi-line string indentation while preserving platform-specific line endings. |
| homepage | |
| repository | https://github.com/jzombie/rust-string-auto-indent |
| max_upload_size | |
| id | 1559418 |
| size | 17,195 |
| OS | Status |
|---|---|
| Ubuntu-latest | |
| macOS-latest | |
| Windows-latest |
A Rust utility for automatically normalizing multi-line string indentation while preserving platform-specific line endings.
When working with multi-line strings inside indented code blocks, unwanted leading spaces may be introduced. This can affect readability, logging output, and formatted text generation.
string-auto-indent provides an automated way to normalize multi-line strings without modifying the first line's indentation.
cargo add string-auto-indent
use string_auto_indent::{auto_indent, LineEnding};
let excessively_indented_text = r#"
Best Practices for Text Indentation
-----------------------------------
1. Importance of Proper Indentation
a. Enhances readability by clearly defining structure.
b. Prevents misinterpretation of hierarchical content.
c. Improves maintainability in collaborative environments.
2. Common Indentation Guidelines
a. Use consistent spacing (e.g., 2 or 4 spaces per level).
b. Avoid mixing spaces and tabs to ensure uniform formatting.
c. Align nested elements to maintain structural clarity.
1b. Maintain relative indentation depth across all nested elements.
2b. Ensure indentation reflects logical hierarchy.
"#;
// Expected output after applying `auto_indent`
let normalized_indentation = r#"
Best Practices for Text Indentation
-----------------------------------
1. Importance of Proper Indentation
a. Enhances readability by clearly defining structure.
b. Prevents misinterpretation of hierarchical content.
c. Improves maintainability in collaborative environments.
2. Common Indentation Guidelines
a. Use consistent spacing (e.g., 2 or 4 spaces per level).
b. Avoid mixing spaces and tabs to ensure uniform formatting.
c. Align nested elements to maintain structural clarity.
1b. Maintain relative indentation depth across all nested elements.
2b. Ensure indentation reflects logical hierarchy.
"#;
// Verify that `auto_indent` correctly normalizes indentation
assert_eq!(
auto_indent(excessively_indented_text),
normalized_indentation,
"The auto_indent function should normalize leading whitespace."
);
\n, \r\n, \r) and normalizes input for processing.Licensed under MIT. See LICENSE for details.