Skip to content

Commit 4fa8573

Browse files
authored
v0.1.0 (#2)
1 parent 70e992f commit 4fa8573

File tree

8 files changed

+177
-102
lines changed

8 files changed

+177
-102
lines changed

.cargo/deny.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[licenses]
2+
allow = [
3+
"MIT",
4+
]

.github/workflows/rust-lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Rust Lint
2+
on: [push, pull_request]
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- uses: dtolnay/rust-toolchain@stable
10+
11+
# Check formatting
12+
- run: cargo fmt --all -- --check
13+
14+
# Run Clippy with warnings treated as errors
15+
- run: cargo clippy --all-targets --all-features -- -D warnings
16+
17+
# Fail on documentation warnings
18+
- run: RUSTDOCFLAGS="-Dwarnings" cargo doc --no-deps --document-private-items
19+
20+
# Install cargo-deny and check for security issues
21+
- name: Install cargo-deny
22+
run: cargo install cargo-deny
23+
- run: cargo deny check
24+
25+
# Install and run cargo-audit for security vulnerabilities
26+
- run: cargo install cargo-audit
27+
- run: cargo audit

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "string-auto-indent"
3-
version = "0.1.0-alpha1"
3+
version = "0.1.0"
44
authors = ["Jeremy Harris <jeremy.harris@zenosmosis.com>"]
55
edition = "2021"
66
description = "Normalizes multi-line string indentation while preserving platform-specific line endings."
@@ -9,3 +9,4 @@ license = "MIT"
99

1010
[dependencies]
1111
doc-comment = "0.3.3"
12+
line-ending = "1.2.0"

README.md

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Multi-line String Auto Indent
1+
# Multi-line String Auto-Indent
22

33
[![made-with-rust][rust-logo]][rust-src-page]
44
[![crates.io][crates-badge]][crates-page]
@@ -29,6 +29,10 @@ cargo add string-auto-indent
2929

3030
## Usage
3131

32+
## Example 1: Basic Indentation
33+
34+
This example removes unnecessary leading spaces while preserving the relative indentation of nested lines.
35+
3236
```rust
3337
use string_auto_indent::{auto_indent, LineEnding};
3438

@@ -38,29 +42,36 @@ let text = r#"
3842
Level 1
3943
Level 2
4044
Level 3
41-
"#;
45+
"#;
4246

43-
// For cross-platform testing
44-
let line_ending = LineEnding::detect(text);
47+
// Expected output after applying auto indentation
48+
let expected = r#"
49+
String Auto Indent
50+
51+
Level 1
52+
Level 2
53+
Level 3
54+
"#;
4555

46-
// With auto-indent
56+
// Verify that `auto_indent` correctly normalizes indentation
4757
assert_eq!(
4858
auto_indent(text),
49-
// For cross-platform testing: Restore platform-specific line endings
50-
line_ending.restore("String Auto Indent\n\nLevel 1\n Level 2\n Level 3\n")
59+
expected,
60+
"The auto_indent function should normalize leading whitespace."
5161
);
5262

53-
// Without auto-indent
54-
assert_eq!(
63+
// Ensure the original text is not identical to the expected output
64+
// This confirms that `auto_indent` actually modifies the string.
65+
assert_ne!(
5566
text,
56-
// For cross-platform testing: Restore platform-specific line endings
57-
line_ending.restore("\n String Auto Indent\n\n Level 1\n Level 2\n Level 3\n"),
67+
expected,
68+
"The original text should *not* be identical to the expected output before normalization."
5869
);
5970
```
6071

6172
### Example Output
6273

63-
**With `auto-indent` enabled.**
74+
#### With `auto-indent`
6475

6576
```text
6677
String Auto Indent
@@ -70,7 +81,7 @@ Level 1
7081
Level 3
7182
```
7283

73-
**With `auto-intent` disabled.**
84+
#### Without `auto-intent`
7485

7586
```text
7687
String Auto Indent
@@ -80,6 +91,54 @@ Level 1
8091
Level 3
8192
```
8293

94+
## Example 2: Mixed Indentation
95+
96+
This example demonstrates how `auto_indent` normalizes inconsistent indentation while preserving the relative structure of nested content.
97+
98+
```rust
99+
use string_auto_indent::{auto_indent, LineEnding};
100+
101+
let text = r#"
102+
String Auto Indent
103+
104+
1. Point 1
105+
a. Sub point a
106+
b. Sub point b
107+
2. Point 2
108+
a. Sub point a
109+
b. Sub piont b
110+
1b. Sub piont 1b
111+
"#;
112+
113+
// Expected output after applying auto indentation
114+
let expected = r#"
115+
String Auto Indent
116+
117+
1. Point 1
118+
a. Sub point a
119+
b. Sub point b
120+
2. Point 2
121+
a. Sub point a
122+
b. Sub piont b
123+
1b. Sub piont 1b
124+
"#;
125+
126+
// Verify that `auto_indent` correctly normalizes indentation
127+
assert_eq!(
128+
auto_indent(text),
129+
expected,
130+
"The auto_indent function should normalize leading whitespace."
131+
);
132+
133+
// Ensure the original text is not identical to the expected output
134+
// This confirms that `auto_indent` actually modifies the string.
135+
assert_ne!(
136+
text,
137+
expected,
138+
"The original text should *not* be identical to the expected output before normalization."
139+
);
140+
```
141+
83142
## How It Works
84143

85144
1. Detects the platform’s line endings (`\n`, `\r\n`, `\r`) and normalizes input for processing.
@@ -93,6 +152,8 @@ Level 1
93152
- Formatting log messages or CLI output while ensuring alignment.
94153
- Cleaning up documentation strings or multi-line literals in indented Rust code.
95154
- Processing structured text while ensuring consistent indentation.
155+
- Declaring multi-line variables in code where the indentation should match the codebase for readability, but the actual string content should not retain unnecessary leading spaces.
156+
- Ensuring consistent formatting in generated strings for use in templates, serialization, or output rendering.
96157

97158
## License
98159
Licensed under **MIT**. See [`LICENSE`][license-page] for details.

examples/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use string_auto_indent::auto_indent;
22

33
fn main() {
4-
println!("");
4+
println!();
55
let text = r#"Example:
66
A
77
B
@@ -15,5 +15,5 @@ fn main() {
1515

1616
println!("Without auto-indent:");
1717
print!("{}", text);
18-
println!("");
18+
println!();
1919
}

0 commit comments

Comments
 (0)