normalizeSpace trims leading and trailing whitespace from s and converts inner sequences of one or more whitespace characters to single spaces.
(s string)
| 144 | // normalizeSpace trims leading and trailing whitespace from s and converts |
| 145 | // inner sequences of one or more whitespace characters to single spaces. |
| 146 | func 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 | |
| 160 | func isRFC5332Space(c byte) bool { |
| 161 | switch c { |
no test coverage detected