MCPcopy
hub / github.com/hashicorp/hcl / SliceBytes

Method SliceBytes

pos.go:179–196  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

177// a panic. Use CanSliceBytes to determine if the result is guaranteed to
178// be an accurate span of the requested range.
179func (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.

Callers 2

WriteDiagnosticMethod · 0.80
TestOutermostExprAtPosFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestOutermostExprAtPosFunction · 0.64