summaryrefslogtreecommitdiffstats
path: root/common/text/transform.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/text/transform.go')
-rw-r--r--common/text/transform.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/text/transform.go b/common/text/transform.go
index f59577803..66a67d8bc 100644
--- a/common/text/transform.go
+++ b/common/text/transform.go
@@ -14,6 +14,7 @@
package text
import (
+ "strings"
"sync"
"unicode"
@@ -45,3 +46,18 @@ func RemoveAccentsString(s string) string {
accentTransformerPool.Put(t)
return s
}
+
+// Chomp removes trailing newline characters from s.
+func Chomp(s string) string {
+ return strings.TrimRightFunc(s, func(r rune) bool {
+ return r == '\n' || r == '\r'
+ })
+}
+
+// Puts adds a trailing \n none found.
+func Puts(s string) string {
+ if s == "" || s[len(s)-1] == '\n' {
+ return s
+ }
+ return s + "\n"
+}