Skip to content

Commit

Permalink
Drop the dependency on regex
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed Jan 25, 2024
1 parent 5d8d37a commit 6b44bc3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ search_path = "0.1.4"
clap = { version = "4.4.11", features = ["derive"] }
enumset = "1.1.3"
libyaml = "0.2.0"
regex = "1.10.3"
25 changes: 17 additions & 8 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ use std::{

#[derive(thiserror::Error, Debug)]
pub enum MetaDataError {
#[error(transparent)]
RegexError(#[from] regex::Error),
#[error(transparent)]
IoError(#[from] std::io::Error),
}

use regex::Regex;
use search_path::SearchPath;

type Query = Vec<(String, String)>;
Expand Down Expand Up @@ -44,11 +41,23 @@ pub fn index() -> Result<Index, MetaDataError> {
let path = entry?.path();

if let Ok(content) = fs::read_to_string(&path) {
let re = Regex::new(r"(?m)^#\+([^:]+):(.+)$")?;
for (_, [key, value]) in re.captures_iter(&content).map(|c| c.extract()) {
let k = key.trim().into();
let v = value.trim().into();
index.entry((k, v)).or_default().insert(path.clone());
for line in content.lines() {
if let Some(line) = line.strip_prefix("#+") {
if let Some((key, value)) = line.split_once(":") {
let k = key.trim();
let v = value.trim();
if !k.is_empty()
&& !v.is_empty()
&& k.chars().all(|c| c.is_ascii_alphanumeric())
&& v.chars().all(|c| c.is_ascii_graphic())
{
index
.entry((k.into(), v.into()))
.or_default()
.insert(path.clone());
}
}
}
}
}
}
Expand Down

0 comments on commit 6b44bc3

Please sign in to comment.