diff --git a/src/lib.rs b/src/lib.rs index 9f2bdbf..b2eb597 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,43 @@ //! I'm so sorry... +const WORD_REPLACE: [(&str, &str); 9] = [ + ("small", "smol"), + ("cute", "kawaii~"), + ("fluff", "floof"), + ("love", "luv"), + ("stupid", "baka"), + ("idiot", "baka"), + ("what", "nani"), + ("meow", "nya~"), + ("roar", "rawrr~"), +]; + +/// Replace certain words with uwuified equivalents, such as: +/// +/// - `small` -> `smol` +/// - `cute` -> `kawaii~` +/// - `fluff` -> `floof` +/// - ... +/// +/// # Example: +/// +/// ``` +/// use imsosorrybtw::replace_words; +/// let text = "small dogs"; +/// let uwuified = replace_words(text); +/// +/// assert_eq!(uwuified, "smol dogs"); +/// ``` +#[allow(clippy::doc_markdown)] +#[must_use] +pub fn replace_words(text: &str) -> String { + WORD_REPLACE + .iter() + .fold(text.to_string(), |acc, (word, replacement)| { + acc.replace(word, replacement) + }) +} + /// Replace certain characters with their UwU equivalents: /// /// - `r` -> `w` @@ -7,8 +45,6 @@ /// - `n` -> `ny` /// - `ove` -> `uv` /// -/// This will **NOT** account for capitalization. -/// /// # Example /// /// ``` @@ -32,10 +68,14 @@ pub fn char_replace(text: &str) -> String { /// UwUify a string. This basically turns the text lowercase and applies every other function in /// this crate to a string in order: /// +/// - `replace_words` /// - `char_replace` #[allow(clippy::doc_markdown)] #[must_use] pub fn uwuify(text: &str) -> String { - let text = text.to_lowercase(); - char_replace(&text) + let mut text = text.to_lowercase(); + text = replace_words(&text); + text = char_replace(&text); + + text } diff --git a/tests/lib.rs b/tests/lib.rs index 82fded1..9ae019f 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,19 +1,7 @@ //! Tests for the `imsosorrybtw` crate. //! If you're apologizing, might as well do it properly! -use imsosorrybtw::{char_replace, uwuify}; - -/// Test the `char_replace` function. -#[test] -fn test_char_replace() { - // This test is the same as the example in the docs, but it's good to have - // it here as well. - - let text = "I'm so sorry..."; - let uwuified = char_replace(text); - - assert_eq!(uwuified, "I'm so sowwy..."); -} +use imsosorrybtw::uwuify; /// Test if `uwuify` turns the text lowercase. #[test]