ruma_events/room/message/
sanitize.rspub fn remove_plain_reply_fallback(mut s: &str) -> &str {
if !s.starts_with("> ") {
return s;
}
while s.starts_with("> ") {
if let Some((_line, rest)) = s.split_once('\n') {
s = rest;
} else {
return "";
}
}
if let Some(rest) = s.strip_prefix('\n') {
rest
} else {
s
}
}
#[cfg(test)]
mod tests {
use super::remove_plain_reply_fallback;
#[test]
fn remove_plain_reply() {
assert_eq!(
remove_plain_reply_fallback("No reply here\nJust a simple message"),
"No reply here\nJust a simple message"
);
assert_eq!(
remove_plain_reply_fallback(
"> <@user:notareal.hs> Replied to on\n\
> two lines\n\
\n\
\n\
This is my reply"
),
"\nThis is my reply"
);
assert_eq!(remove_plain_reply_fallback("\n> Not on first line"), "\n> Not on first line");
assert_eq!(
remove_plain_reply_fallback("> <@user:notareal.hs> Previous message\n\n> New quote"),
"> New quote"
);
}
}