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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use std::{collections::HashSet, str};
use indicatif::{ProgressBar, ProgressStyle};
pub(crate) fn is_alphanumeric(text: &str) -> bool {
if text.is_empty() {
return false;
}
text.chars().all(|c| c.is_alphanumeric())
}
pub(crate) fn contains_punctuation(text: &str) -> bool {
if text.is_empty() {
return false;
}
text.chars().any(|c| c.is_ascii_punctuation())
}
pub(crate) fn contains_numbers(text: &str) -> bool {
if text.is_empty() {
return false;
}
text.chars().any(|c| c.is_ascii_digit())
}
pub(crate) fn contains_special_characters(text: &str, special_characters: HashSet<char>) -> bool {
if text.is_empty() {
return false;
}
text.chars().any(|c| special_characters.contains(&c))
}
pub(crate) fn get_progress_bar(total: u64) -> ProgressBar {
let progress_bar = ProgressBar::new(total);
progress_bar.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.green/blue}] {human_pos}/{human_len} ({eta})")
.unwrap()
.progress_chars("##-"));
progress_bar
}
pub fn hash_string(text: &str) -> String {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
let mut hasher = DefaultHasher::new();
text.hash(&mut hasher);
format!("{:x}", hasher.finish())
}
pub(crate) fn is_valid_utf8(text: &str) -> bool {
let b = text.as_bytes();
if str::from_utf8(b).is_err() {
return false;
} else {
return true;
}
}
pub(crate) fn char_to_byte(text: String, start: usize, end: usize) -> (usize, usize) {
let start = text.char_indices().nth(start);
let end = text.char_indices().nth(end);
let start = match start {
Some(start) => start.0,
None => 0,
};
let end = match end {
Some(end) => end.0,
None => text.len(),
};
(start, end)
}