mirror of
https://github.com/antonmedv/fx
synced 2024-11-11 07:10:28 +00:00
40 lines
638 B
Go
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]
|
|
}
|