Skip to content

Commit

Permalink
implement the "windows newline" trick
Browse files Browse the repository at this point in the history
because on windows we add `\r\n` and only `\n` on linux, we can
just conditionally add `\r` when on windows and then always add
`\n`.
  • Loading branch information
amtoine committed Jun 16, 2023
1 parent 5b5f117 commit d4bb23a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ pub fn format_inner(contents: &[u8], _config: &Config) -> Vec<u8> {
/// It is used frequently in `nufmt`, so
/// we have a wrapper to improve readability of the code.
fn insert_newline(mut bytes: Vec<u8>) -> Vec<u8> {
// If I need cfg windows, then I need \r\n
// let newline = vec![b'\r', b'\n'];
let newline = vec![b'\n'];
bytes.extend(newline.iter());
#[cfg(windows)]
bytes.extend(b"\r");
bytes.extend(b"\n");
bytes
}

Expand Down

0 comments on commit d4bb23a

Please sign in to comment.