github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/soliton/collate/bin.go (about) 1 // Copyright 2020 WHTCORPS INC, 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 defCauslate 15 16 import ( 17 "strings" 18 19 "github.com/whtcorpsinc/milevadb/soliton/stringutil" 20 ) 21 22 type binDefCauslator struct { 23 } 24 25 // Compare implement DefCauslator interface. 26 func (bc *binDefCauslator) Compare(a, b string) int { 27 return strings.Compare(a, b) 28 } 29 30 // Key implement DefCauslator interface. 31 func (bc *binDefCauslator) Key(str string) []byte { 32 return []byte(str) 33 } 34 35 // Pattern implements DefCauslator interface. 36 func (bc *binDefCauslator) Pattern() WildcardPattern { 37 return &binPattern{} 38 } 39 40 type binPaddingDefCauslator struct { 41 } 42 43 func (bpc *binPaddingDefCauslator) Compare(a, b string) int { 44 return strings.Compare(truncateTailingSpace(a), truncateTailingSpace(b)) 45 } 46 47 func (bpc *binPaddingDefCauslator) Key(str string) []byte { 48 return []byte(truncateTailingSpace(str)) 49 } 50 51 // Pattern implements DefCauslator interface. 52 // Notice that trailing spaces are significant. 53 func (bpc *binPaddingDefCauslator) Pattern() WildcardPattern { 54 return &binPattern{} 55 } 56 57 type binPattern struct { 58 patChars []byte 59 patTypes []byte 60 } 61 62 // Compile implements WildcardPattern interface. 63 func (p *binPattern) Compile(patternStr string, escape byte) { 64 p.patChars, p.patTypes = stringutil.CompilePattern(patternStr, escape) 65 } 66 67 // Compile implements WildcardPattern interface. 68 func (p *binPattern) DoMatch(str string) bool { 69 return stringutil.DoMatch(str, p.patChars, p.patTypes) 70 }