mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
* Make sort by order_* fields case-insensitive. * Sort internet radios by name case-insensitive
45 lines
916 B
Go
45 lines
916 B
Go
package utils
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/deluan/sanitize"
|
|
"github.com/navidrome/navidrome/conf"
|
|
)
|
|
|
|
func NoArticle(name string) string {
|
|
articles := strings.Split(conf.Server.IgnoredArticles, " ")
|
|
for _, a := range articles {
|
|
n := strings.TrimPrefix(name, a+" ")
|
|
if n != name {
|
|
return n
|
|
}
|
|
}
|
|
return name
|
|
}
|
|
|
|
func LongestCommonPrefix(list []string) string {
|
|
if len(list) == 0 {
|
|
return ""
|
|
}
|
|
|
|
for l := 0; l < len(list[0]); l++ {
|
|
c := list[0][l]
|
|
for i := 1; i < len(list); i++ {
|
|
if l >= len(list[i]) || list[i][l] != c {
|
|
return list[i][0:l]
|
|
}
|
|
}
|
|
}
|
|
return list[0]
|
|
}
|
|
|
|
func SanitizeFieldForSorting(originalValue string) string {
|
|
v := strings.TrimSpace(sanitize.Accents(originalValue))
|
|
return strings.ToLower(v)
|
|
}
|
|
|
|
func SanitizeFieldForSortingNoArticle(originalValue string) string {
|
|
v := strings.TrimSpace(sanitize.Accents(originalValue))
|
|
return strings.ToLower(NoArticle(v))
|
|
}
|