mirror of
https://github.com/thegeeklab/drone-template-lib.git
synced 2024-11-16 09:50:39 +00:00
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:
parent
8efa917a1f
commit
be0e4a22ab
@ -100,14 +100,19 @@ 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 {
|
||||||
return url.QueryEscape(options.Fn())
|
return url.QueryEscape(options.Fn())
|
||||||
|
Loading…
Reference in New Issue
Block a user