rbatis_codegen/codegen/
string_util.rs

1use std::collections::LinkedList;
2
3//find like #{*,*},${*,*} value *
4pub fn find_convert_string(arg: &str) -> LinkedList<(String, String)> {
5    let mut list = LinkedList::new();
6    let chars: Vec<u8> = arg.bytes().collect();
7    let mut item = String::with_capacity(arg.len());
8    let mut index: i32 = -1;
9    for v in &chars {
10        index = index + 1;
11        if !item.is_empty() {
12            item.push(*v as char);
13            if *v == '}' as u8 {
14                let key = item[2..item.len() - 1].to_string();
15                list.push_back((key, item.clone()));
16                item.clear();
17            }
18            continue;
19        }
20        if (*v == '#' as u8 || *v == '$' as u8)
21            && chars.get(index as usize + 1).eq(&Some(&('{' as u8)))
22        {
23            item.push(*v as char);
24        }
25    }
26    return list;
27}
28
29pub fn count_string_num(s: &String, c: char) -> usize {
30    let cs = s.chars();
31    let mut num = 0;
32    for x in cs {
33        if x == c {
34            num += 1;
35        }
36    }
37    return num;
38}
39
40///input 'strings' => strings
41pub fn un_packing_string(column: &str) -> &str {
42    if column.len() >= 2 {
43        if column.starts_with("'") && column.ends_with("'") {
44            return &column[1..column.len() - 1];
45        }
46        if column.starts_with("`") && column.ends_with("`") {
47            return &column[1..column.len() - 1];
48        }
49        if column.starts_with("\"") && column.ends_with("\"") {
50            return &column[1..column.len() - 1];
51        }
52    }
53    return column;
54}