fn aligned_crop(text: &str, match_index: usize, context: usize) -> (usize, usize) {
    let is_word_component = |c: &char| c.is_alphanumeric() && !is_cjk(*c);

    let word_end_index = |mut index| {
        if text.chars().nth(index - 1).map_or(false, |c| is_word_component(&c)) {
            index += text.chars().skip(index).take_while(is_word_component).count();
        }
        index
    };

    if context == 0 {
        // count need to be at least 1 for cjk queries to return something
        return (match_index, 1 + text.chars().skip(match_index).take_while(is_word_component).count());
    }
    let start = match match_index.saturating_sub(context) {
        0 => 0,
        n => {
            let word_end_index = word_end_index(n);
            // skip whitespaces if any
            word_end_index + text.chars().skip(word_end_index).take_while(char::is_ascii_whitespace).count()
        }
    };
    let end = word_end_index(match_index + context);

    (start, end - start)
}
/// returns the start index and the length on the crop.
returns the start index and the length on the crop.
returns the start index and the length on the crop .
fn aligned_crop(text: &str, match_index: usize, context: usize) -> (usize, usize) {
    let is_word_component = |c: &char| c.is_alphanumeric() && !is_cjk(*c);
    let word_end_index = |mut index| {
        if text.chars().nth(index - 1).map_or(false, |c| is_word_component(&c)) {
            index += text.chars().skip(index).take_while(is_word_component).count();
        }
        index
    };
    if context == 0 {
        // count need to be at least 1 for cjk queries to return something
        return (match_index, 1 + text.chars().skip(match_index).take_while(is_word_component).count());
    }
    let start = match match_index.saturating_sub(context) {
        0 => 0,
        n => {
            let word_end_index = word_end_index(n);
            // skip whitespaces if any
            word_end_index + text.chars().skip(word_end_index).take_while(char::is_ascii_whitespace).count()
        }
    };
    let end = word_end_index(match_index + context);
    (start, end - start)
}
fn aligned_crop ( text : & str , match_index : usize , context : usize ) -> ( usize , usize ) { let is_word_component = | c : & char | c . is_alphanumeric ( ) && ! is_cjk ( * c ) ; let word_end_index = | mut index | { if text . chars ( ) . nth ( index - 1 ) . map_or ( false , | c | is_word_component ( & c ) ) { index += text . chars ( ) . skip ( index ) . take_while ( is_word_component ) . count ( ) ; } index } ; if context == 0 { // count need to be at least 1 for cjk queries to return something return ( match_index , 1 + text . chars ( ) . skip ( match_index ) . take_while ( is_word_component ) . count ( ) ) ; } let start = match match_index . saturating_sub ( context ) { 0 => 0 , n => { let word_end_index = word_end_index ( n ) ; // skip whitespaces if any word_end_index + text . chars ( ) . skip ( word_end_index ) . take_while ( char :: is_ascii_whitespace ) . count ( ) } } ; let end = word_end_index ( match_index + context ) ; ( start , end - start ) }
returns the start index and the length on the crop.
returns the start index and the length on the crop .
text
&str
match_index
usize
context
usize
text
&str
match_index
usize
context
usize