MCPcopy
hub / github.com/micro-editor/micro / findLineParams

Function findLineParams

internal/buffer/search.go:20–62  ·  view source on GitHub ↗
(b *Buffer, start, end Loc, i int, r *regexp.Regexp)

Source from the content-addressed store, hash-verified

18)
19
20func findLineParams(b *Buffer, start, end Loc, i int, r *regexp.Regexp) ([]byte, int, int, *regexp.Regexp) {
21 l := b.LineBytes(i)
22 charpos := 0
23 padMode := 0
24
25 if i == end.Y {
26 nchars := util.CharacterCount(l)
27 end.X = util.Clamp(end.X, 0, nchars)
28 if end.X < nchars {
29 l = util.SliceStart(l, end.X+1)
30 padMode |= padEnd
31 }
32 }
33
34 if i == start.Y {
35 nchars := util.CharacterCount(l)
36 start.X = util.Clamp(start.X, 0, nchars)
37 if start.X > 0 {
38 charpos = start.X - 1
39 l = util.SliceEnd(l, charpos)
40 padMode |= padStart
41 }
42 }
43
44 if padMode != 0 {
45 re, err := regexp.Compile(r.String() + `\E`)
46 if err == nil {
47 // r contains \Q without closing \E
48 r = re
49 }
50
51 if padMode == padStart {
52 r = regexp.MustCompile(".(?:" + r.String() + ")")
53 } else if padMode == padEnd {
54 r = regexp.MustCompile("(?:" + r.String() + ").")
55 } else {
56 // padMode == padStart|padEnd
57 r = regexp.MustCompile(".(?:" + r.String() + ").")
58 }
59 }
60
61 return l, charpos, padMode, r
62}
63
64func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
65 lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))

Callers 1

findDownMethod · 0.85

Calls 6

CharacterCountFunction · 0.92
ClampFunction · 0.92
SliceStartFunction · 0.92
SliceEndFunction · 0.92
LineBytesMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected