1mod greetings;
8mod dictionary;
9
10use std::collections::HashMap;
11
12use dictionary::*;
13
14fn is_ender(c: char) -> bool {
15 match c {
16 '.' | '!' | '?' | '‽' => true,
17 _ => false,
18 }
19}
20
21fn unphrase(_: &HashMap<String, Vec<&'static str>>, string: &str) -> String {
22 let out = string.to_string();
23
24 let out = out.replace("'sup", PHRASE_ASK_GOINGS_SLANG);
25 let out = out.replace("what's been going on with you", PHRASE_ASK_GOINGS_FORMAL);
26 let out = out.replace("what's up", PHRASE_ASK_GOINGS_INFORMAL);
27
28 out
29}
30
31fn reformat(dict: &HashMap<String, Vec<&'static str>>, string: &str)
32 -> String
33{
34 let mut out = String::new();
35 let unphrase = unphrase(dict, &string.to_lowercase());
36 let a : Vec<_> = unphrase.split(|x| x == ' ' || x == ',').collect();
37
38 for i in a {
39 if i.is_empty() == false {
40 let i = i.to_lowercase();
41 let i = if let Some(i) = dict.get(&i) {
42 i[0]
43 } else {
44 &i
45};
47
48out.push_str(&i);
50out.push(' ');
52 }
53 }
54
55 out
56}
57
58pub fn encode(utf8_text: &str) -> Vec<u8> {
63 let dict = dictionary::from();
64 let utem = Vec::new();
65let mut index = 0;
67 let group: Vec<_> = utf8_text.split(is_ender).collect();
68
69 for i in utf8_text.match_indices(is_ender) {
70 let reformatted = reformat(&dict, group[index]);
71
72 match i.1 {
73 "." => println!(". {}", reformatted),
74 "!" => println!("! {}", reformatted),
75 "?" => println!("? {}", reformatted),
76 "‽" => println!("‽ {}", reformatted),
77 _ => unreachable!(),
78 }
79
80index += 1;
82 }
83
84 let end = reformat(&dict, group[index]);
85 if end.is_empty() == false {
86 println!("_ {}", end);
87 }
88 println!();
89
90 utem
91}
92
93pub fn translate(ranslat: &str) -> String {
94 if ranslat.starts_with("%") {
96 return ranslat[1..].to_string();
97 }
98
99 ranslat.to_string()
100}