refactor is_ms_filter
* refactor to use matches or patterns * simplify text searching with iterator * match is_ms_filter on bytes level * add regex doc for is_ms_filter * use is_ascii_alphabetic * check equality rather than map_or = Co-authored-by: Connor Skees <connor1skees@gmail.com>
This commit is contained in:
parent
8c1cde8a61
commit
80986efee9
@ -5,35 +5,18 @@ use crate::{
|
|||||||
value::Value,
|
value::Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Matches regex `^[a-zA-Z]+\s*=`.
|
||||||
fn is_ms_filter(s: &str) -> bool {
|
fn is_ms_filter(s: &str) -> bool {
|
||||||
let mut chars = s.chars();
|
let mut bytes = s.bytes();
|
||||||
|
|
||||||
if let Some(c) = chars.next() {
|
if !bytes.next().map_or(false, |c| c.is_ascii_alphabetic()) {
|
||||||
if !matches!(c, 'a'..='z' | 'A'..='Z') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in &mut chars {
|
bytes
|
||||||
match c {
|
.skip_while(|c| c.is_ascii_alphabetic())
|
||||||
' ' | '\t' | '\n' => break,
|
.find(|c| !matches!(c, b' ' | b'\t' | b'\n'))
|
||||||
'a'..='z' | 'A'..='Z' => continue,
|
== Some(b'=')
|
||||||
'=' => return true,
|
|
||||||
_ => return false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for c in chars {
|
|
||||||
match c {
|
|
||||||
' ' | '\t' | '\n' => continue,
|
|
||||||
'=' => return true,
|
|
||||||
_ => return false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user