computeNext computes the next DFA state if we're in d reading c (an input byte or endText).
(d *dstate, c int)
| 208 | |
| 209 | // computeNext computes the next DFA state if we're in d reading c (an input byte or endText). |
| 210 | func (m *matcher) computeNext(d *dstate, c int) *dstate { |
| 211 | this, next := &m.z1, &m.z2 |
| 212 | this.dec(d.enc) |
| 213 | |
| 214 | // compute flags in effect before c |
| 215 | flag := syntax.EmptyOp(0) |
| 216 | if this.flag&flagBOL != 0 { |
| 217 | flag |= syntax.EmptyBeginLine |
| 218 | } |
| 219 | if this.flag&flagBOT != 0 { |
| 220 | flag |= syntax.EmptyBeginText |
| 221 | } |
| 222 | if this.flag&flagWord != 0 { |
| 223 | if !isWordByte(c) { |
| 224 | flag |= syntax.EmptyWordBoundary |
| 225 | } else { |
| 226 | flag |= syntax.EmptyNoWordBoundary |
| 227 | } |
| 228 | } else { |
| 229 | if isWordByte(c) { |
| 230 | flag |= syntax.EmptyWordBoundary |
| 231 | } else { |
| 232 | flag |= syntax.EmptyNoWordBoundary |
| 233 | } |
| 234 | } |
| 235 | if c == '\n' { |
| 236 | flag |= syntax.EmptyEndLine |
| 237 | } |
| 238 | if c == endText { |
| 239 | flag |= syntax.EmptyEndLine | syntax.EmptyEndText |
| 240 | } |
| 241 | |
| 242 | // re-expand queue using new flags. |
| 243 | // TODO: only do this when it matters |
| 244 | // (something is gating on word boundaries). |
| 245 | m.stepEmpty(&this.q, &next.q, flag) |
| 246 | this, next = next, this |
| 247 | |
| 248 | // now compute flags after c. |
| 249 | flag = 0 |
| 250 | next.flag = 0 |
| 251 | if c == '\n' { |
| 252 | flag |= syntax.EmptyBeginLine |
| 253 | next.flag |= flagBOL |
| 254 | } |
| 255 | if isWordByte(c) { |
| 256 | next.flag |= flagWord |
| 257 | } |
| 258 | |
| 259 | // re-add start, process rune + expand according to flags. |
| 260 | if m.stepByte(&this.q, &next.q, c, flag) { |
| 261 | return &dmatch |
| 262 | } |
| 263 | return m.cache(next) |
| 264 | } |
| 265 | |
| 266 | func (m *matcher) cache(z *nstate) *dstate { |
| 267 | enc := z.enc() |
no test coverage detected