github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/util/collatedstring/collatedstring.go (about)

     1  // Copyright 2023 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package collatedstring
    12  
    13  import "golang.org/x/text/collate"
    14  
    15  // DefaultCollationTag is the "default" collation for strings.
    16  const DefaultCollationTag = "default"
    17  
    18  // CCollationTag is the "C" collation for strings. At the time of writing
    19  // this, it behaves the same os "default" since LC_COLLATE cannot be modified.
    20  const CCollationTag = "C"
    21  
    22  // PosixCollationTag is the "POSIX" collation for strings. At the time of
    23  // writing this, it behaves the same os "default" since LC_COLLATE cannot be
    24  // modified.
    25  const PosixCollationTag = "POSIX"
    26  
    27  var supportedTagNames []string
    28  
    29  func IsDefaultEquivalentCollation(s string) bool {
    30  	return s == DefaultCollationTag || s == CCollationTag || s == PosixCollationTag
    31  }
    32  
    33  // Supported returns a list of all the collation names that are supported.
    34  func Supported() []string {
    35  	return supportedTagNames
    36  }
    37  
    38  func init() {
    39  	if collate.CLDRVersion != "23" {
    40  		panic("This binary was built with an incompatible version of golang.org/x/text. " +
    41  			"See https://github.com/cockroachdb/cockroachdb-parser/issues/63738 for details")
    42  	}
    43  
    44  	supportedTagNames = []string{
    45  		DefaultCollationTag,
    46  		CCollationTag,
    47  		PosixCollationTag,
    48  	}
    49  	for _, t := range collate.Supported() {
    50  		supportedTagNames = append(supportedTagNames, t.String())
    51  	}
    52  }