Files
iris-context/commands/core/utils.go
T
VERSE bf67e50ea6 Feat: crash log (#7)
Merged #6
- crash log (db0e1be9a02f70927124f9f3563df5e9dee3a764)
- perf(watchdog): limit buffer size and optimize crash substring search (https://github.com/versenilvis/IRIS/pull/7/commits/7725434fedf8b32929dc0d71e1256fda13cfdfca)
- refactor(crash): use dynamic buffer for stack trace capture (https://github.com/versenilvis/IRIS/pull/7/commits/07809a4330a1236471e8dae0e83afd4323a4c83a)
2026-05-23 23:32:36 +07:00

79 lines
1.4 KiB
Go

package core
import (
"fmt"
"io"
"strings"
)
var DebugWriter io.Writer
func debugLog(format string, a ...any) {
if DebugWriter != nil {
_, _ = fmt.Fprintf(DebugWriter, format+"\n", a...)
}
}
// 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)
}