Skip to content

Commit

Permalink
no need to read line by line anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jan 30, 2024
1 parent 5a8218b commit 50d3f41
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,33 +214,27 @@ mod itweak {

f.values.clear();

for line in BufReader::new(File::open(filename).ok()?)
.lines()
.map_while(Result::ok)
{
let mut it = line.split("tweak!(");

if it.next().is_none() {
continue;
}

for val_str in it {
// Find end of tweak
let mut prec = 1;
let (end, _) = val_str.char_indices().find(|(_, c)| {
match c {
';' | ')' if prec == 1 => {
return true;
}
')' => prec -= 1,
'(' => prec += 1,
_ => {}
let content = std::fs::read_to_string(filename).ok()?;
let mut it = content.split("tweak!(");

it.next(); // skip part before first tweak!

for val_str in it {
// Find end of tweak
let mut prec = 1;
let (end, _) = val_str.char_indices().find(|(_, c)| {
match c {
';' | ')' if prec == 1 => {
return true;
}
false
})?;
')' => prec -= 1,
'(' => prec += 1,
_ => {}
}
false
})?;

f.values.push(val_str[..end].to_string());
}
f.values.push(val_str[..end].to_string());
}

Some(())
Expand Down

0 comments on commit 50d3f41

Please sign in to comment.