owo/
lib.rs

1use rand::seq::IndexedRandom;
2
3/// Prefixes to be add to beginning of strings
4pub const PREFIXES: [&'static str; 10] = [
5    "<3 ",
6    "0w0 ",
7    "H-hewwo?? ",
8    "HIIII! ",
9    "Haiiii! ",
10    "Huohhhh. ",
11    "OWO ",
12    "OwO ",
13    "UwU ",
14    "uwu ",
15];
16
17/// Suffixes to be add to beginning of strings
18pub const SUFFIXES: [&str; 31] = [
19    " :3",
20    " (●´ω`●)",
21    " UwU",
22    " (✿ ♡‿♡)",
23    " ÙωÙ",
24    " ʕʘ‿ʘʔ",
25    " ʕ•̫͡•ʔ",
26    " >_>",
27    " ^_^",
28    "..",
29    " Huoh.",
30    " ^-^",
31    " ;_;",
32    " ;-;",
33    " xD",
34    " x3",
35    " :D",
36    " :P",
37    " ;3",
38    " XDDD",
39    ", fwendo",
40    " ㅇㅅㅇ",
41    " (人◕ω◕)",
42    "(^v^)",
43    " x3",
44    " ._.",
45    " ( \"◟ \")",
46    " (• o •)",
47    " (;ω;)",
48    " (◠‿◠✿)",
49    " >_<",
50];
51
52/// All chars/words to be substituted with owo'd versions
53pub const SUBSTITUTIONS: [(&str, &str); 10] = [
54    ("r", "w"),
55    ("l", "w"),
56    ("R", "W"),
57    ("L", "W"),
58    // ("ow", "OwO"),
59    ("no", "nu"),
60    ("has", "haz"),
61    ("have", "haz"),
62    ("you", "uu"),
63    ("the ", "da "),
64    ("The ", "Da "),
65];
66
67/// Add random prefixes and suffixes from PREFIXES and SUFFIXES arrays
68///
69/// # Examples
70///
71/// ```
72/// use owo::add_affixes;
73/// let hewwo = add_affixes("hello".to_string());
74/// ```
75pub fn add_affixes(msg: String) -> String {
76    let prefix = PREFIXES.choose(&mut rand::rng()).unwrap_or(&"Huohhhh. ");
77    let suffix = SUFFIXES.choose(&mut rand::rng()).unwrap_or(&" UwU");
78
79    format!("{prefix}{msg}{suffix}")
80}
81
82/// Replace chars in the original message based on the SUBSTITUTIONS array
83///
84/// # Examples
85///
86/// ```
87/// use owo::{substitute, add_affixes};
88/// let hewwo = substitute(&mut "hello".to_string());
89/// // or 
90/// let mut hewwo = add_affixes("hello".to_string());
91/// let huoh = substitute(&mut hewwo);
92/// ```
93pub fn substitute(msg: &mut String) -> &String {
94    for substiution in SUBSTITUTIONS.iter() {
95        *msg = msg.replace(substiution.0, substiution.1);
96    }
97
98    msg
99}
100
101/// owo a string
102///
103/// # Examples
104///
105/// ```
106/// use owo::owo;
107/// 
108/// println!("{}", owo::owo("Jimmy Carter wins posthumous Grammy for narrating an audiobook of his Sunday school lessons".to_string()))
109/// ```
110pub fn owo(msg: String) -> String {
111    let mut new_msg = add_affixes(msg);
112    substitute(&mut new_msg).to_owned()
113}