fn get_string_subsets()

in amzn-smt-string-transformer/src/string_mappings.rs [324:364]


fn get_string_subsets<'a>(
    s: &str,
    char_map: &'a CharMap,
) -> (Vec<&'a String>, Vec<&'a String>, Vec<&'a String>) {
    let mut prefix_strings: Vec<&String> = Vec::new();
    let mut mid_substrings: Vec<&String> = Vec::new();
    let mut suffix_strings: Vec<&String> = Vec::new();

    // collect the prefix, midpoint, and suffix strings
    for (string_lit, s_props) in &char_map.string_lit_props {
        // don't add the current string to any lists
        // also ignore empty strings since theyre contained in everything
        if string_lit == s || string_lit.is_empty() {
            continue;
        }
        if let StringSetProperties::Some {
            len: _len_bool,
            ranges: _,
            keep_ints: _,
            keep_substrings,
            keep_prefix_suffix: _,
        } = s_props
        {
            if *keep_substrings {
                // don't do else_if, so we cover the case of
                // substrings being repeated
                // example: ":" both as suffix and in the middle of a string
                if s.starts_with(string_lit) {
                    prefix_strings.push(string_lit);
                }
                if s.ends_with(string_lit) {
                    suffix_strings.push(string_lit);
                }
                if s.contains(string_lit) {
                    mid_substrings.push(string_lit);
                }
            }
        }
    }
    (prefix_strings, mid_substrings, suffix_strings)
}