From add37b9c4991d7ce9bdd58bb4f8c66ac8a9c7244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sk=C3=B6ld?= Date: Sun, 15 Nov 2015 03:34:04 -0800 Subject: [PATCH] Adds a "Native" option to newline_style. By using it one will get \r\n line endings on Windows, and \n line endings on other platforms. --- src/config.rs | 1 + src/filemap.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index dcf0816335b..713d3aefd3c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,6 +26,7 @@ macro_rules! configuration_option_enum{ configuration_option_enum! { NewlineStyle: Windows, // \r\n Unix, // \n + Native, // \r\n in Windows, \n on other platforms } configuration_option_enum! { BraceStyle: diff --git a/src/filemap.rs b/src/filemap.rs index 3f1a867f385..5b997b55c25 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -59,7 +59,17 @@ pub fn write_file(text: &StringBuffer, -> Result<(), io::Error> where T: Write { - match config.newline_style { + let style = if config.newline_style == NewlineStyle::Native { + if cfg!(windows) { + NewlineStyle::Windows + } else { + NewlineStyle::Unix + } + } else { + config.newline_style + }; + + match style { NewlineStyle::Unix => write!(writer, "{}", text), NewlineStyle::Windows => { for (c, _) in text.chars() { @@ -71,6 +81,7 @@ pub fn write_file(text: &StringBuffer, } Ok(()) } + NewlineStyle::Native => unreachable!(), } }