mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Accept LC_CTYPE without country/language codes (fixes #103)
This commit is contained in:
@@ -4,14 +4,29 @@ import "strings"
|
||||
|
||||
var usAscii = "US-ASCII"
|
||||
|
||||
func GetLocaleCharset(env map[string]string) string {
|
||||
locale := FirstNonBlank(env["LC_ALL"], env["LC_CTYPE"], env["LANG"])
|
||||
func extractCharset(locale, defaultCharset string) string {
|
||||
parts := strings.Split(locale, ".")
|
||||
|
||||
if len(parts) == 2 {
|
||||
return parts[1]
|
||||
}
|
||||
|
||||
return defaultCharset
|
||||
}
|
||||
|
||||
func GetLocaleCharset(env map[string]string) string {
|
||||
if env["LC_ALL"] != "" {
|
||||
return extractCharset(env["LC_ALL"], usAscii)
|
||||
}
|
||||
|
||||
if env["LC_CTYPE"] != "" {
|
||||
return extractCharset(env["LC_CTYPE"], env["LC_CTYPE"])
|
||||
}
|
||||
|
||||
if env["LANG"] != "" {
|
||||
return extractCharset(env["LANG"], usAscii)
|
||||
}
|
||||
|
||||
return usAscii
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestGetLocaleCharset(t *testing.T) {
|
||||
{"", "", "pl_PL.ISO-8859-2", "ISO-8859-2"},
|
||||
{"", "", "", "US-ASCII"},
|
||||
{"UTF-8", "pl_PL.ISO-8859-1", "pl_PL.ISO-8859-2", "US-ASCII"},
|
||||
{"", "ISO-8859-1", "pl_PL.ISO-8859-2", "US-ASCII"},
|
||||
{"", "ISO-8859-1", "pl_PL.ISO-8859-2", "ISO-8859-1"},
|
||||
{"", "", "ISO-8859-2", "US-ASCII"},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user