github.com/dolthub/go-mysql-server@v0.18.0/sql/encodings/binary.go (about)

     1  // Copyright 2022 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package encodings
    16  
    17  import "unicode/utf8"
    18  
    19  // binaryEncoder is the implementation of Binary. This returns whatever it is given.
    20  type binaryEncoder struct{}
    21  
    22  // Binary represents the `binary` character set encoding.
    23  var Binary Encoder = binaryEncoder{}
    24  
    25  // Decode implements the Encoder interface.
    26  func (binaryEncoder) Decode(str []byte) ([]byte, bool) {
    27  	return str, true
    28  }
    29  
    30  // Encode implements the Encoder interface.
    31  func (binaryEncoder) Encode(str []byte) ([]byte, bool) {
    32  	return str, true
    33  }
    34  
    35  // EncodeReplaceUnknown implements the Encoder interface.
    36  func (binaryEncoder) EncodeReplaceUnknown(str []byte) []byte {
    37  	return str
    38  }
    39  
    40  // DecodeRune implements the Encoder interface.
    41  func (binaryEncoder) DecodeRune(r []byte) ([]byte, bool) {
    42  	return r, true
    43  }
    44  
    45  // EncodeRune implements the Encoder interface.
    46  func (binaryEncoder) EncodeRune(r []byte) ([]byte, bool) {
    47  	return r, true
    48  }
    49  
    50  // Uppercase implements the Encoder interface.
    51  func (binaryEncoder) Uppercase(str string) string {
    52  	return str
    53  }
    54  
    55  // Lowercase implements the Encoder interface.
    56  func (binaryEncoder) Lowercase(str string) string {
    57  	return str
    58  }
    59  
    60  // UppercaseRune implements the Encoder interface.
    61  func (binaryEncoder) UppercaseRune(r rune) rune {
    62  	return r
    63  }
    64  
    65  // LowercaseRune implements the Encoder interface.
    66  func (binaryEncoder) LowercaseRune(r rune) rune {
    67  	return r
    68  }
    69  
    70  // NextRune implements the Encoder interface.
    71  func (binaryEncoder) NextRune(str string) (rune, int) {
    72  	if len(str) == 0 {
    73  		return utf8.RuneError, 0
    74  	}
    75  	return rune(str[0]), 1
    76  }
    77  
    78  // IsReturnSafe implements the Encoder interface. Since all functions return their input, they are not safe to freely
    79  // modify, and must be copied to preserve the original slice.
    80  func (binaryEncoder) IsReturnSafe() bool {
    81  	return false
    82  }
    83  
    84  // Binary_RuneWeight returns the weight of a given rune based on its relational sort order from
    85  // the `binary` collation.
    86  func Binary_RuneWeight(r rune) int32 {
    87  	return int32(r)
    88  }