chore: format
This commit is contained in:
parent
74512ffdb2
commit
d211387420
4 changed files with 24 additions and 23 deletions
|
@ -0,0 +1 @@
|
|||
|
17
src/base4.rs
17
src/base4.rs
|
@ -43,10 +43,10 @@ pub fn encode(text: String) -> String {
|
|||
}
|
||||
|
||||
/// Decodes base 4 catspeak to english text
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// use cat2text::base4::decode;
|
||||
///
|
||||
///
|
||||
/// assert_eq!("i love cats", decode("meow mreow mrrp; meow mrow meow meow mrow mrow mrrp mrrp mreow meow mrrp mrrp; meow meow mrow meow meow mrrp mrrp mrrp meow mrrp meow mrow".to_string()));
|
||||
/// ```
|
||||
pub fn decode(text: String) -> String {
|
||||
|
@ -59,8 +59,17 @@ pub fn decode(text: String) -> String {
|
|||
for engl_word in catspeak_words {
|
||||
let mut word = "".to_string();
|
||||
for engl_letter in core::split_every_3(engl_word) {
|
||||
let char_num = core::cat_to_num(engl_letter.split(" ").map(|item| item.to_string()).collect(), alphabet(), char_length());
|
||||
word += String::from_utf8(vec![(char_num + 96) as u8]).unwrap().as_str();
|
||||
let char_num = core::cat_to_num(
|
||||
engl_letter
|
||||
.split(" ")
|
||||
.map(|item| item.to_string())
|
||||
.collect(),
|
||||
alphabet(),
|
||||
char_length(),
|
||||
);
|
||||
word += String::from_utf8(vec![(char_num + 96) as u8])
|
||||
.unwrap()
|
||||
.as_str();
|
||||
}
|
||||
word += " ";
|
||||
output += word.as_str();
|
||||
|
|
16
src/core.rs
16
src/core.rs
|
@ -1,11 +1,11 @@
|
|||
//! Handles conversion one letter at a time for any base
|
||||
// based off this SO answer: https://stackoverflow.com/a/1119769
|
||||
/// Converts a [`u32`] to catspeak
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// use cat2text::core::num_to_cat;
|
||||
/// use cat2text::base4::{alphabet, char_length};
|
||||
///
|
||||
///
|
||||
/// assert_eq!("meow mreow mrrp".to_string(), num_to_cat(9, alphabet(), char_length()));
|
||||
/// ```
|
||||
pub fn num_to_cat(num: u32, alphabet: Vec<String>, char_length: u32) -> String {
|
||||
|
@ -29,13 +29,13 @@ pub fn num_to_cat(num: u32, alphabet: Vec<String>, char_length: u32) -> String {
|
|||
}
|
||||
|
||||
/// Converts catspeak to a [`u32`]
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// use cat2text::core::cat_to_num;
|
||||
/// use cat2text::base4::{alphabet, char_length};
|
||||
///
|
||||
///
|
||||
/// let letter = vec!["meow".to_string(), "mreow".to_string(), "mrrp".to_string()];
|
||||
///
|
||||
///
|
||||
/// assert_eq!(9, cat_to_num(letter, alphabet(), char_length()));
|
||||
/// ```
|
||||
pub fn cat_to_num(text: Vec<String>, alphabet: Vec<String>, char_length: u32) -> u32 {
|
||||
|
@ -59,10 +59,10 @@ pub fn cat_to_num(text: Vec<String>, alphabet: Vec<String>, char_length: u32) ->
|
|||
}
|
||||
|
||||
/// Splits a cat word into every 3 segments
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// use cat2text::core::split_every_3;
|
||||
///
|
||||
///
|
||||
/// assert_eq!(vec!["meow meow mrrp".to_string(), "meow mreow mrrp".to_string(), "mreow meow mrrp".to_string()], split_every_3("meow meow mrrp meow mreow mrrp mreow meow mrrp".to_string()));
|
||||
/// ```
|
||||
pub fn split_every_3(text: String) -> Vec<String> {
|
||||
|
@ -79,4 +79,4 @@ pub fn split_every_3(text: String) -> Vec<String> {
|
|||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -16,20 +16,11 @@ fn main() {
|
|||
if trimmed == "1".to_string() {
|
||||
input = "".to_string();
|
||||
stdin.read_line(&mut input).unwrap();
|
||||
println!(
|
||||
"{}",
|
||||
base4::decode(
|
||||
input.trim().to_string()
|
||||
)
|
||||
);
|
||||
println!("{}", base4::decode(input.trim().to_string()));
|
||||
} else if trimmed == "2".to_string() {
|
||||
input = "".to_string();
|
||||
stdin.read_line(&mut input).unwrap();
|
||||
println!(
|
||||
"{}",
|
||||
base4::encode(input.trim().to_string())
|
||||
|
||||
);
|
||||
println!("{}", base4::encode(input.trim().to_string()));
|
||||
} else {
|
||||
println!("Invalid input, exiting...");
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue