simple_string_patterns/
utils.rs1
2use crate::{enums::StringBounds, BoundsPosition, CaseMatchMode};
3
4pub(crate) fn add_sanitized_numeric_string(output: &mut Vec<String>, num_string: &str) {
7 output.push(num_string.trim_end_matches(".").trim_end_matches(",").to_string());
8}
9
10
11pub(crate) fn strs_to_string_bounds<'a>(strs: &'a [&str], case_mode: CaseMatchMode, mode: BoundsPosition) -> Vec<StringBounds<'a>> {
15 strs.into_iter().map(|txt| StringBounds::new(mode, *txt, true, case_mode)).collect()
16}
17
18pub(crate) fn strs_to_negative_string_bounds<'a>(strs: &'a [&str], case_mode: CaseMatchMode, mode: BoundsPosition) -> Vec<StringBounds<'a>> {
22 strs.into_iter().map(|txt| StringBounds::new(mode, *txt, false, case_mode)).collect()
23}
24
25pub(crate) fn pairs_to_string_bounds<'a>(pairs: &'a [(&str, bool)], mode: BoundsPosition) -> Vec<StringBounds<'a>> {
29 pairs.into_iter().map(|(txt, ci)| StringBounds::new(mode, *txt, true, CaseMatchMode::insensitive(*ci))).collect()
30}
31
32pub(crate) fn extract_string_element_by_index(parts: Vec<String>, index: i32) -> Option<String> {
35 let num_parts = parts.len();
36 let target_index = if index >= 0 { index as usize } else { (num_parts as i32 + index) as usize };
37 if target_index < num_parts {
38 parts.get(target_index).map(|part| part.to_owned())
39 } else {
40 None
41 }
42}