chiark / gitweb /
ini: fixes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 20:28:49 +0000 (21:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 20:28:49 +0000 (21:28 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/ini.rs

index 0d60b79ad59eccd9362122683c8e2a634ddd3b52..294bea3da9c6134394783091c84f4316e09edae2 100644 (file)
@@ -13,7 +13,7 @@ use std::rc::Rc;
 pub struct Loc {
   pub file: Arc<PathBuf>,
   pub lno: usize,
-  pub section: Option<Arc<String>>,
+  pub section: Option<Arc<str>>,
 }
 
 #[derive(Debug,Clone)]
@@ -22,8 +22,9 @@ pub struct Val {
   pub loc: Loc,
 }
 
-pub type Parsed = HashMap<Arc<String>, Section>;
+pub type Parsed = HashMap<Arc<str>, Section>;
 
+#[derive(Debug)]
 pub struct Section {
   /// Location of first encounter
   pub loc: Loc,
@@ -35,6 +36,7 @@ impl Display for Loc {
   fn fmt(&self, f: &mut fmt::Formatter) {
     write!(f, "{:?}:{}", &self.file, self.lno)?;
     if let Some(s) = &self.section {
+      write!(f, " ")?;
       let dbg = format!("{:?}", &s);
       if let Some(mid) = (||{
         let mid = dbg.strip_prefix(r#"""#)?;
@@ -62,7 +64,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path)
     let line = line.trim();
 
     if line.is_empty() { continue }
-    if regex_is_match!(r#"^ [;#] "#x, line) { continue }
+    if regex_is_match!(r#"^ [;\#] "#x, line) { continue }
 
     let loc = Loc {
       lno,
@@ -74,7 +76,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path)
       if let Some((_,new,)) =
         regex_captures!(r#"^ \[ \s* (.+?) \s* \] $"#x, line)
       {
-        let new: Arc<String> = new.to_owned().into();
+        let new: Arc<str> = new.to_owned().into();
 
         section.take(); // drops previous RefCell borrow of parsed
 
@@ -93,7 +95,7 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path)
         section = Some(new_section);
 
       } else if let Some((_, key, val)) =
-        regex_captures!(r#"^ ( [^\[] .*? ) \s* = \s* (.*) $"#, line)
+        regex_captures!(r#"^ ( [^\[] .*? ) \s* = \s* (.*) $"#x, line)
       {
         let val = Val { loc: loc.clone(), val: val.into() };