Prevent backslash stripping in string literals

This commit is contained in:
Marcus Klaas 2015-12-12 16:20:53 +01:00
parent e20722ab5d
commit 8cccf45d43
3 changed files with 13 additions and 4 deletions

View File

@ -30,11 +30,10 @@ pub struct StringFormat<'a> {
pub config: &'a Config, pub config: &'a Config,
} }
// TODO: simplify this! // FIXME: simplify this!
pub fn rewrite_string<'a>(s: &str, fmt: &StringFormat<'a>) -> Option<String> { pub fn rewrite_string<'a>(s: &str, fmt: &StringFormat<'a>) -> Option<String> {
// TODO if lo.col > IDEAL - 10, start a new line (need cur indent for that)
// Strip line breaks. // Strip line breaks.
let re = Regex::new(r"(\\[:space:]+)").unwrap(); let re = Regex::new(r"(\\[\n\r][:space:]*)").unwrap();
let stripped_str = re.replace_all(s, ""); let stripped_str = re.replace_all(s, "");
let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::<Vec<&str>>(); let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::<Vec<&str>>();
@ -87,7 +86,7 @@ pub fn rewrite_string<'a>(s: &str, fmt: &StringFormat<'a>) -> Option<String> {
let line = if fmt.trim_end { let line = if fmt.trim_end {
raw_line.trim() raw_line.trim()
} else { } else {
// TODO: use as_str once it's stable. // FIXME: use as_str once it's stable.
&*raw_line &*raw_line
}; };

View File

@ -34,3 +34,8 @@ formatting"#;
"stuffin'" "stuffin'"
} }
fn issue682() {
let a = "hello \\ o/";
let b = a.replace("\\ ", "\\");
}

View File

@ -40,3 +40,8 @@ formatting"#;
"stuffin'" "stuffin'"
} }
fn issue682() {
let a = "hello \\ o/";
let b = a.replace("\\ ", "\\");
}