summaryrefslogtreecommitdiff
path: root/internal/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/utils.go')
-rw-r--r--internal/utils.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/internal/utils.go b/internal/utils.go
index 779b95a..c135f9b 100644
--- a/internal/utils.go
+++ b/internal/utils.go
@@ -4,6 +4,7 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
+ "strings"
"time"
)
@@ -22,17 +23,19 @@ func GenerateCardID(bulgarianWord string) string {
return fmt.Sprintf("%d_%s", epochMillis, hashStr)
}
-// SanitizeFilename creates a safe filename from a string
+// SanitizeFilename creates a safe filename from a string.
+// Uses strings.Builder to avoid per-rune heap allocations.
func SanitizeFilename(s string) string {
- result := ""
+ var b strings.Builder
+ b.Grow(len(s))
for _, r := range s {
if isAlphaNumeric(r) || r == '-' || r == '_' {
- result += string(r)
+ b.WriteRune(r)
} else {
- result += "_"
+ b.WriteByte('_')
}
}
- return result
+ return b.String()
}
// isAlphaNumeric checks if a rune is alphanumeric