pub fn match_pair(&self, p: Paren) -> Option<usize> {
        let n = self.core.current_offset();
        let mut level: usize = 0;
        let x = self.buffer()[n];
        if x == p.open {
            self.buffer()[n + 1..]
                .iter()
                .position(|&c| {
                    if c == p.open {
                        level += 1;
                        return false;
                    }
                    if c != p.close {
                        return false;
                    }
                    if level == 0 {
                        return true;
                    }
                    level -= 1;
                    false
                })
                .map(|i| i + n + 1)
        } else if x == p.close {
            self.buffer()[..n].iter().rposition(|&c| {
                if c == p.close {
                    level += 1;
                    return false;
                }
                if c != p.open {
                    return false;
                }
                if level == 0 {
                    return true;
                }
                level -= 1;
                false
            })
        } else {
            None
        }
    }
/// Matches a pair of parentheses.
///
/// # Examples
///
/// ```
/// # use edit::editor::Editor;
/// use edit::editor::Paren;
/// let editor = Editor::new("a { b } c", 0, 2).unwrap();
/// assert_eq!(editor.match_pair(Paren {open: '{', close: '}'}), Some(6));
///
/// let editor = Editor::new("a { b  c", 0, 2).unwrap();
/// assert_eq!(editor.match_pair(Paren {open: '{', close: '}'}), None);
///
/// let editor = Editor::new(" [1, 3) ", 0, 1).unwrap();
/// assert_eq!(editor.match_pair(Paren {open: '[', close: ')'}), Some(6));
/// ```
Matches a pair of parentheses.
Matches a pair of parentheses .
pub fn match_pair(&self, p: Paren) -> Option<usize> {
        let n = self.core.current_offset();
        let mut level: usize = 0;
        let x = self.buffer()[n];
        if x == p.open {
            self.buffer()[n + 1..]
                .iter()
                .position(|&c| {
                    if c == p.open {
                        level += 1;
                        return false;
                    }
                    if c != p.close {
                        return false;
                    }
                    if level == 0 {
                        return true;
                    }
                    level -= 1;
                    false
                })
                .map(|i| i + n + 1)
        } else if x == p.close {
            self.buffer()[..n].iter().rposition(|&c| {
                if c == p.close {
                    level += 1;
                    return false;
                }
                if c != p.open {
                    return false;
                }
                if level == 0 {
                    return true;
                }
                level -= 1;
                false
            })
        } else {
            None
        }
    }
pub fn match_pair ( & self , p : Paren ) -> Option < usize > { let n = self . core . current_offset ( ) ; let mut level : usize = 0 ; let x = self . buffer ( ) [ n ] ; if x == p . open { self . buffer ( ) [ n + 1 .. ] . iter ( ) . position ( | & c | { if c == p . open { level += 1 ; return false ; } if c != p . close { return false ; } if level == 0 { return true ; } level -= 1 ; false } ) . map ( | i | i + n + 1 ) } else if x == p . close { self . buffer ( ) [ .. n ] . iter ( ) . rposition ( | & c | { if c == p . close { level += 1 ; return false ; } if c != p . open { return false ; } if level == 0 { return true ; } level -= 1 ; false } ) } else { None } }
Matches a pair of parentheses.
Matches a pair of parentheses .
&self
p
Paren
&self
p
Paren
examples
None
use edit::editor::editor;
use edit::editor::Paren;
let editor = Editor::new("a { b } c", 0, 2).unwrap();
assert_eq!(editor.match_pair(Paren {open: '{', close: '}'}), Some(6)).




use edit :: editor :: Paren ; let editor = Editor :: new ( " a { b } c " 0 2 ) . unwrap () ; assert_eq! ( editor . match_pair ( Paren { open : ' { ' close : ' } ' } ) Some ( 6 )) .