fic: Replace accentuated letters by non-accentuated ones

This commit is contained in:
nemunaire 2021-09-03 17:43:59 +02:00
parent 5c12963da8
commit f2bc4b015f

View File

@ -9,6 +9,41 @@ import (
// ToURLid converts the given string to a valid URLid. // ToURLid converts the given string to a valid URLid.
func ToURLid(str string) string { func ToURLid(str string) string {
re_a := regexp.MustCompile("[áàâäā]")
str = re_a.ReplaceAllLiteralString(str, "a")
re_A := regexp.MustCompile("[ÀÁÂÄĀ]")
str = re_A.ReplaceAllLiteralString(str, "A")
re_e := regexp.MustCompile("[éèêëȩē]")
str = re_e.ReplaceAllLiteralString(str, "e")
re_E := regexp.MustCompile("[ÉÈÊËĒ]")
str = re_E.ReplaceAllLiteralString(str, "E")
re_i := regexp.MustCompile("[íìîïī]")
str = re_i.ReplaceAllLiteralString(str, "i")
re_I := regexp.MustCompile("[ÌÍÎÏĪ]")
str = re_I.ReplaceAllLiteralString(str, "I")
re_o := regexp.MustCompile("[òóôöō]")
str = re_o.ReplaceAllLiteralString(str, "o")
re_O := regexp.MustCompile("[ÒÓÔÖŌ]")
str = re_O.ReplaceAllLiteralString(str, "O")
re_oe := regexp.MustCompile("[œ]")
str = re_oe.ReplaceAllLiteralString(str, "oe")
re_OE := regexp.MustCompile("[Œ]")
str = re_OE.ReplaceAllLiteralString(str, "OE")
re_u := regexp.MustCompile("[ùúûüū]")
str = re_u.ReplaceAllLiteralString(str, "u")
re_U := regexp.MustCompile("[ÙÚÛÜŪ]")
str = re_U.ReplaceAllLiteralString(str, "U")
re_y := regexp.MustCompile("[ỳýŷÿȳ]")
str = re_y.ReplaceAllLiteralString(str, "y")
re_Y := regexp.MustCompile("[ỲÝŶŸȲ]")
str = re_Y.ReplaceAllLiteralString(str, "Y")
re := regexp.MustCompile("[^a-zA-Z0-9]+") re := regexp.MustCompile("[^a-zA-Z0-9]+")
return strings.TrimSuffix(re.ReplaceAllLiteralString(str, "-"), "-") return strings.TrimSuffix(re.ReplaceAllLiteralString(str, "-"), "-")
} }