MCPcopy
hub / github.com/valyala/quicktemplate / stripSpaceExt

Function stripSpaceExt

parser/util.go:37–72  ·  view source on GitHub ↗
(b []byte, isCollapse bool)

Source from the content-addressed store, hash-verified

35}
36
37func stripSpaceExt(b []byte, isCollapse bool) []byte {
38 if len(b) == 0 {
39 return b
40 }
41
42 var dst []byte
43 if isCollapse && isSpace(b[0]) {
44 dst = append(dst, ' ')
45 }
46 isLastSpace := isSpace(b[len(b)-1])
47 for len(b) > 0 {
48 n := bytes.IndexByte(b, '\n')
49 if n < 0 {
50 n = len(b)
51 }
52 z := b[:n]
53 if n == len(b) {
54 b = b[n:]
55 } else {
56 b = b[n+1:]
57 }
58 z = stripLeadingSpace(z)
59 z = stripTrailingSpace(z)
60 if len(z) == 0 {
61 continue
62 }
63 dst = append(dst, z...)
64 if isCollapse {
65 dst = append(dst, ' ')
66 }
67 }
68 if isCollapse && !isLastSpace && len(dst) > 0 {
69 dst = dst[:len(dst)-1]
70 }
71 return dst
72}
73
74func isSpace(c byte) bool {
75 return unicode.IsSpace(rune(c))

Callers 2

collapseSpaceFunction · 0.85
stripSpaceFunction · 0.85

Calls 3

isSpaceFunction · 0.85
stripLeadingSpaceFunction · 0.85
stripTrailingSpaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…