Skip to content

Commit

Permalink
Adds a "Native" option to newline_style.
Browse files Browse the repository at this point in the history
By using it one will get \r\n line endings on Windows, and \n line endings
on other platforms.
  • Loading branch information
rhoot committed Nov 15, 2015
1 parent cdf56f7 commit add37b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config.rs
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion src/filemap.rs
Expand Up @@ -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() {
Expand All @@ -71,6 +81,7 @@ pub fn write_file(text: &StringBuffer,
}
Ok(())
}
NewlineStyle::Native => unreachable!(),
}
}

Expand Down

0 comments on commit add37b9

Please sign in to comment.