Strip the brake line at end of file
This commit is contained in:
parent
f116941904
commit
6d07c43876
|
@ -9,7 +9,7 @@ use crate::optimizer::Optimizer;
|
||||||
use crate::parser::Parser;
|
use crate::parser::Parser;
|
||||||
use crate::resolver::Resolver;
|
use crate::resolver::Resolver;
|
||||||
use crate::translator::{Translator, TranslatedSource};
|
use crate::translator::{Translator, TranslatedSource};
|
||||||
use crate::util::rustfmt_block;
|
use crate::util::{read_to_string, rustfmt_block};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Compiler {
|
pub struct Compiler {
|
||||||
|
@ -28,7 +28,7 @@ impl Compiler {
|
||||||
fn translate_file_contents(&self, input: &Path) -> Result<TranslatedSource, Error> {
|
fn translate_file_contents(&self, input: &Path) -> Result<TranslatedSource, Error> {
|
||||||
let parser = Parser::new().delimiter(self.config.delimiter);
|
let parser = Parser::new().delimiter(self.config.delimiter);
|
||||||
let translator = Translator::new().escape(self.config.escape);
|
let translator = Translator::new().escape(self.config.escape);
|
||||||
let content = fs::read_to_string(input)
|
let content = read_to_string(input)
|
||||||
.chain_err(|| format!("Failed to open template file: {:?}", input))?;
|
.chain_err(|| format!("Failed to open template file: {:?}", input))?;
|
||||||
|
|
||||||
let stream = parser.parse(&*content);
|
let stream = parser.parse(&*content);
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
use std::path::Path;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
pub fn read_to_string(path: &Path) -> io::Result<String> {
|
||||||
|
let mut content = std::fs::read_to_string(path)?;
|
||||||
|
|
||||||
|
// strip break line at file end
|
||||||
|
if content.ends_with('\n') {
|
||||||
|
content.truncate(content.len() - 1);
|
||||||
|
if content.ends_with('\r') {
|
||||||
|
content.truncate(content.len() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(content)
|
||||||
|
}
|
||||||
|
|
||||||
/// Format block expression using `rustfmt` command
|
/// Format block expression using `rustfmt` command
|
||||||
pub fn rustfmt_block(source: &str) -> io::Result<String> {
|
pub fn rustfmt_block(source: &str) -> io::Result<String> {
|
||||||
let mut new_source = String::with_capacity(source.len() + 11);
|
let mut new_source = String::with_capacity(source.len() + 11);
|
||||||
|
|
Loading…
Reference in New Issue