2016-02-29 09:56:09 -09:00
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
2016-03-02 09:18:39 -09:00
|
|
|
"strings"
|
2016-03-24 05:51:50 -08:00
|
|
|
|
2020-01-23 15:44:08 -09:00
|
|
|
"github.com/navidrome/navidrome/conf"
|
2016-02-29 09:56:09 -09:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func NoArticle(name string) string {
|
2020-01-23 21:29:31 -09:00
|
|
|
articles := strings.Split(conf.Server.IgnoredArticles, " ")
|
2016-02-29 09:56:09 -09:00
|
|
|
for _, a := range articles {
|
2016-03-02 09:18:39 -09:00
|
|
|
n := strings.TrimPrefix(name, a+" ")
|
|
|
|
|
if n != name {
|
2016-02-29 09:56:09 -09:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return name
|
|
|
|
|
}
|
2020-03-28 15:22:55 -08:00
|
|
|
|
2021-07-15 15:53:40 -08:00
|
|
|
func StringInSlice(a string, slice []string) bool {
|
|
|
|
|
for _, b := range slice {
|
2020-03-28 15:22:55 -08:00
|
|
|
if b == a {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2020-06-04 15:05:41 -08:00
|
|
|
|
2021-07-15 15:53:40 -08:00
|
|
|
func InsertString(slice []string, value string, index int) []string {
|
|
|
|
|
return append(slice[:index], append([]string{value}, slice[index:]...)...)
|
2020-06-04 15:05:41 -08:00
|
|
|
}
|
|
|
|
|
|
2021-07-15 15:53:40 -08:00
|
|
|
func RemoveString(slice []string, index int) []string {
|
|
|
|
|
return append(slice[:index], slice[index+1:]...)
|
2020-06-04 15:05:41 -08:00
|
|
|
}
|
|
|
|
|
|
2021-07-15 15:53:40 -08:00
|
|
|
func MoveString(slice []string, srcIndex int, dstIndex int) []string {
|
|
|
|
|
value := slice[srcIndex]
|
|
|
|
|
return InsertString(RemoveString(slice, srcIndex), value, dstIndex)
|
2020-06-04 15:05:41 -08:00
|
|
|
}
|
2020-06-11 13:36:09 -08:00
|
|
|
|
2020-09-09 04:57:59 -08:00
|
|
|
func BreakUpStringSlice(items []string, chunkSize int) [][]string {
|
|
|
|
|
numTracks := len(items)
|
2020-06-11 13:36:09 -08:00
|
|
|
var chunks [][]string
|
|
|
|
|
for i := 0; i < numTracks; i += chunkSize {
|
|
|
|
|
end := i + chunkSize
|
|
|
|
|
if end > numTracks {
|
|
|
|
|
end = numTracks
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-09 04:57:59 -08:00
|
|
|
chunks = append(chunks, items[i:end])
|
2020-06-11 13:36:09 -08:00
|
|
|
}
|
|
|
|
|
return chunks
|
|
|
|
|
}
|
2020-07-17 06:27:30 -08: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]
|
|
|
|
|
}
|