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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use crate;
use HashMap;
use *;
/// Translates `text` into leetspeak, returning a new string. Since each English letter
/// is mapped to multiple leetspeak letters, each leetspeak letter is chosen from its mapping at random using
/// [`rand::thread_rng()`]. This means that the result of [`translate()`] is non-deterministic
/// (i.e. translating the same `text` may return different results). If you want deterministic (non-random)
/// translation, use [`translate_with_level()`] or [`translate_custom()`].
/// The translation table is based on [wikipedia/leet](https://en.wikipedia.org/wiki/Leet#Orthography)
///
/// Usage:
/// ```
/// let text = "sphinx of black quartz, judge my vow";
/// let translation = leetspeak::translate(text);
/// ```
/// The level determines the degree of translation. [`Level::One`] replaces a few common
/// letters with numbers; [`Level::Two`] replaces most letters with either single-digit numbers
/// multi-character strings that use symbols to represent characters; [`Level::Three`] is the same
/// as level 2, except it replaces *all* letters in the original text. Below are examples of the
/// translation output using the pangram "sphinx of black quartz, judge my vow"
///
/// | Level | Output |
/// | ----- | ------ |
/// | Level 1: | "5ph1nx 0f 814ck qu427z, jud93 my v0w" |
/// | Level 2: | "5p#1nx 0f 81@<k qv@27z, \_\|v\|)93 m`/ \\/0vv" |
/// | Level 3: | "$\|>/-/!\|\\\|}{ ()/= /3\|\_@(\|< 0\_v@I2+7\_, \_]vcl(\_+& /V\\`/ \\\|()vv" |
/// Translates `text` into leetspeak using the translation level `level`, returning a new string.
/// [`Level::One`] replaces a few common letters with numbers; [`Level::Two`] replaces most letters with
/// either single-digit numbers multi-character strings that use symbols to represent characters;
/// [`Level::Three`] is the same as level 2, except it replaces all letters in the original text.
///
/// Usage:
/// ```
/// let text = "sphinx of black quartz, judge my vow";
/// let translation = leetspeak::translate_with_level(text, &leetspeak::Level::One);
/// assert_eq!(translation, r#"5ph1nx 0f 814ck qu427z, jud93 my v0w"#);
/// ```
/// Translates `text` into leetspeak using a custom mapping table (type `HashMap<char,String>`),
/// returning a new string. Characters not included in the mapping table are not changed.
///
/// Usage:
/// ```
/// let mapping = std::collections::HashMap::from([
/// ('a', String::from("4")),
/// ('c', String::from("<")),
/// ('e', String::from("€")),
/// ('m', String::from(r#"/\/\"#)),
/// ('p', String::from("|*")),
/// ('s', String::from("ehs")),
/// ('w', String::from("vv")),
/// ('z', String::from("7_")),
///]);
///
/// let text = "sphinx of black quartz, judge my vow";
/// let translation = leetspeak::translate_custom(text, &mapping, &true);
/// assert_eq!(translation, r#"ehs|*hinx of bl4<k qu4rt7_, judg€ /\/\y vovv"#);
///```
/// Inverts the case of an ASCII character.
/// 'A' => 'a' and 'a' => 'A'