Files
gluetun/internal/updater/providers/torguard/filename.go
Quentin McGaw 4bde50fb3a chore(all): use casers instead of strings.Title
- Add `golang.org/x/text` dependency
- Update code to use `cases.Title(language.English)`
2022-05-27 16:29:41 +00:00

36 lines
715 B
Go

package torguard
import (
"strings"
"golang.org/x/text/cases"
)
func parseFilename(fileName string, titleCaser cases.Caser) (country, city string) {
const prefix = "TorGuard."
const suffix = ".ovpn"
s := strings.TrimPrefix(fileName, prefix)
s = strings.TrimSuffix(s, suffix)
switch {
case strings.Count(s, ".") == 1 && !strings.HasPrefix(s, "USA"):
parts := strings.Split(s, ".")
country = parts[0]
city = parts[1]
case strings.HasPrefix(s, "USA"):
country = "USA"
s = strings.TrimPrefix(s, "USA-")
s = strings.ReplaceAll(s, "-", " ")
s = strings.ReplaceAll(s, ".", " ")
s = strings.ToLower(s)
s = titleCaser.String(s)
city = s
default:
country = s
}
return country, city
}