Skip to content

Commit

Permalink
Stripping strings outside of TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
szeweq committed Mar 6, 2024
1 parent 530c284 commit 34bd188
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib-core/src/min.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,7 @@ fn strip_toml_array(a: &mut Vec<toml::Value>) {
fn strip_toml_value(v: &mut toml::Value) {
match v {
toml::Value::Table(st) => { strip_toml_table(st); }
toml::Value::String(s) => {
let Some(li) = s.bytes().position(|b| !b.is_ascii_whitespace()) else {
return;
};
*s = s.split_off(li);
let Some(ri) = s.bytes().rposition(|b| !b.is_ascii_whitespace()) else {
return;
};
s.truncate(ri + 1);
}
toml::Value::String(s) => { strip_string(s); }
toml::Value::Array(a) => { strip_toml_array(a); }
_ => {}
}
Expand Down Expand Up @@ -202,3 +193,14 @@ fn uncomment_json_recursive(m: &mut serde_json::Map<String, Value>) {
true
});
}

fn strip_string(s: &mut String) {
let Some(li) = s.bytes().position(|b| !b.is_ascii_whitespace()) else {
return;
};
*s = s.split_off(li);
let Some(ri) = s.bytes().rposition(|b| !b.is_ascii_whitespace()) else {
return;
};
s.truncate(ri + 1);
}

0 comments on commit 34bd188

Please sign in to comment.