// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
// TODO: add tests
use std::fs::{self, File};
use std::io::{self, BufWriter, Read, Write};
-use strings::string_buffer::StringBuffer;
-
use checkstyle::{output_checkstyle_file, output_footer, output_header};
use config::{Config, NewlineStyle, WriteMode};
use rustfmt_diff::{make_diff, print_diff, Mismatch};
// A map of the files of a crate, with their new content
pub type FileMap = Vec<FileRecord>;
-pub type FileRecord = (String, StringBuffer);
+pub type FileRecord = (String, String);
// Append a newline to the end of each file.
-pub fn append_newline(s: &mut StringBuffer) {
+pub fn append_newline(s: &mut String) {
s.push_str("\n");
}
-pub fn write_all_files<T>(file_map: &FileMap, out: &mut T, config: &Config) -> Result<(), io::Error>
+pub fn write_all_files<T>(
+ file_map: &[FileRecord],
+ out: &mut T,
+ config: &Config,
+) -> Result<(), io::Error>
where
T: Write,
{
}
// Prints all newlines either as `\n` or as `\r\n`.
-pub fn write_system_newlines<T>(
- writer: T,
- text: &StringBuffer,
- config: &Config,
-) -> Result<(), io::Error>
+pub fn write_system_newlines<T>(writer: T, text: &str, config: &Config) -> Result<(), io::Error>
where
T: Write,
{
match style {
NewlineStyle::Unix => write!(writer, "{}", text),
NewlineStyle::Windows => {
- for (c, _) in text.chars() {
+ for c in text.chars() {
match c {
'\n' => write!(writer, "\r\n")?,
'\r' => continue,
}
pub fn write_file<T>(
- text: &StringBuffer,
+ text: &str,
filename: &str,
out: &mut T,
config: &Config,
T: Write,
{
fn source_and_formatted_text(
- text: &StringBuffer,
+ text: &str,
filename: &str,
config: &Config,
) -> Result<(String, String), io::Error> {
fn create_diff(
filename: &str,
- text: &StringBuffer,
+ text: &str,
config: &Config,
) -> Result<Vec<Mismatch>, io::Error> {
let (ori, fmt) = source_and_formatted_text(text, filename, config)?;
if let Ok((ori, fmt)) = source_and_formatted_text(text, filename, config) {
let mismatch = make_diff(&ori, &fmt, 3);
let has_diff = !mismatch.is_empty();
- print_diff(mismatch, |line_num| {
- format!("Diff in {} at line {}:", filename, line_num)
- });
+ print_diff(
+ mismatch,
+ |line_num| format!("Diff in {} at line {}:", filename, line_num),
+ config.color(),
+ );
return Ok(has_diff);
}
}