tidb: github.com/pingcap/tidb/util/stringutil Index | Files

package stringutil

import "github.com/pingcap/tidb/util/stringutil"


Package Files



const (
    // PatMatch is the enumeration value for per-character match.
    PatMatch = iota + 1
    // PatOne is the enumeration value for '_' match.
    // PatAny is the enumeration value for '%' match.


var ErrSyntax = errors.New("invalid syntax")

ErrSyntax indicates that a value does not have the right syntax for the target type.

func CompileLike2Regexp Uses

func CompileLike2Regexp(str string) string

CompileLike2Regexp convert a like `lhs` to a regular expression

func CompilePattern Uses

func CompilePattern(pattern string, escape byte) (patChars, patTypes []byte)

CompilePattern handles escapes and wild cards convert pattern characters and pattern types.

func Copy Uses

func Copy(src string) string

Copy deep copies a string.

func DoMatch Uses

func DoMatch(str string, patChars, patTypes []byte) bool

DoMatch matches the string with patChars and patTypes. The algorithm has linear time complexity. https://research.swtch.com/glob

func Escape Uses

func Escape(str string, sqlMode mysql.SQLMode) string

Escape the identifier for pretty-printing. For instance, the identifier "foo `bar`" will become "`foo “bar“`". The sqlMode controls whether to escape with backquotes (`) or double quotes (`"`) depending on whether mysql.ModeANSIQuotes is enabled.

func IsExactMatch Uses

func IsExactMatch(patTypes []byte) bool

IsExactMatch return true if no wildcard character

func MemoizeStr Uses

func MemoizeStr(l func() string) fmt.Stringer

MemoizeStr returns memoized version of stringFunc.

func Unquote Uses

func Unquote(s string) (t string, err error)

Unquote interprets s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes. For example: test=`"\"\n"` (hex: 22 5c 22 5c 6e 22) should be converted to `"\n` (hex: 22 0a).

func UnquoteChar Uses

func UnquoteChar(s string, quote byte) (value []byte, tail string, err error)

UnquoteChar decodes the first character or byte in the escaped string or character literal represented by the string s. It returns four values:

1) value, the decoded Unicode code point or byte value; 2) multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation; 3) tail, the remainder of the string after the character; and 4) an error that will be nil if the character is syntactically valid.

The second argument, quote, specifies the type of literal being parsed and therefore which escaped quote character is permitted. If set to a single quote, it permits the sequence \' and disallows unescaped '. If set to a double quote, it permits \" and disallows unescaped ". If set to zero, it does not permit either escape and allows both quote characters to appear unescaped. Different with strconv.UnquoteChar, it permits unnecessary backslash.

type StringerFunc Uses

type StringerFunc func() string

StringerFunc defines string func implement fmt.Stringer.

func (StringerFunc) String Uses

func (l StringerFunc) String() string

String implements fmt.Stringer

type StringerStr Uses

type StringerStr string

StringerStr defines a alias to normal string. implement fmt.Stringer

func (StringerStr) String Uses

func (i StringerStr) String() string

String implements fmt.Stringer

Package stringutil imports 7 packages (graph) and is imported by 140 packages. Updated 2020-06-04. Refresh now. Tools for package owners.