align_spans_by_mapping

Function align_spans_by_mapping 

Source
pub fn align_spans_by_mapping<T: AsRef<[usize]>>(
    spans: &[Span],
    mapping: &[T],
) -> Vec<Vec<Span>>
Expand description

Converts the spans by the given mapping. Generally speaking, the character correspondence between two texts is not necessarily surjective, not injective, not even a methematical map - some character in textA may not have a correspondence in textB, or may have multiple correspondences in textB. Thus, mapping should be provided as Vec<Vec<Span>>.

ยงExamples

let spans = [(0, 2), (3, 4)];
let mapping = [vec![0, 1], vec![], vec![2], vec![4, 5, 6]];
assert_eq!(
    textspan::align_spans_by_mapping(&spans, &mapping),
    [[(0, 2)], [(4, 7)]]
)