github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/strutil/chop.go (about) 1 package strutil 2 3 // ChopLineEnding removes a line ending ("\r\n" or "\n") from the end of s. It 4 // returns itself if it doesn't end with a line ending. 5 func ChopLineEnding(s string) string { 6 if len(s) >= 2 && s[len(s)-2:] == "\r\n" { 7 return s[:len(s)-2] 8 } else if len(s) >= 1 && s[len(s)-1] == '\n' { 9 return s[:len(s)-1] 10 } 11 return s 12 }