github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/cstr.go (about)

     1  // Copyright 2021 Matrix Origin
     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 tree
    16  
    17  import (
    18  	"strings"
    19  )
    20  
    21  type CStrParts [4]*CStr
    22  type CStr struct {
    23  	o string
    24  	c string
    25  	// quote bool
    26  }
    27  
    28  func NewCStr(str string, lower int64) *CStr {
    29  	cs := &CStr{o: str}
    30  	if lower == 0 {
    31  		cs.c = cs.o
    32  		return cs
    33  	}
    34  	cs.c = strings.ToLower(cs.o)
    35  	return cs
    36  }
    37  
    38  func (cs *CStr) SetConfig(lower int64) {
    39  	if lower == 0 {
    40  		cs.c = cs.o
    41  		return
    42  	}
    43  	cs.c = strings.ToLower(cs.o)
    44  }
    45  
    46  func (cs *CStr) ToLower() string {
    47  	return strings.ToLower(cs.o)
    48  }
    49  
    50  func (cs *CStr) Origin() string {
    51  	return cs.o
    52  }
    53  
    54  func (cs *CStr) Compare() string {
    55  	return cs.c
    56  }
    57  
    58  func (cs *CStr) Empty() bool {
    59  	return len(cs.o) == 0
    60  }
    61  
    62  func NewCStrUseOrigin(str string, useOrigin int64) *CStr {
    63  	cs := &CStr{o: str}
    64  	if useOrigin == 1 {
    65  		cs.c = cs.o
    66  		return cs
    67  	}
    68  	cs.c = strings.ToLower(cs.o)
    69  	return cs
    70  }