diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 03:54:28 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 03:54:28 +0200 |
| commit | 93dfe3798e03e74766b229418cde364a5ef29ae9 (patch) | |
| tree | 4438058be9bee9a9b8682148a1f8417a530fac2f /internal/stats/stats.go | |
| parent | 8d9d903852a2cd28034e00e116a7bfcc14783108 (diff) | |
Replace custom stringsTrim with strings.TrimSpace
Remove duplicate stringsTrim implementations in stats and tmux packages,
replacing all call sites with the standard library strings.TrimSpace.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/stats/stats.go')
| -rw-r--r-- | internal/stats/stats.go | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/internal/stats/stats.go b/internal/stats/stats.go index 4b05617..939e1aa 100644 --- a/internal/stats/stats.go +++ b/internal/stats/stats.go @@ -13,6 +13,7 @@ import ( "os" "path/filepath" "strconv" + "strings" "sync/atomic" "time" ) @@ -264,7 +265,7 @@ func TakeSnapshot() (Snapshot, error) { // CacheDir resolves the cache directory for stats. func CacheDir() (string, error) { - if x := os.Getenv("XDG_CACHE_HOME"); stringsTrim(x) != "" { + if x := os.Getenv("XDG_CACHE_HOME"); strings.TrimSpace(x) != "" { return filepath.Join(x, "hexai"), nil } home, err := os.UserHomeDir() @@ -274,22 +275,6 @@ func CacheDir() (string, error) { return filepath.Join(home, ".local", "hexai", "cache"), nil } -// stringsTrim is a tiny helper to avoid importing strings everywhere here. -func stringsTrim(s string) string { - i := 0 - j := len(s) - for i < j && (s[i] == ' ' || s[i] == '\t' || s[i] == '\n' || s[i] == '\r') { - i++ - } - for j > i && (s[j-1] == ' ' || s[j-1] == '\t' || s[j-1] == '\n' || s[j-1] == '\r') { - j-- - } - if i == 0 && j == len(s) { - return s - } - return s[i:j] -} - // DebugString returns a compact single-line view of a snapshot (useful for logs). func (s Snapshot) DebugString() string { return "Σ reqs=" + strconv.FormatInt(s.Global.Reqs, 10) + " rpm=" + fmt.Sprintf("%.2f", s.RPM) |
