quintodrome/utils/strings.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.1 KiB
Go
Raw Normal View History

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/deluan/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
}
func StringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
2020-06-04 15:05:41 -08:00
func InsertString(array []string, value string, index int) []string {
return append(array[:index], append([]string{value}, array[index:]...)...)
}
func RemoveString(array []string, index int) []string {
return append(array[:index], array[index+1:]...)
}
func MoveString(array []string, srcIndex int, dstIndex int) []string {
value := array[srcIndex]
return InsertString(RemoveString(array, srcIndex), value, dstIndex)
}
2020-06-11 13:36:09 -08:00
func BreakUpStringSlice(mediaFileIds []string, chunkSize int) [][]string {
numTracks := len(mediaFileIds)
var chunks [][]string
for i := 0; i < numTracks; i += chunkSize {
end := i + chunkSize
if end > numTracks {
end = numTracks
}
chunks = append(chunks, mediaFileIds[i:end])
}
return chunks
}