photoprism/pkg/txt/numeric.go
Michael Mayer 6a452bcf43 Search: Add Filters for ISO, FNumber and Focal Length Range #3818
Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-10-12 14:53:40 +02:00

33 lines
474 B
Go

package txt
import (
"strings"
)
// Numeric removes non-numeric characters from a string and returns the result.
func Numeric(s string) string {
if s == "" {
return ""
}
sep := '.'
if c := strings.Count(s, "."); c == 0 || c > 1 {
sep = ','
}
// Remove invalid characters.
s = strings.Map(func(r rune) rune {
if r == sep {
return '.'
} else if r == '-' {
return '-'
} else if r < '0' || r > '9' {
return -1
}
return r
}, s)
return s
}