navidrome/utils/strings.go

34 lines
575 B
Go
Raw Normal View History

2016-02-29 13:56:09 -05:00
package utils
import (
2016-03-02 13:18:39 -05:00
"strings"
2016-03-24 09:51:50 -04:00
2017-04-01 09:47:14 -04:00
"github.com/cloudsonic/sonic-server/conf"
2016-02-29 13:56:09 -05:00
)
func NoArticle(name string) string {
2017-04-01 09:47:14 -04:00
articles := strings.Split(conf.Sonic.IgnoredArticles, " ")
2016-02-29 13:56:09 -05:00
for _, a := range articles {
2016-03-02 13:18:39 -05:00
n := strings.TrimPrefix(name, a+" ")
if n != name {
2016-02-29 13:56:09 -05:00
return n
}
}
return name
}
2016-03-24 09:51:50 -04:00
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]
}