Refactor string utilities into its own package str

This commit is contained in:
Deluan 2024-06-05 22:09:27 -04:00
parent 46fc38bf61
commit abe5690018
16 changed files with 158 additions and 125 deletions

View file

@ -8,7 +8,7 @@ import (
"strings"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/utils"
"github.com/navidrome/navidrome/utils/str"
)
type Line struct {
@ -36,7 +36,7 @@ var (
)
func ToLyrics(language, text string) (*Lyrics, error) {
text = utils.SanitizeText(text)
text = str.SanitizeText(text)
lines := strings.Split(text, "\n")
@ -67,7 +67,7 @@ func ToLyrics(language, text string) (*Lyrics, error) {
if idTag != nil {
switch idTag[1] {
case "ar":
artist = utils.SanitizeText(strings.TrimSpace(idTag[2]))
artist = str.SanitizeText(strings.TrimSpace(idTag[2]))
case "offset":
{
off, err := strconv.ParseInt(strings.TrimSpace(idTag[2]), 10, 64)
@ -78,7 +78,7 @@ func ToLyrics(language, text string) (*Lyrics, error) {
}
}
case "ti":
title = utils.SanitizeText(strings.TrimSpace(idTag[2]))
title = str.SanitizeText(strings.TrimSpace(idTag[2]))
}
continue

View file

@ -12,8 +12,8 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/utils"
"github.com/navidrome/navidrome/utils/slice"
"github.com/navidrome/navidrome/utils/str"
)
type MediaFile struct {
@ -187,7 +187,7 @@ func (mfs MediaFiles) ToAlbum() Album {
a.Genre = slice.MostFrequent(a.Genres).Name
slices.SortFunc(a.Genres, func(a, b Genre) int { return cmp.Compare(a.ID, b.ID) })
a.Genres = slices.Compact(a.Genres)
a.FullText = " " + utils.SanitizeStrings(fullText...)
a.FullText = " " + str.SanitizeStrings(fullText...)
a = fixAlbumArtist(a, albumArtistIds)
songArtistIds = append(songArtistIds, a.AlbumArtistID, a.ArtistID)
slices.Sort(songArtistIds)