MCPcopy Create free account
hub / github.com/antonmedv/gitmal / normalizeSpace

Function normalizeSpace

pkg/gitdiff/patch_identity.go:146–158  ·  view source on GitHub ↗

normalizeSpace trims leading and trailing whitespace from s and converts inner sequences of one or more whitespace characters to single spaces.

(s string)

Source from the content-addressed store, hash-verified

144// normalizeSpace trims leading and trailing whitespace from s and converts
145// inner sequences of one or more whitespace characters to single spaces.
146func normalizeSpace(s string) string {
147 var sb strings.Builder
148 for i := 0; i < len(s); i++ {
149 c := s[i]
150 if !isRFC5332Space(c) {
151 if sb.Len() > 0 && isRFC5332Space(s[i-1]) {
152 sb.WriteByte(' ')
153 }
154 sb.WriteByte(c)
155 }
156 }
157 return sb.String()
158}
159
160func isRFC5332Space(c byte) bool {
161 switch c {

Callers 1

ParsePatchIdentityFunction · 0.85

Calls 3

isRFC5332SpaceFunction · 0.85
WriteByteMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected