Skip to main content

Crate use_line

Crate use_line 

Source
Expand description

§use-line

Composable line-level text primitives for RustUse.

use-line provides small helpers for line counting, indentation, dedentation, and line-ending normalization. It stays explicit about logical lines and keeps the behavior predictable across LF, CRLF, and CR inputs.

§Included primitives

  • line_count
  • non_empty_line_count
  • trim_lines
  • normalize_line_endings
  • indent_lines
  • dedent_lines
  • lines_with_numbers

§Example

use use_line::{dedent_lines, line_count, lines_with_numbers, LineEnding};

assert_eq!(line_count("alpha\nbeta\n"), 2);
assert_eq!(dedent_lines("    alpha\n      beta"), "alpha\n  beta");
assert_eq!(lines_with_numbers("alpha")[0].number.get(), 1);
assert_eq!(LineEnding::Crlf.as_str(), "\r\n");

Structs§

Line
A numbered logical line.
LineNumber
A 1-based line number.
LineStats
Aggregate line counts derived from text.

Enums§

LineEnding
Supported line-ending shapes.

Functions§

dedent_lines
Removes the common indentation shared by non-empty lines.
indent_lines
Prefixes each logical line with the provided indent string.
line_count
Counts logical lines, ignoring a trailing empty line created only by a final line ending.
lines_with_numbers
Returns numbered logical lines.
non_empty_line_count
Counts logical lines whose trimmed content is not empty.
normalize_line_endings
Normalizes line endings to the requested target.
trim_lines
Trims each logical line independently and preserves the input line-ending style when possible.