Adds the given state to the DFA. This allocates room for transitions out of this state in self.cache.trans. The transitions can be set with the returned StatePtr. If None is returned, then the state limit was reached and the DFA should quit.
(&mut self, state: State)
| 1500 | /// If None is returned, then the state limit was reached and the DFA |
| 1501 | /// should quit. |
| 1502 | fn add_state(&mut self, state: State) -> Option<StatePtr> { |
| 1503 | // This will fail if the next state pointer exceeds STATE_PTR. In |
| 1504 | // practice, the cache limit will prevent us from ever getting here, |
| 1505 | // but maybe callers will set the cache size to something ridiculous... |
| 1506 | let si = match self.cache.trans.add() { |
| 1507 | None => return None, |
| 1508 | Some(si) => si, |
| 1509 | }; |
| 1510 | // If the program has a Unicode word boundary, then set any transitions |
| 1511 | // for non-ASCII bytes to STATE_QUIT. If the DFA stumbles over such a |
| 1512 | // transition, then it will quit and an alternative matching engine |
| 1513 | // will take over. |
| 1514 | if self.prog.has_unicode_word_boundary { |
| 1515 | for b in 128..256 { |
| 1516 | let cls = self.byte_class(Byte::byte(b as u8)); |
| 1517 | self.cache.trans.set_next(si, cls, STATE_QUIT); |
| 1518 | } |
| 1519 | } |
| 1520 | // Finally, put our actual state on to our heap of states and index it |
| 1521 | // so we can find it later. |
| 1522 | self.cache.size += |
| 1523 | self.cache.trans.state_heap_size() |
| 1524 | + state.data.len() |
| 1525 | + (2 * mem::size_of::<State>()) |
| 1526 | + mem::size_of::<StatePtr>(); |
| 1527 | self.cache.compiled.insert(state, si); |
| 1528 | // Transition table and set of states and map should all be in sync. |
| 1529 | debug_assert!(self.cache.compiled.len() |
| 1530 | == self.cache.trans.num_states()); |
| 1531 | Some(si) |
| 1532 | } |
| 1533 | |
| 1534 | /// Quickly finds the next occurrence of any literal prefixes in the regex. |
| 1535 | /// If there are no literal prefixes, then the current position is |
no test coverage detected