Files
asciinema/util/locale.go

37 lines
695 B
Go
Raw Permalink Normal View History

2015-01-26 21:33:22 +01:00
package util
import "strings"
2015-01-26 21:33:22 +01:00
2015-02-07 14:03:59 +01:00
var usAscii = "US-ASCII"
2015-01-26 21:33:22 +01:00
func extractCharset(locale, defaultCharset string) string {
2015-03-05 16:40:52 +01:00
parts := strings.Split(locale, ".")
2015-01-26 21:33:22 +01:00
2015-03-05 16:40:52 +01:00
if len(parts) == 2 {
return parts[1]
2015-01-26 21:33:22 +01:00
}
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)
}
2015-02-07 14:03:59 +01:00
return usAscii
}
2015-01-26 21:33:22 +01:00
func IsUtf8Locale(env map[string]string) bool {
charset := GetLocaleCharset(env)
return charset == "utf-8" || charset == "UTF-8" || charset == "utf8"
2015-01-26 21:33:22 +01:00
}