1use crate::charset_def::{get_charset_definition, get_charset_definitions};
4
5static UNICODE: &str = "Unicode";
6
7pub fn encode(charset_name: &str, input: &str) -> String {
11 if charset_name == UNICODE {
12 return input.to_string();
13 }
14 let mut output = String::new();
15
16 match get_charset_definition(charset_name) {
17 Some(charset_def) => {
18 for char in input.chars() {
19 match charset_def.get(&char) {
20 Some(encoded) => output.push_str(encoded),
21 None => output.push(char),
22 }
23 }
24 }
25 None => {
26 output = input.to_string();
27 }
28 }
29 output
30}
31
32pub fn get_charset_name() -> Vec<String> {
34 let mut charset_names = Vec::with_capacity(get_charset_definitions().len() + 1);
35
36 charset_names.push(UNICODE.to_string());
37 for (k, _) in get_charset_definitions() {
38 charset_names.push(k.to_string());
39 }
40 charset_names
41}
42
43pub fn get_charset_names() -> Vec<String> {
45 get_charset_name()
46}