SliceBytes returns a sub-slice of the given slice that is covered by the receiving range, assuming that the given slice is the source code of the file indicated by r.Filename. If the receiver refers to any byte offsets that are outside of the slice then the result is constrained to the overlapping
(b []byte)
| 177 | // a panic. Use CanSliceBytes to determine if the result is guaranteed to |
| 178 | // be an accurate span of the requested range. |
| 179 | func (r Range) SliceBytes(b []byte) []byte { |
| 180 | start := r.Start.Byte |
| 181 | end := r.End.Byte |
| 182 | if start < 0 { |
| 183 | start = 0 |
| 184 | } else if start > len(b) { |
| 185 | start = len(b) |
| 186 | } |
| 187 | if end < 0 { |
| 188 | end = 0 |
| 189 | } else if end > len(b) { |
| 190 | end = len(b) |
| 191 | } |
| 192 | if end < start { |
| 193 | end = start |
| 194 | } |
| 195 | return b[start:end] |
| 196 | } |
| 197 | |
| 198 | // Overlaps returns true if the receiver and the other given range share any |
| 199 | // characters in common. |
no outgoing calls