- create centralized structured logger with rotation (https://github.com/versenilvis/IRIS/commit/96ad7c95ef0f7a9957b1bbf70bb6c8da3ce28b2e) - update core lookup and utils to use new logger (https://github.com/versenilvis/IRIS/commit/8b74b5a9cdc1828cff8c6d0bdaaccbe31da7a00a) - add log startup metadata and propagate reload flags (https://github.com/versenilvis/IRIS/commit/31208aa91a58e9e09abbf5497c314f5c961a58e2) - add log key interceptions and pty events (https://github.com/versenilvis/IRIS/commit/91ccb92835dd16ee70bf630fe0f267aad93c9db0) - add test for logger 221a40c893b75e6215787163cd751a4c1cb6c1d8 - secure reload arguments file path to prevent symlink attacks (https://github.com/versenilvis/IRIS/pull/13/commits/c3eabfda451230e52cb71f0c2a556687f839bd3f) - close log file on reinitialization to prevent descriptor leak (https://github.com/versenilvis/IRIS/pull/13/commits/a57d2c9be107a8c6200cf7046cc85b2f58667dce)
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package core
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// SplitAliasTokens parses the input string into shell-like tokens handling quotes
|
|
// example: SplitAliasTokens("git commit -m \"hello world\"")
|
|
func Tokenize(s string) []string {
|
|
tokens := []string{}
|
|
var current strings.Builder
|
|
inQuote := false
|
|
var quoteChar rune
|
|
|
|
escaped := false
|
|
for _, c := range s {
|
|
if escaped {
|
|
current.WriteRune(c)
|
|
escaped = false
|
|
continue
|
|
}
|
|
|
|
switch {
|
|
case c == '\\':
|
|
escaped = true
|
|
case !inQuote && (c == '"' || c == '\''):
|
|
inQuote = true
|
|
quoteChar = c
|
|
case inQuote && c == quoteChar:
|
|
inQuote = false
|
|
case c == ' ' && !inQuote:
|
|
if current.Len() > 0 {
|
|
tokens = append(tokens, current.String())
|
|
current.Reset()
|
|
}
|
|
default:
|
|
current.WriteRune(c)
|
|
}
|
|
}
|
|
|
|
tokens = append(tokens, current.String())
|
|
return tokens
|
|
}
|
|
|
|
// HasPrefix checks if s starts with prefix using case-insensitive matching
|
|
func HasPrefix(s, prefix string) bool {
|
|
if len(prefix) > len(s) {
|
|
return false
|
|
}
|
|
for i := 0; i < len(prefix); i++ {
|
|
a, b := s[i], prefix[i]
|
|
if a >= 'A' && a <= 'Z' {
|
|
a += 32
|
|
}
|
|
if b >= 'A' && b <= 'Z' {
|
|
b += 32
|
|
}
|
|
if a != b {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// CI = case insensitive
|
|
func HasPrefixCI(s, prefix string) bool {
|
|
return HasPrefix(s, prefix)
|
|
}
|