Files
tamerye/src/util.rs
T

22 lines
653 B
Rust

pub(crate) fn transpose_codepoints_in_range(
text: &str,
distance: i32,
range_start: u32,
range_end: u32,
) -> String {
debug_assert!(range_start <= range_end);
debug_assert!(i64::from(range_start) + i64::from(distance) >= 0);
debug_assert!(i64::from(range_end) + i64::from(distance) <= i64::from(u32::MAX));
text.chars()
.map(|c| {
let codepoint = c as u32;
if range_start <= codepoint && codepoint <= range_end {
std::char::from_u32(codepoint.strict_add_signed(distance)).unwrap_or(c)
} else {
c
}
})
.collect()
}