/// Parse a single value, which is either a quoted string, or a word without whitespace fn val(input: &str) -> IResult<&str, &str, ()> {
alt((delimited(char('"'), take_while(|c| c != '"'), char('"')), take_while(|c| c != '\n' && c != ' '))).parse(input)
}
/// Parse a key followed by a value, separated by = fn keyval(input: &str) -> IResult<&str, (&str, &str), ()> {
terminated(alphanumeric1, char('=')).and(val).parse(input)
}
/// Parser any number of key-value pairs, separated by 0 or more whitespace fn keyvals(input: &str) -> IResult<&str, BTreeMap<String, String>, ()> {
fold_many0(terminated(keyval, multispace0), BTreeMap::new, |mut map, (key, value)| {
map.insert(key.to_owned(), value.to_owned());
map
})
.parse(input)
}
/// Parse a key-value pair, where the key is a specific tag, separated by =, /// terminated by whitespace fn keyed_val<'i>(key: &'static str) -> impl Parser<&'i str, &'>i str, ()> {
terminated(preceded(terminated(tag(key), char('=')), val), multispace1)
}
#[test] fn test_attach() { let txt = "+uhid1 at bus=0 sernum=\"\" on uhub1"; let res = event(txt); letmut data = BTreeMap::new();
data.insert("bus".to_owned(), "0".to_owned());
data.insert("sernum".to_owned(), "".to_owned());
assert_eq!(
res,
Ok(( "",
Event::Attach {
dev: "uhid1".to_owned(),
parent: data,
location: "uhub1".to_owned(),
}
))
)
}
#[test] fn test_detach() { let txt = "-uhid1 at on uhub1"; let res = event(txt); let data = BTreeMap::new();
assert_eq!(
res,
Ok(( "",
Event::Detach {
dev: "uhid1".to_owned(),
parent: data,
location: "uhub1".to_owned(),
}
))
)
}
#[test] fn test_nomatch() { let txt = "? at bus=0 on uhub1"; let res = event(txt); letmut data = BTreeMap::new();
data.insert("bus".to_owned(), "0".to_owned());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.