Remove line breaks from path and do not allow search option for protocol links.

This commit is contained in:
Tom Alexander
2023-10-08 13:02:09 -04:00
parent aa253c38dd
commit d987b9b75b
3 changed files with 33 additions and 6 deletions

View File

@@ -732,3 +732,33 @@ impl<'s> RadioLink<'s> {
self.path
}
}
enum PathState {
Normal,
HasLineBreak(String),
}
impl<'s> AngleLink<'s> {
/// Remove line breaks but preserve multiple consecutive spaces.
pub fn get_path(&self) -> Cow<'s, str> {
let mut state = PathState::Normal;
for (offset, c) in self.path.char_indices() {
match (&mut state, c) {
(PathState::Normal, '\n') => {
let mut ret = String::with_capacity(self.path.len());
ret.push_str(&self.path[..offset]);
state = PathState::HasLineBreak(ret);
}
(PathState::Normal, _) => {}
(PathState::HasLineBreak(_), '\n') => {}
(PathState::HasLineBreak(ret), _) => {
ret.push(c);
}
}
}
match state {
PathState::Normal => Cow::Borrowed(self.path),
PathState::HasLineBreak(ret) => Cow::Owned(ret),
}
}
}