1use std::{collections::HashSet, str};
9
10use indicatif::{ProgressBar, ProgressStyle};
11
12pub(crate) fn is_alphanumeric(text: &str) -> bool {
20 if text.is_empty() {
21 return false;
22 }
23 text.chars().all(|c| c.is_alphanumeric())
24}
25
26pub(crate) fn contains_punctuation(text: &str) -> bool {
34 if text.is_empty() {
35 return false;
36 }
37 text.chars().any(|c| c.is_ascii_punctuation())
38}
39
40pub(crate) fn contains_numbers(text: &str) -> bool {
54 if text.is_empty() {
55 return false;
56 }
57 text.chars().any(|c| c.is_ascii_digit())
58}
59
60pub(crate) fn contains_special_characters(text: &str, special_characters: HashSet<char>) -> bool {
74 if text.is_empty() {
75 return false;
76 }
77 text.chars().any(|c| special_characters.contains(&c))
78}
79
80pub(crate) fn get_progress_bar(total: u64) -> ProgressBar {
87 let progress_bar = ProgressBar::new(total);
88
89 progress_bar.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.green/blue}] {human_pos}/{human_len} ({eta})")
90 .unwrap()
91 .progress_chars("##-"));
92 progress_bar
93}
94
95pub fn hash_string(text: &str) -> String {
96 use std::collections::hash_map::DefaultHasher;
97 use std::hash::{Hash, Hasher};
98
99 let mut hasher = DefaultHasher::new();
100 text.hash(&mut hasher);
101 format!("{:x}", hasher.finish())
102}
103
104pub(crate) fn is_valid_utf8(text: &str) -> bool {
105 let b = text.as_bytes();
106 if str::from_utf8(b).is_err() {
107 return false;
108 } else {
109 return true;
110 }
111}
112
113pub(crate) fn char_to_byte(text: String, start: usize, end: usize) -> (usize, usize) {
114 let start = text.char_indices().nth(start);
115 let end = text.char_indices().nth(end);
116 let start = match start {
117 Some(start) => start.0,
118 None => 0,
119 };
120 let end = match end {
121 Some(end) => end.0,
122 None => text.len(),
123 };
124 (start, end)
125}