2023-09-07 23:53:51 +03:00
|
|
|
package main
|
|
|
|
|
2023-09-11 19:27:54 +03:00
|
|
|
import (
|
2023-09-14 18:25:27 +03:00
|
|
|
"strings"
|
2023-09-11 19:27:54 +03:00
|
|
|
)
|
|
|
|
|
2023-09-14 18:25:27 +03:00
|
|
|
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
|
|
|
|
}
|
2023-09-14 22:58:39 +03:00
|
|
|
|
|
|
|
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]
|
|
|
|
}
|