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

Method Overlap

pos.go:222–249  ·  view source on GitHub ↗

Overlap finds a range that is either identical to or a sub-range of both the receiver and the other given range. It returns an empty range within the receiver if there is no overlap between the two ranges. A non-empty result is either identical to or a subset of the receiver.

(other Range)

Source from the content-addressed store, hash-verified

220//
221// A non-empty result is either identical to or a subset of the receiver.
222func (r Range) Overlap(other Range) Range {
223 if !r.Overlaps(other) {
224 // Start == End indicates an empty range
225 return Range{
226 Filename: r.Filename,
227 Start: r.Start,
228 End: r.Start,
229 }
230 }
231
232 var start, end Pos
233 if r.Start.Byte > other.Start.Byte {
234 start = r.Start
235 } else {
236 start = other.Start
237 }
238 if r.End.Byte < other.End.Byte {
239 end = r.End
240 } else {
241 end = other.End
242 }
243
244 return Range{
245 Filename: r.Filename,
246 Start: start,
247 End: end,
248 }
249}
250
251// PartitionAround finds the portion of the given range that overlaps with
252// the reciever and returns three ranges: the portion of the reciever that

Callers 2

PartitionAroundMethod · 0.95
TestPosOverlapFunction · 0.80

Calls 1

OverlapsMethod · 0.95

Tested by 1

TestPosOverlapFunction · 0.64