fn initialize_charmap_with_ranges()

in amzn-smt-string-transformer/src/transpiler.rs [770:809]


fn initialize_charmap_with_ranges(
    partitions: &[NodeSetData],
    mut offset: u32,
    char_map: &mut CharMap,
) -> u32 {
    let mut ranges: BTreeSet<(char, char)> = BTreeSet::new();
    for p in partitions {
        for (_sfc, sfc_args) in &p.string_fcts {
            // foreach range
            if let StringFctArgs::ReRange(c1, c2) = sfc_args {
                ranges.insert((*c1, *c2));
            }
        }
    }

    // if we hit an int range and it's already been mapped, no problem
    // that range will just be skipped
    for (c1, c2) in ranges {
        if !char_map.has_range(c1, c2) {
            let orig_offset = offset;
            let cur_range = RangeParams::new(c1, c2, offset + 1);
            char_map
                .char_map
                .insert(c1, char::from_u32(offset).unwrap());
            offset += (c2 as u32) - (c1 as u32);
            for illegal_char in &char_map.illegal_chars {
                if (*illegal_char as u32) <= offset && (*illegal_char as u32) > orig_offset {
                    offset += 1;
                    break;
                }
            }
            char_map
                .char_map
                .insert(c2, char::from_u32(offset).unwrap());
            offset += 1;
            char_map.ranges.push(cur_range);
        }
    }
    offset
}