/// Insert symbols for the frame into a multimap.
Insert symbols for the frame into a multimap.
Insert symbols for the frame into a multimap .
pub fn insert_symbols(&self, map: &mut BTreeMap<Symbol, Vec<usize>>, frame_number: usize) {
        let mut insert = |symbol: Symbol| {
            if let Some(v) = map.get_mut(&symbol) {
                v.push(frame_number);
            } else {
                map.insert(symbol, vec![frame_number]);
            }
        };
        for row in 0..self.y_max {
            let mut symbol: Symbol = Symbol::default();
            let mut previous: FrameCell = FrameCell::default();
            for column in 0..self.x_max {
                let idx: usize = row * self.x_max + column;
                let current: FrameCell = self.buf[idx];
                if let Some(ch) = current.ch {
                    // left strip spaces
                    if ch == ' ' && symbol.text.is_empty() {
                        continue;
                    }
                    if symbol.text.is_empty() {
                        symbol.x = column;
                        symbol.y = row;
                        symbol.fg = current.fg;
                        symbol.intensity = current.intensity;
                        symbol.text.push(ch);
                    } else if current.attr_eq(&previous) {
                        debug_assert!(!symbol.text.is_empty());
                        symbol.text.push(ch);
                    } else {
                        log::trace!(
                            "Ending symbol; previous does not match. symbol={}",
                            symbol.text
                        );
                        insert(symbol.clone());
                        if ch == ' ' {
                            symbol.text = String::new();
                        } else {
                            symbol.text = String::from(ch);
                        }
                        symbol.x = column;
                        symbol.y = row;
                        symbol.fg = current.fg;
                        symbol.intensity = current.intensity;
                    }
                } else if !symbol.text.is_empty() {
                    log::trace!("Ending symbol; unused cell. symbol={}", symbol.text);
                    insert(symbol.clone());
                    symbol.text = String::new();
                }
                previous = current;
            }
            if !symbol.text.is_empty() {
                log::trace!("Ending symbol; end of row. symbol={}", symbol.text);
                insert(symbol);
            }
        }
    }
pub fn insert_symbols ( & self , map : & mut BTreeMap < Symbol , Vec < usize > > , frame_number : usize ) { let mut insert = | symbol : Symbol | { if let Some ( v ) = map . get_mut ( & symbol ) { v . push ( frame_number ) ; } else { map . insert ( symbol , vec ! [ frame_number ] ) ; } } ; for row in 0 .. self . y_max { let mut symbol : Symbol = Symbol :: default ( ) ; let mut previous : FrameCell = FrameCell :: default ( ) ; for column in 0 .. self . x_max { let idx : usize = row * self . x_max + column ; let current : FrameCell = self . buf [ idx ] ; if let Some ( ch ) = current . ch { // left strip spaces if ch == ' ' && symbol . text . is_empty ( ) { continue ; } if symbol . text . is_empty ( ) { symbol . x = column ; symbol . y = row ; symbol . fg = current . fg ; symbol . intensity = current . intensity ; symbol . text . push ( ch ) ; } else if current . attr_eq ( & previous ) { debug_assert ! ( symbol text is_empty ( ) ) ; symbol . text . push ( ch ) ; } else { log :: trace ! ( " " symbol text ) ; insert ( symbol . clone ( ) ) ; if ch == ' ' { symbol . text = String :: new ( ) ; } else { symbol . text = String :: from ( ch ) ; } symbol . x = column ; symbol . y = row ; symbol . fg = current . fg ; symbol . intensity = current . intensity ; } } else if ! symbol . text . is_empty ( ) { log :: trace ! ( " " symbol text ) ; insert ( symbol . clone ( ) ) ; symbol . text = String :: new ( ) ; } previous = current ; } if ! symbol . text . is_empty ( ) { log :: trace ! ( " " symbol text ) ; insert ( symbol ) ; } } }
Insert symbols for the frame into a multimap.
Insert symbols for the frame into a multimap .
&self
map
&mut BTreeMap<Symbol, Vec<usize>>
frame_number
usize