-
Notifications
You must be signed in to change notification settings - Fork 25
/
addr.go
47 lines (38 loc) · 911 Bytes
/
addr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"github.com/as/text"
"github.com/as/text/find"
)
type q int64
func (a q) In(a1 Addr) bool { return text.Region3(int64(a), int64(a1.s-1), int64(a1.e)) == 0 }
type Addr struct {
s q
e q
}
type a = Addr
func d2a(q0, q1 int64) Addr { return Addr{q(q0), q(q1)} }
func (a Addr) Empty() bool { return a.s == a.e }
func (a Addr) Len() int { return int(a.e - a.s) }
func (a Addr) In(a1 Addr) bool {
if a.Empty() {
return a.e.In(a1)
}
return a.Len() <= a1.Len() && text.Region5(int64(a.s), int64(a.e), int64(a1.s), int64(a1.e)) == 0
}
func (a Addr) Dot() (q0, q1 int64) { return int64(a.s), int64(a.e) }
func expandAddr(a Addr, ed text.Editor) Addr {
if !a.Empty() {
return a
}
a0 := d2a(ed.Dot())
if a.In(a0) {
return a0
}
return a
}
func expandFile(a Addr, ed text.Editor) Addr {
if !a.Empty() {
return a
}
return d2a(find.ExpandFile(ed.Bytes(), int64(a.s)))
}