1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 19:56:16 +00:00
mycorrhiza/util/util.go

50 lines
871 B
Go
Raw Normal View History

package util
import (
"strings"
"unicode"
)
2020-07-03 19:20:56 +00:00
func addColonPerhaps(name string) string {
if strings.HasPrefix(name, ":") {
return name
}
return ":" + name
}
func removeColonPerhaps(name string) string {
if strings.HasPrefix(name, ":") {
return name[1:]
}
return name
}
func UrlToCanonical(name string) string {
2020-07-03 19:20:56 +00:00
return removeColonPerhaps(
strings.ToLower(strings.ReplaceAll(name, " ", "_")))
}
func DisplayToCanonical(name string) string {
2020-07-03 19:20:56 +00:00
return removeColonPerhaps(
strings.ToLower(strings.ReplaceAll(name, " ", "_")))
}
func CanonicalToDisplay(name string) (res string) {
tmp := strings.Title(name)
var afterPoint bool
for _, ch := range tmp {
if afterPoint {
afterPoint = false
ch = unicode.ToLower(ch)
}
switch ch {
case '.':
afterPoint = true
case '_':
ch = ' '
}
res += string(ch)
}
2020-07-03 19:20:56 +00:00
return addColonPerhaps(res)
}