#[cfg(any(
feature = "shift_cipher",
feature = "base16",
feature = "base32",
feature = "base32hex",
feature = "hex"
))]
pub(crate) fn text_to_mono_case(
text: &Vec<u8>,
to_uppercase: bool,
) -> Vec<u8> {
let mut mono_case_text = Vec::new();
for l in text {
if to_uppercase && 0x61 <= *l && *l <= 0x7a {
mono_case_text.push(*l - 0x20);
} else if !to_uppercase && 0x41 <= *l && *l <= 0x5a {
mono_case_text.push(*l + 0x20);
} else {
mono_case_text.push(*l);
}
}
mono_case_text
}
#[cfg(any(feature = "doc_tests", test))]
mod tests {
#[cfg(any(
feature = "shift_cipher",
feature = "base16",
feature = "base32",
feature = "base32hex",
feature = "hex"
))]
use super::*;
#[cfg(any(
feature = "shift_cipher",
feature = "base16",
feature = "base32",
feature = "base32hex",
feature = "hex"
))]
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_01() {
let text = vec![0x56, 0x49, 0x47, 0x45, 0x4e, 0x45, 0x52, 0x45];
let expected_text = vec![0x76, 0x69, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x65];
let calculated_text = text_to_mono_case(&text, false);
assert_eq![calculated_text, expected_text];
}
#[cfg(any(
feature = "shift_cipher",
feature = "base16",
feature = "base32",
feature = "base32hex",
feature = "hex"
))]
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_02() {
let text = vec![0x76, 0x69, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x65];
let expected_text = vec![0x56, 0x49, 0x47, 0x45, 0x4e, 0x45, 0x52, 0x45];
let calculated_text = text_to_mono_case(&text, true);
assert_eq![calculated_text, expected_text];
}
}