fx/utils.go
2024-03-21 20:48:09 +01:00

40 lines
638 B
Go

package main
import (
"strings"
)
func regexCase(code string) (string, bool) {
if strings.HasSuffix(code, "/i") {
return code[:len(code)-2], true
} else if strings.HasSuffix(code, "/") {
return code[:len(code)-1], false
} else {
return code, true
}
}
func flex(width int, a, b string) string {
return a + strings.Repeat(" ", max(1, width-len(a)-len(b))) + b
}
func safeSlice(b []byte, start, end int) []byte {
length := len(b)
if start > length {
start = length
}
if end > length {
end = length
}
if start < 0 {
start = 0
}
if end < 0 {
end = 0
}
if start > end {
start = end
}
return b[start:end]
}