File: trim.go

package info (click to toggle)
golang-github-andreyvit-diff 0.0~git20170406.c7f18ee-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 72 kB
  • sloc: makefile: 2
file content (19 lines) | stat: -rw-r--r-- 555 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package diff

import (
	"strings"
)

// TrimLines applies TrimSpace to each string in the given array.
func TrimLines(input []string) []string {
	result := make([]string, 0, len(input))
	for _, el := range input {
		result = append(result, strings.TrimSpace(el))
	}
	return result
}

// TrimLinesInString applies TrimSpace to each line in the given string, and returns the new trimmed string. Empty lines are not removed.
func TrimLinesInString(input string) string {
	return strings.Join(TrimLines(strings.Split(strings.TrimSpace(input), "\n")), "\n")
}