2
1
Fork 0

typegen: make reference sep parser more idiomatic

This commit is contained in:
outfoxxed 2024-07-21 14:54:39 -07:00
parent 8caead7505
commit fe17f4adbb
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -656,17 +656,13 @@ fn parse_details(comment: Comment) -> String {
(':', false), (':', false),
]; ];
let mut chars = src.chars().enumerate(); let (end, ty) = src.chars().enumerate()
let (end, ty) = loop { .find_map(|(i, char)| {
match chars.next() { separators.iter()
Some((i, c)) => { .find(|(sc, _)| char == *sc)
if let Some(strip) = separators.iter().filter(|(sc, _)| c == *sc).map(|(_, strip)| *strip).next() { .map(|(_, strip)| (i + if *strip { 1 } else { 0 }, &src[..i]))
break (i + if strip { 1 } else { 0 }, &src[..i]); })
} .unwrap_or_else(|| (src.len(), src));
},
None => break (src.len(), src),
}
};
let mut split = ty.rsplit_once('.').unwrap_or(("", ty)); let mut split = ty.rsplit_once('.').unwrap_or(("", ty));