#line-ending #normalized #iterator #ending

normalized-line-endings

Returns an iterator over characters with all line endings converted to \n

8 releases

new 0.0.8 May 21, 2025
0.0.7 May 20, 2025

#3 in #ending

Download history 123/week @ 2025-05-14

123 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

16KB
143 lines

Normalized line endings

Crates.io Code coverage build Linux build Windows build MacOs MIT licensed Apache 2.0 licensed Contributor Covenant Made by Human

Overview

The Normalized Line Endings crate provides an iterator over characters with normalized line endings, meaning all valid line endings in the input are converted to a single newline character: \n (U+000A).

For example:

  • \n\n
  • \r\n
  • \r\n\n

The normalized iterator can be created using standalone function normalized or by calling the method normalized on any iterator over characters.

This work was inspired by normalize-line-endings crate.

Examples

Using standalone function

use normalized_line_endings::normalized;

let input = "This is a string \n with \r some \n\r\n random newlines\r\r\n\n";
assert_eq!(
  "This is a string \n with \n some \n\n random newlines\n\n\n",
  normalized(input.chars()).collect::<String>()
);

Using trait extension

use normalized_line_endings::Normalized;

let input = "This is a string \n with \r some \n\r\n random newlines\r\r\n\n";
assert_eq!(
  "This is a string \n with \n some \n\n random newlines\n\n\n",
  input.chars().normalized().collect::<String>()
);

License

Licensed under either of

at your option.

Contribution

Any contributions to normalized-line-endings are greatly appreciated. All contributions intentionally submitted for inclusion in the work by you, shall be dual licensed as above, without any additional terms or conditions.


Brought to you with 💙 by Engos Software

No runtime deps