Merge pull request #607 from rhoot/native-newline

Adding a "Native" option to newline_style.
This commit is contained in:
Nick Cameron 2015-11-16 08:25:22 +13:00
commit f88345c431
2 changed files with 13 additions and 1 deletions

View File

@ -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:

View File

@ -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!(),
}
}