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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
use HashMap;
use Regex;
/// Converts a comma-separated string into a vector of strings.
///
/// This function splits a comma-separated string into individual elements,
/// trims whitespace from each element, and filters out empty strings.
/// Each resulting string is converted into an owned String type.
///
/// # Arguments
///
/// * `comma_separated_values` - A string slice containing comma-separated values.
///
/// # Returns
///
/// A Vec<String> containing the processed strings from the input.
///
/// # Example
///
/// ```rust
/// let input = "hello, world, , rust ";
/// let result = byteutils::string::to_array(input);
/// assert_eq!(result, vec!["hello", "world", "rust"]);
/// ```
/// Escapes special characters in a SQL string by replacing backslashes with double backslashes
/// and single quotes with double single quotes.
///
/// # Arguments
///
/// * `input` - The string to escape
///
/// # Returns
///
/// A String with SQL special characters properly escaped
///
/// # Example
///
/// ```rust
/// let input = "O'Connor\\Path";
/// let escaped = byteutils::string::escape_sql(input);
/// assert_eq!(escaped, "O''Connor\\\\Path");
/// ```
/// Encloses a string in single quotes for SQL string literals.
///
/// # Arguments
///
/// * `name` - The string to enclose in quotes
///
/// # Returns
///
/// A String wrapped in single quotes
///
/// # Example
///
/// ```rust
/// let name = "table_name";
/// let quoted = byteutils::string::enclose_quotes(name);
/// assert_eq!(quoted, "'table_name'");
/// ```
/// Checks if a given word is present in the source string as a whole word, ignoring case.
///
/// This function creates a case-insensitive regular expression pattern that matches the given word
/// as a whole word (bounded by word boundaries) and checks if this pattern
/// is found in the source string.
///
/// # Arguments
///
/// * `src` - A string slice that holds the text to search in.
/// * `word` - A string slice that holds the word to search for.
///
/// # Returns
///
/// Returns `true` if the word is found as a whole word in the source string (ignoring case),
/// `false` otherwise.
///
/// # Examples
///
/// ```rust
/// let source = "Hello world! Welcome to Rust.";
/// assert!(byteutils::string::is_contain_word(source, "world"));
/// assert!(!byteutils::string::is_contain_word(source, "Rust!"));
/// ```
/// Checks if any of the given words are present in the source string as whole words.
///
/// This function iterates through the given list of words and checks if any
/// of them are present in the source string as whole words using the
/// `is_contain_word` function.
///
/// # Arguments
///
/// * `src` - A string slice that holds the text to search in.
/// * `words` - A slice of String values representing the words to search for.
///
/// # Returns
///
/// Returns `true` if any of the words in the list are found as whole words
/// in the source string, `false` otherwise.
///
/// # Examples
///
/// ```rust
/// let source = "The quick brown fox jumps over the lazy dog.";
/// let words = vec!["quick".to_string(), "slow".to_string(), "fox".to_string()];
/// assert!(byteutils::string::has_contain_words(source, &words));
///
/// let no_match_words = vec!["cat".to_string(), "elephant".to_string()];
/// assert!(!byteutils::string::has_contain_words(source, &no_match_words));
/// ```
/// Replaces placeholders in a string with specified replacement values.
///
/// This function takes a string containing placeholders in the format `{{placeholder}}` and
/// replaces them with the specified replacement value. It uses regex pattern matching to
/// find and replace all occurrences of the placeholder.
///
/// # Arguments
///
/// * `input` - A string slice that contains the text with placeholders
/// * `placeholder` - A string slice representing the placeholder name (without braces)
/// * `replacement` - A string slice containing the value to replace the placeholder with
///
/// # Returns
///
/// Returns a new String with all occurrences of the placeholder replaced with the replacement value.
///
/// # Examples
///
/// ```rust
/// let template = "Hello {{name}}! Welcome to {{place}}.";
/// let result = byteutils::string::replace_placeholder(template, "name", "John");
/// assert_eq!(result, "Hello John! Welcome to {{place}}.");
/// ```
///
/// # Panics
///
/// This function will panic if the regex pattern creation fails, which should only happen
/// if the placeholder contains characters that make an invalid regex pattern.
/// Replaces multiple placeholders in a string using a map of placeholder-value pairs.
///
/// This function processes a template string containing multiple placeholders in the format
/// `{{placeholder}}` and replaces each one with its corresponding value from the provided map.
/// If a placeholder in the template doesn't have a corresponding entry in the map, it remains
/// unchanged in the output string.
///
/// # Arguments
///
/// * `template` - A string slice containing the template text with placeholders
/// * `replacements` - A HashMap where keys are placeholder names and values are their replacements
///
/// # Returns
///
/// Returns a new String with all matched placeholders replaced with their corresponding values.
///
/// # Examples
///
/// ```rust
/// use std::collections::HashMap;
///
/// let mut replacements = HashMap::new();
/// replacements.insert("name".to_string(), "John".to_string());
/// replacements.insert("age".to_string(), "30".to_string());
///
/// let template = "Hello {{name}}! You are {{age}} years old.";
/// let result = byteutils::string::replace_multiple_placeholders(template, &replacements);
/// assert_eq!(result, "Hello John! You are 30 years old.");
/// ```