Added negative truncation to helper function

This allows you to grab a truncated portion of a string from the end.
This commit is contained in:
Dean Sofer 2018-04-25 13:56:44 -07:00 committed by Don
parent 8efa917a1f
commit be0e4a22ab

View File

@ -100,13 +100,18 @@ func isFailure(conditional bool, options *raymond.Options) string {
} }
func truncate(s string, len int) string { func truncate(s string, len int) string {
if utf8.RuneCountInString(s) <= len { if utf8.RuneCountInString(s) <= int(math.Abs(float64(len))) {
return s return s
} }
runes := []rune(s) runes := []rune(s)
if len < 0 {
len = -len
return string(runes[len:])
} else {
return string(runes[:len]) return string(runes[:len])
}
} }
func urlencode(options *raymond.Options) string { func urlencode(options *raymond.Options) string {