Documentation ¶
Index ¶
- Constants
- Variables
- func BuildStringFromLabels(labels map[string]string) string
- func CompileLike2Regexp(str string) string
- func CompilePattern(pattern string, escape byte) (patWeights []rune, patTypes []byte)
- func CompilePatternBytes(pattern string, escape byte) (patChars, patTypes []byte)
- func CompilePatternInner(pattern string, escape byte) (patWeights []rune, patTypes []byte)
- func ConvertPosInUtf8(str *string, pos int64) int64
- func Copy(src string) string
- func DoMatch(str string, patChars []rune, patTypes []byte) bool
- func DoMatchBytes(str string, patChars, patTypes []byte) bool
- func DoMatchInner(str string, patWeights []rune, patTypes []byte, matcher func(a, b rune) bool) bool
- func Escape(str string, sqlMode mysql.SQLMode) string
- func EscapeGlobExceptAsterisk(s string) string
- func GetTailSpaceCount(str string) int64
- func IsExactMatch(patTypes []byte) bool
- func IsLowerASCII(c byte) bool
- func IsUpperASCII(c byte) bool
- func LowerOneString(str []byte)
- func LowerOneStringExcludeEscapeChar(str []byte, escapeChar byte) byte
- func MemoizeStr(l func() string) fmt.Stringer
- func TrimUtf8String(str *string, trimmedNum int64) int64
- func Unquote(s string) (t string, err error)
- func UnquoteChar(s string, quote byte) (value []byte, tail string, err error)
- func Utf8Len(b byte) int
- type StringerFunc
- type StringerStr
Constants ¶
const ( // PatMatch is the enumeration value for per-character match. PatMatch = iota + 1 // PatOne is the enumeration value for '_' match. PatOne // PatAny is the enumeration value for '%' match. PatAny )
Variables ¶
var ErrSyntax = errors.New("invalid syntax")
ErrSyntax indicates that a value does not have the right syntax for the target type.
Functions ¶
func BuildStringFromLabels ¶
BuildStringFromLabels construct config labels into string by following format: "keyA=valueA,keyB=valueB"
func CompileLike2Regexp ¶
CompileLike2Regexp convert a like `lhs` to a regular expression
func CompilePattern ¶
CompilePattern is a adapter for `CompilePatternInner`, `pattern` can be any unicode string.
func CompilePatternBytes ¶
CompilePatternBytes is a adapter for `CompilePatternInner`, `pattern` can only be an ascii string.
func CompilePatternInner ¶
CompilePatternInner handles escapes and wild cards convert pattern characters and pattern types.
func ConvertPosInUtf8 ¶
ConvertPosInUtf8 converts a binary index to the position which shows the occurrence location in the utf8 string Take "你好" as example:
binary index for "好" is 3, ConvertPosInUtf8("你好", 3) should return 2
func DoMatchBytes ¶
DoMatchBytes is a adapter for `DoMatchInner`, `str` can only be an ascii string.
func DoMatchInner ¶
func DoMatchInner(str string, patWeights []rune, patTypes []byte, matcher func(a, b rune) bool) bool
DoMatchInner matches the string with patChars and patTypes. The algorithm has linear time complexity. https://research.swtch.com/glob
func Escape ¶
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 EscapeGlobExceptAsterisk ¶
EscapeGlobExceptAsterisk escapes '?', '[', ']' for a glob path pattern.
func GetTailSpaceCount ¶
GetTailSpaceCount returns the number of tailed spaces.
func IsExactMatch ¶
IsExactMatch return true if no wildcard character
func LowerOneString ¶
func LowerOneString(str []byte)
LowerOneString lowers the ascii characters in a string
func LowerOneStringExcludeEscapeChar ¶
LowerOneStringExcludeEscapeChar lowers strings and exclude an escape char
When escape_char is a capital char, we shouldn't lower the escape char. For example, 'aaaa' ilike 'AAAA' escape 'A', we should convert 'AAAA' to 'AaAa'. If we do not exclude the escape char, 'AAAA' will be lowered to 'aaaa', and we can not get the correct result.
When escape_char is a lower char, we need to convert it to the capital char Because: when lowering "ABC" with escape 'a', after lower, "ABC" -> "abc", then 'a' will be an escape char and it is not expected. Morever, when escape char is uppered we need to tell it to the caller.
func MemoizeStr ¶
MemoizeStr returns memoized version of stringFunc.
func TrimUtf8String ¶
TrimUtf8String needs the string input should always be valid which means that it should always return true in utf8.ValidString(str)
func Unquote ¶
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 ¶
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.
Types ¶
type StringerFunc ¶
type StringerFunc func() string
StringerFunc defines string func implement fmt.Stringer.
type StringerStr ¶
type StringerStr string
StringerStr defines a alias to normal string. implement fmt.Stringer