github.com/pingcap/tidb/parser@v0.0.0-20231013125129-93a834a6bf8d/charset/encoding_latin1.go (about) 1 // Copyright 2021 PingCAP, 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package charset 15 16 import ( 17 "bytes" 18 19 "golang.org/x/text/encoding" 20 ) 21 22 // EncodingLatin1Impl is the instance of encodingLatin1. 23 // TiDB uses utf8 implementation for latin1 charset because of the backward compatibility. 24 var EncodingLatin1Impl = &encodingLatin1{encodingUTF8{encodingBase{enc: encoding.Nop}}} 25 26 func init() { 27 EncodingLatin1Impl.self = EncodingLatin1Impl 28 } 29 30 // encodingLatin1 compatibles with latin1 in old version TiDB. 31 type encodingLatin1 struct { 32 encodingUTF8 33 } 34 35 // Name implements Encoding interface. 36 func (*encodingLatin1) Name() string { 37 return CharsetLatin1 38 } 39 40 // Peek implements Encoding interface. 41 func (*encodingLatin1) Peek(src []byte) []byte { 42 if len(src) == 0 { 43 return src 44 } 45 return src[:1] 46 } 47 48 // IsValid implements Encoding interface. 49 func (*encodingLatin1) IsValid(_ []byte) bool { 50 return true 51 } 52 53 // Tp implements Encoding interface. 54 func (*encodingLatin1) Tp() EncodingTp { 55 return EncodingTpLatin1 56 } 57 58 func (*encodingLatin1) Transform(_ *bytes.Buffer, src []byte, _ Op) ([]byte, error) { 59 return src, nil 60 }