mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Auth: Refactor cluster configuration and provisioning API endpoints #98
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
package clean
|
||||
|
||||
// ASCII removes all non-ascii characters from a string and returns it.
|
||||
// ASCII removes all non-ASCII bytes from a string.
|
||||
// Fast path: return the original string when it already contains only ASCII.
|
||||
func ASCII(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
result := make([]rune, 0, len(s))
|
||||
|
||||
for _, r := range s {
|
||||
if r <= 127 {
|
||||
result = append(result, r)
|
||||
// Fast path: all bytes < 128 → no allocation.
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] >= 0x80 { // non-ASCII
|
||||
// Slow path: filter into a new byte slice.
|
||||
dst := make([]byte, 0, len(s))
|
||||
for j := 0; j < len(s); j++ {
|
||||
b := s[j]
|
||||
if b < 0x80 {
|
||||
dst = append(dst, b)
|
||||
}
|
||||
}
|
||||
return string(dst)
|
||||
}
|
||||
}
|
||||
|
||||
return string(result)
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user