1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::collections::HashSet;
static KEYBOARDS: [&str; 1] = [
"abcdefghijklmnopqrstuvwxyz",
];
pub fn detect_keyboard(_s: &str) -> &str {
KEYBOARDS[0]
}
pub fn typos(s: &str) -> Vec<String> {
let kb = detect_keyboard(s);
let mut ts = Vec::new();
for oi in 0..s.len() {
ts.push(format!("{}{}", &s[..oi], &s[oi+1..]));
}
for oi in 0..s.len() {
for k in kb.chars() {
ts.push(format!("{}{}{}", &s[..oi], k, &s[oi+1..]));
}
}
for oi in 0..s.len() {
for k in kb.chars() {
ts.push(format!("{}{}{}", &s[..oi], k, &s[oi..]));
}
}
ts
}
pub fn misspell(s: &str) -> HashSet<String> {
let mut ms = HashSet::new();
for w in typos(s).into_iter() {
ms.insert(w);
}
if ms.contains(s) {
ms.remove(s);
}
ms
}