textshrink/
lib.rs

1mod internal;
2
3/// Replace the text using more common character sequences
4pub fn replace(
5    string: &str,
6    watch_casing: bool,
7    loosely: bool,
8) -> String {
9    if watch_casing {
10        if loosely {
11            return internal::optimize_loosely_without_watching_case(
12                string,
13                &internal::get_replacements(),
14                internal::get_alias(),
15            );
16        } else {
17            return internal::optimize_without_watching_case(
18                string,
19                &internal::get_replacements(),
20            );
21        }
22    } else {
23        if loosely {
24            return internal::optimize_loosely(
25                string,
26                &internal::get_replacements(),
27                internal::get_alias(),
28            );
29        } else {
30            return internal::optimize(string, &internal::get_replacements());
31        }
32    }
33}
34
35/// Replace the text with a custom hashmap easily created with [crate::internal::convert_to_replaceable]
36/// The alias vec contains equivilants -> * can also be used as °, to get the default aliases use [crate::internal::get_alias]
37pub fn replace_custom(
38    string: &str,
39    watch_casing: bool,
40    loosely: bool,
41    map: &std::collections::HashMap<String, String>,
42    aliases: Vec<Vec<String>>,
43) -> String {
44    if watch_casing {
45        if loosely {
46            return internal::optimize_loosely_without_watching_case(
47                string, map, aliases,
48            );
49        } else {
50            return internal::optimize_without_watching_case(string, map);
51        }
52    } else {
53        if loosely {
54            return internal::optimize_loosely(string, map, aliases);
55        } else {
56            return internal::optimize(string, map);
57        }
58    }
59}