2 unstable releases

new 0.3.0 Mar 23, 2023
0.2.2 Nov 8, 2022
0.2.1 Oct 26, 2022
0.2.0 Feb 17, 2021
0.1.0 Jun 7, 2020

#83 in Text processing

Download history 4174/week @ 2022-12-03 4699/week @ 2022-12-10 5484/week @ 2022-12-17 2631/week @ 2022-12-24 4757/week @ 2022-12-31 6267/week @ 2023-01-07 5687/week @ 2023-01-14 7080/week @ 2023-01-21 7785/week @ 2023-01-28 12946/week @ 2023-02-04 15149/week @ 2023-02-11 10966/week @ 2023-02-18 11583/week @ 2023-02-25 11668/week @ 2023-03-04 24224/week @ 2023-03-11 21781/week @ 2023-03-18

71,264 downloads per month
Used in 127 crates (9 directly)

MIT license

12KB
201 lines

newline-converter

newline-converter is a simple library used for converting the newline characters in strings between Windows \r\n and Unix \n style. It mainly serves as a backend for Rust Newline converter CLI tool.

Crates.io

Comparision of newline-wrangling methods

newline-converter (this crate)

  • ✅ Properly handles edge-cases like lone \r characters. For example, \r\n sequences won't become \r\r\n after unix2dos call:
    use newline_converter::unix2dos;
    assert_eq!(
      unix2dos("\nfoo\r\nbar\n"),
      "\r\nfoo\rbar\n"
    );
    
  • ✅ Is the fastest when input data is small (few bytes of text with line breaks).
  • ❌ Is the slowest (or second slowest in case of unix2dos) when dealing with larger data sets (ex. 100 paragraphs of Lorem Ipsum).

string.replace

  • ❌ Does not handle edge cases properly in unix2dos.
  • ✅ Good performance on larger data sets.

regex crate Regex::replace_all

  • ❌ Does not handle edge cases properly in unix2dos, because of lack of support for look around.
  • ✅ The best performance with larger data sets.

fancy-regex crate Regex::replace_all

  • ✅ Properly handles edge cases.
  • unix2dos has worst performance of all implementations, by an order of magnitude (because of look around used).

Look into benches/bench.rs for the comparision benchmarks.

MSRV

Minimum Supported Rust Version is 1.38.0.

Dependencies

~530KB