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
use Regex;
/// Finds and returns the substring before the first occurrence of a given separator.
///
/// # Arguments
///
/// * `s` - A string slice that holds the text to search within.
/// * `separator` - A string slice that specifies the character(s) to look for as a separator.
///
/// # Returns
///
/// Returns a new `String` containing the substring before the first occurrence of the separator.
/// If the separator is not found, an empty `String` is returned.
///
/// # Examples
///
/// ```
/// use bt_string_utils::finder::get_first_occurrance;
/// let result = get_first_occurrance("Hello, world!", ", ");
/// assert_eq!(result, "Hello");
///
/// let result = get_first_occurrance("No separator here", ",");
/// assert_eq!(result, "");
/// ```
/// Checks whether a given string contains the specified `word`
/// as a whole word, using word boundaries.
///
/// A whole word match means the `word` must be surrounded by non-word characters
/// (e.g., spaces, punctuation) or string boundaries. Substrings within longer words
/// will not match.
///
/// # Arguments
///
/// * `text` - The string to search within.
/// * `word` - The target word to search for.
///
/// # Returns
///
/// * `true` if `word` appears as a whole word in `haystack`.
/// * `false` otherwise.
///
/// # Examples
///
/// ```
/// use bt_string_utils::finder::contains_whole_word;
/// assert_eq!(contains_whole_word("this is a target match", "target"), true);
/// assert_eq!(contains_whole_word("this is a targeted match", "target"), false);
/// assert_eq!(contains_whole_word("no-target", "target"), false);
/// ```
/// Returns a UTF-8 safe slice containing the first `n` characters of `s`.
/// If `s` contains fewer than `n` characters, the entire string is returned.
/// # Arguments
///
/// * `s` - The input string slice.
/// * `n` - The number of Unicode characters to include.
///
/// # Returns
///
/// A `&str` slice containing at most the first `n` Unicode characters.
///
/// ```
/// use bt_string_utils::finder::get_first_n_chars;
/// assert_eq!(get_first_n_chars("hello world", 5), "hello");
/// assert_eq!(get_first_n_chars("héllo", 2), "hé");
/// assert_eq!(get_first_n_chars("short", 20), "short");
/// ```
///Get last n chars of a str
/// Returns a slice containing the last `n` Unicode characters of the input string.
///
/// # Examples
/// ```
/// use bt_string_utils::finder::get_last_n_chars;
/// let s = "a💙b💛c";
/// assert_eq!(get_last_n_chars(s, 2), "💛c");
/// ```
/// Extracts the first letter of every word in a string and returns
/// the collected initials in uppercase.
///
/// Words are defined as sequences of non‑whitespace characters.
/// Leading, trailing, and repeated whitespace are ignored.
///
/// # Examples
///
/// ```
/// use bt_string_utils::finder::initials_uppercase;
/// let result = initials_uppercase("Rust language is fast");
/// assert_eq!(result, "RLIF");
/// ```
///
/// ```
/// use bt_string_utils::finder::initials_uppercase;
/// let result = initials_uppercase(" multiple spaces here ");
/// assert_eq!(result, "MSH");
/// ```
///
/// ```
/// use bt_string_utils::finder::initials_uppercase;
/// let result = initials_uppercase("");
/// assert_eq!(result, "");
/// ```
/// Finds and returns the value corresponding to a given key in a vector of key-value pairs.
///
/// # Arguments
///
/// * `kv_pairs` - A reference to a vector of strings where each string represents a key-value pair separated by '='.
/// * `key_to_find` - The key for which the corresponding value is to be found.
///
/// # Returns
///
/// Returns an `Option`:
/// - `Some(value)` if a matching key is found, containing the value associated with that key.
/// - `None` if no matching key is found.
///
/// # Examples
///
/// ```
/// use bt_string_utils::finder::find_value_by_key;
/// let pairs = vec!["name=John".to_owned(), "age=30".to_owned(), "city=New York".to_owned()];
/// assert_eq!(find_value_by_key(&pairs, "name"), Some("John".to_string()));
/// assert_eq!(find_value_by_key(&pairs, "gender"), None);
/// ```