/// Given a position in some text, return the containing word boundaries.
///
/// The returned range may not necessary be a 'word'; for instance it could be
/// the sequence of whitespace between two words.
///
/// If the position is on a word boundary, that will be considered the start
/// of the range.
///
/// This uses Unicode word boundaries, as defined in [UAX#29].
///
/// [UAX#29]: http://www.unicode.org/reports/tr29/
Given a position in some text, return the containing word boundaries.
The returned range may not necessary be a 'word'; for instance it could be
the sequence of whitespace between two words.

If the position is on a word boundary, that will be considered the start
of the range.

This uses Unicode word boundaries, as defined in [UAX#29].


Given a position in some text return the containing word boundaries . The returned range may not necessary be a ' word ' ; for instance it could be the sequence of whitespace between two words . If the position is on a word boundary that will be considered the start of the range . This uses Unicode word boundaries as defined in [ UAX#29 ] .
pub fn word_range_for_pos(text: &str, pos: usize) -> Range<usize> {
    let mut word_iter = text.split_word_bound_indices().peekable();
    let mut word_start = pos;
    while let Some((ix, _)) = word_iter.next() {
        if word_iter.peek().map(|(ix, _)| *ix > pos).unwrap_or(false) {
            word_start = ix;
            break;
        }
    }
    let word_end = word_iter.next().map(|(ix, _)| ix).unwrap_or(pos);
    word_start..word_end
}
pub fn word_range_for_pos ( text : & str , pos : usize ) -> Range < usize > { let mut word_iter = text . split_word_bound_indices ( ) . peekable ( ) ; let mut word_start = pos ; while let Some ( ( ix , _ ) ) = word_iter . next ( ) { if word_iter . peek ( ) . map ( | ( ix , _ ) | * ix > pos ) . unwrap_or ( false ) { word_start = ix ; break ; } } let word_end = word_iter . next ( ) . map ( | ( ix , _ ) | ix ) . unwrap_or ( pos ) ; word_start .. word_end }
Given a position in some text, return the containing word boundaries.
Given a position in some text return the containing word boundaries .
text
&str
pos
usize