You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fx/utils.go

55 lines
889 B
Go

package main
import (
"strings"
)
func isHexDigit(ch byte) bool {
return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')
}
func isDigit(ch byte) bool {
return ch >= '0' && ch <= '9'
}
func max(i, j int) int {
if i > j {
return i
}
return j
}
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]
}