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

Function RangeOver

pos.go:77–101  ·  view source on GitHub ↗

RangeOver returns a new range that covers both of the given ranges and possibly additional content between them if the two ranges do not overlap. If either range is empty then it is ignored. The result is empty if both given ranges are empty. The result is meaningless if the two ranges to not belo

(a, b Range)

Source from the content-addressed store, hash-verified

75// The result is meaningless if the two ranges to not belong to the same
76// source file.
77func RangeOver(a, b Range) Range {
78 if a.Empty() {
79 return b
80 }
81 if b.Empty() {
82 return a
83 }
84
85 var start, end Pos
86 if a.Start.Byte < b.Start.Byte {
87 start = a.Start
88 } else {
89 start = b.Start
90 }
91 if a.End.Byte > b.End.Byte {
92 end = a.End
93 } else {
94 end = b.End
95 }
96 return Range{
97 Filename: a.Filename,
98 Start: start,
99 End: end,
100 }
101}
102
103// ContainsPos returns true if and only if the given position is contained within
104// the receiving range.

Callers 2

TestRangeOverFunction · 0.85
WriteDiagnosticMethod · 0.85

Calls 1

EmptyMethod · 0.80

Tested by 1

TestRangeOverFunction · 0.68