MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeLocaleName

Function EncodeLocaleName

pkg/sql/lex/encode.go:45–62  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43// need to be quoted, and they are considered equivalent to dash characters by
44// the CLDR standard: http://cldr.unicode.org/.
45func 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.

Callers 6

collatedStringTypeSQLMethod · 0.92
FormatMethod · 0.92
FormatMethod · 0.92
FormatMethod · 0.92
FormatMethod · 0.92
NormalizeLocaleNameFunction · 0.85

Calls 3

ParseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…