(re *Regexp, b []byte)
| 163 | } |
| 164 | |
| 165 | func grep(re *Regexp, b []byte) []int { |
| 166 | var m []int |
| 167 | lineno := 1 |
| 168 | for { |
| 169 | i := re.Match(b, true, true) |
| 170 | if i < 0 { |
| 171 | break |
| 172 | } |
| 173 | start := bytes.LastIndex(b[:i], nl) + 1 |
| 174 | end := i + 1 |
| 175 | if end > len(b) { |
| 176 | end = len(b) |
| 177 | } |
| 178 | lineno += bytes.Count(b[:start], nl) |
| 179 | m = append(m, lineno) |
| 180 | if start < end && b[end-1] == '\n' { |
| 181 | lineno++ |
| 182 | } |
| 183 | b = b[end:] |
| 184 | if len(b) == 0 { |
| 185 | break |
| 186 | } |
| 187 | } |
| 188 | return m |
| 189 | } |
| 190 | |
| 191 | var grepTests = []struct { |
| 192 | re string |