gd_rs/
util.rs

1use std::collections::HashMap;
2
3pub fn parser(str: String, sep: char) -> HashMap<String, String> {
4    let mut map = HashMap::new();
5    let mut curr_str = String::new();
6    let mut values = Vec::new();
7
8    for ch in str.chars() {
9        if ch != sep {
10            curr_str.push(ch);
11        } else {
12            values.push(curr_str.clone());
13            curr_str.clear();
14            if values.len() == 2 {
15                let key = values.get(0).unwrap().clone();
16                let value = values.get(1).unwrap().clone();
17                map.insert(key, value);
18                values.clear();
19            }
20        }
21    }
22
23    map
24}
25pub fn tags_replace(str: &mut String, tags: &[[&str; 2]], plus: &str) {
26    for [f, t] in tags {
27        *str = str.replacen(
28            format!("{f}{plus}").as_str(),
29            format!("{t}{plus}").as_str(),
30            99999,
31        );
32    }
33}
34
35pub fn xor(b: &Vec<u8>, k: u8) -> Vec<u8> {
36    b.clone().iter_mut().map(|v| *v ^ k).collect()
37}