mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-01-23 21:28:15 -05:00
25 lines
522 B
Go
25 lines
522 B
Go
|
package util
|
||
|
|
||
|
import (
|
||
|
"regexp"
|
||
|
"strings"
|
||
|
"unicode"
|
||
|
)
|
||
|
|
||
|
// CleanupWhitespace will trim up and remove extra lines and stuff
|
||
|
func CleanupWhitespace(s string) string {
|
||
|
// Remove trailing whitespace from all lines
|
||
|
slices := strings.Split(s, "\n")
|
||
|
for idx := range slices {
|
||
|
slices[idx] = strings.TrimRightFunc(slices[idx], unicode.IsSpace)
|
||
|
}
|
||
|
// Output: [a b c]
|
||
|
result := strings.Join(slices, "\n")
|
||
|
|
||
|
// Remove empty lines
|
||
|
r1 := regexp.MustCompile("\n+")
|
||
|
result = r1.ReplaceAllString(result, "\n")
|
||
|
|
||
|
return result
|
||
|
}
|