vim: Add g?
convert to Rot13
/Rot47
(#27824)
Release Notes: - Added `g?` convert to `Rot13`/`Rot47` --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
7bc0dd1bf6
commit
57d7bc23ae
12 changed files with 252 additions and 23 deletions
|
@ -9168,6 +9168,42 @@ impl Editor {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn convert_to_rot13(
|
||||
&mut self,
|
||||
_: &ConvertToRot13,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.manipulate_text(window, cx, |text| {
|
||||
text.chars()
|
||||
.map(|c| match c {
|
||||
'A'..='M' | 'a'..='m' => ((c as u8) + 13) as char,
|
||||
'N'..='Z' | 'n'..='z' => ((c as u8) - 13) as char,
|
||||
_ => c,
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn convert_to_rot47(
|
||||
&mut self,
|
||||
_: &ConvertToRot47,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.manipulate_text(window, cx, |text| {
|
||||
text.chars()
|
||||
.map(|c| {
|
||||
let code_point = c as u32;
|
||||
if code_point >= 33 && code_point <= 126 {
|
||||
return char::from_u32(33 + ((code_point + 14) % 94)).unwrap();
|
||||
}
|
||||
c
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
fn manipulate_text<Fn>(&mut self, window: &mut Window, cx: &mut Context<Self>, mut callback: Fn)
|
||||
where
|
||||
Fn: FnMut(&str) -> String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue