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

38 lines
701 B
Go

10 months ago
package main
9 months ago
import (
"regexp"
9 months ago
"strings"
9 months ago
)
var identifier = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
10 months ago
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'
}
10 months ago
9 months ago
func max(i, j int) int {
if i > j {
return i
}
return j
}
9 months ago
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
}