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.
This commit is contained in:
Johan Sköld 2015-11-15 03:34:04 -08:00
parent cdf56f75a1
commit add37b9c49
2 changed files with 13 additions and 1 deletions

View File

@ -26,6 +26,7 @@ macro_rules! configuration_option_enum{
configuration_option_enum! { NewlineStyle: configuration_option_enum! { NewlineStyle:
Windows, // \r\n Windows, // \r\n
Unix, // \n Unix, // \n
Native, // \r\n in Windows, \n on other platforms
} }
configuration_option_enum! { BraceStyle: configuration_option_enum! { BraceStyle:

View File

@ -59,7 +59,17 @@ pub fn write_file(text: &StringBuffer,
-> Result<(), io::Error> -> Result<(), io::Error>
where T: Write 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::Unix => write!(writer, "{}", text),
NewlineStyle::Windows => { NewlineStyle::Windows => {
for (c, _) in text.chars() { for (c, _) in text.chars() {
@ -71,6 +81,7 @@ pub fn write_file(text: &StringBuffer,
} }
Ok(()) Ok(())
} }
NewlineStyle::Native => unreachable!(),
} }
} }