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
use std::collections::{HashSet, LinkedList};
pub fn find_convert_string(arg: &str) -> LinkedList<(String, String)> {
let mut list = LinkedList::new();
let mut cache = HashSet::new();
let chars: Vec<u8> = arg.bytes().collect();
let mut item = String::new();
let mut last_index: i32 = -1;
let mut index: i32 = -1;
for v in &chars {
index = index + 1;
if last_index == -1 && (*v == '#' as u8 || *v == '$' as u8) {
let next = chars.get(index as usize + 1);
let next_char = b'{';
if next.is_some() && next.unwrap().eq(&next_char) {
last_index = index;
}
continue;
}
if *v == b'}' && last_index != -1 {
item = String::from_utf8(chars[(last_index + 2) as usize..index as usize].to_vec())
.unwrap();
if cache.get(&item).is_some() {
item.clear();
last_index = -1;
continue;
}
let value =
String::from_utf8(chars[last_index as usize..(index + 1) as usize].to_vec())
.unwrap();
cache.insert(item.clone());
list.push_back((item.clone(), value));
item.clear();
last_index = -1;
}
}
return list;
}
pub fn count_string_num(s: &str, c: char) -> usize {
let cs = s.chars();
let mut num = 0;
for x in cs {
if x == c {
num += 1;
}
}
num
}
pub fn un_packing_string(column: &str) -> &str {
if column.len() >= 2 {
if column.starts_with('\'') && column.ends_with('\'') {
return &column[1..column.len() - 1];
}
if column.starts_with('`') && column.ends_with('`') {
return &column[1..column.len() - 1];
}
if column.starts_with('\"') && column.ends_with('\"') {
return &column[1..column.len() - 1];
}
}
column
}