From b5cacfdc5ffef320c1fb9574d7bbb9693ccbd7ae Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 29 Jan 2020 12:50:15 -0500 Subject: [PATCH] Update regex usages that are different in 1.x --- tools/src/bin/concat_chapters.rs | 2 +- tools/src/bin/link2print.rs | 24 ++++++++++++------------ tools/src/bin/remove_links.rs | 10 +++++----- tools/src/bin/remove_markup.rs | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tools/src/bin/concat_chapters.rs b/tools/src/bin/concat_chapters.rs index c318402a3..71fd86f05 100644 --- a/tools/src/bin/concat_chapters.rs +++ b/tools/src/bin/concat_chapters.rs @@ -61,7 +61,7 @@ fn match_files( regex.replace_all(source_filename, replacement); let source_path = entry.path(); let mut target_path = PathBuf::from(&target_dir); - target_path.push(target_filename); + target_path.push(target_filename.to_string()); return Some((source_path, target_path)); } } diff --git a/tools/src/bin/link2print.rs b/tools/src/bin/link2print.rs index 404c83933..33d90ec24 100644 --- a/tools/src/bin/link2print.rs +++ b/tools/src/bin/link2print.rs @@ -28,26 +28,26 @@ fn parse_references(buffer: String) -> (String, HashMap) { let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###) .unwrap(); let output = re.replace_all(&buffer, |caps: &Captures<'_>| { - let key = caps.at(1).unwrap().to_owned().to_uppercase(); - let val = caps.at(2).unwrap().to_owned(); + let key = caps.get(1).unwrap().as_str().to_uppercase(); + let val = caps.get(2).unwrap().as_str().to_string(); if ref_map.insert(key, val).is_some() { panic!("Did not expect markdown page to have duplicate reference"); } "".to_string() - }); + }).to_string(); (output, ref_map) } fn parse_links((buffer, ref_map): (String, HashMap)) -> String { // FIXME: check which punctuation is allowed by spec. - let re = Regex::new(r###"(?:(?P
(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P[^]]+)\](?:(?:\([[:blank:]]*(?P[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P[^]]*)\]))?))"###).expect("could not create regex");
+    let re = Regex::new(r###"(?:(?P
(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^\[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P[^]]+)\](?:(?:\([[:blank:]]*(?P[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P[^]]*)\]))?))"###).expect("could not create regex");
     let error_code =
         Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
     let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
         match caps.name("pre") {
-            Some(pre_section) => format!("{}", pre_section.to_owned()),
+            Some(pre_section) => format!("{}", pre_section.as_str()),
             None => {
-                let name = caps.name("name").expect("could not get name").to_owned();
+                let name = caps.name("name").expect("could not get name").as_str();
                 // Really we should ignore text inside code blocks,
                 // this is a hack to not try to treat `#[derive()]`,
                 // `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
@@ -55,21 +55,21 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                    name.starts_with("profile") ||
                    name.starts_with("test") ||
                    name.starts_with("no_mangle") ||
-                   error_code.is_match(&name) {
-                    return name
+                   error_code.is_match(name) {
+                    return name.to_string()
                 }
 
                 let val = match caps.name("val") {
                     // `[name](link)`
-                    Some(value) => value.to_owned(),
+                    Some(value) => value.as_str().to_string(),
                     None => {
                         match caps.name("key") {
                             Some(key) => {
-                                match key {
+                                match key.as_str() {
                                     // `[name][]`
                                     "" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
                                     // `[name][reference]`
-                                    _ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
+                                    _ => format!("{}", ref_map.get(&key.as_str().to_uppercase()).expect(&format!("could not find url for the link text `{}`", key.as_str()))),
                                 }
                             }
                             // `[name]` as reference
@@ -81,7 +81,7 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
             }
         }
     });
-    output
+    output.to_string()
 }
 
 #[cfg(test)]
diff --git a/tools/src/bin/remove_links.rs b/tools/src/bin/remove_links.rs
index 4733394b9..a096389b8 100644
--- a/tools/src/bin/remove_links.rs
+++ b/tools/src/bin/remove_links.rs
@@ -19,18 +19,18 @@ fn main() {
     let link_regex = Regex::new(regex).unwrap();
     let first_pass = link_regex.replace_all(&buffer, |caps: &Captures<'_>| {
         // Save the link reference we want to delete.
-        if let Some(reference) = caps.at(2) {
-            refs.insert(reference.to_owned());
+        if let Some(reference) = caps.get(2) {
+            refs.insert(reference.as_str().to_string());
         }
 
         // Put the link title back.
-        caps.at(1).unwrap().to_owned()
+        caps.get(1).unwrap().as_str().to_string()
     });
 
     // Search for the references we need to delete.
     let ref_regex = Regex::new(r"(?m)^\[([^\]]+)\]:\s.*\n").unwrap();
     let out = ref_regex.replace_all(&first_pass, |caps: &Captures<'_>| {
-        let capture = caps.at(1).unwrap().to_owned();
+        let capture = caps.get(1).unwrap().to_owned();
 
         // Check if we've marked this reference for deletion ...
         if refs.contains(capture.as_str()) {
@@ -38,7 +38,7 @@ fn main() {
         }
 
         // ... else we put back everything we captured.
-        caps.at(0).unwrap().to_owned()
+        caps.get(0).unwrap().as_str().to_string()
     });
 
     write!(io::stdout(), "{}", out).unwrap();
diff --git a/tools/src/bin/remove_markup.rs b/tools/src/bin/remove_markup.rs
index c4e85ee8c..8877e038f 100644
--- a/tools/src/bin/remove_markup.rs
+++ b/tools/src/bin/remove_markup.rs
@@ -40,8 +40,8 @@ fn remove_markup(input: String) -> String {
                 let result =
                     regexen.iter().fold(line.to_string(), |result, regex| {
                         regex.replace_all(&result, |caps: &Captures<'_>| {
-                            caps.at(1).unwrap().to_owned()
-                        })
+                            caps.get(1).unwrap().as_str().to_string()
+                        }).to_string()
                     });
                 Some(result)
             }