EncodeLocaleName writes the locale identifier in s to buf. Any dash characters are mapped to underscore characters. Underscore characters do not need to be quoted, and they are considered equivalent to dash characters by the CLDR standard: http://cldr.unicode.org/.
(buf *bytes.Buffer, s string)
| 43 | // need to be quoted, and they are considered equivalent to dash characters by |
| 44 | // the CLDR standard: http://cldr.unicode.org/. |
| 45 | func EncodeLocaleName(buf *bytes.Buffer, s string) { |
| 46 | // If possible, try to normalize the case of the locale name (only for non-default |
| 47 | // locales). Default locales will always be quoted so they can be parsed correctly. |
| 48 | isDefaultLocale := collatedstring.IsDefaultEquivalentCollation(s) |
| 49 | if isDefaultLocale { |
| 50 | s = fmt.Sprintf("%q", s) |
| 51 | } else if normalized, err := language.Parse(s); err == nil { |
| 52 | s = normalized.String() |
| 53 | } |
| 54 | for i, n := 0, len(s); i < n; i++ { |
| 55 | ch := s[i] |
| 56 | if ch == '-' { |
| 57 | buf.WriteByte('_') |
| 58 | } else { |
| 59 | buf.WriteByte(ch) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // LocaleNamesAreEqual checks for equality of two locale names. The comparison |
| 65 | // is case-insensitive and treats '-' and '_' as the same. |
no test coverage detected
searching dependent graphs…