Documentation
¶
Overview ¶
Package like implements functions used by LIKE operator. The expression is parsed into a list of subexpressions, which are '%' placeholder, '_' placeholder, rune set [...] and "substring". During execution, the tested string will be compared with the list subexpressions, recursively for '%' placeholder.
E.g. if LIKE EXPRESSION is '%hello ____[abc0-9]world', the result of the parsing is the following list of Likexp. Likexp LX_TYPE_ZERO_OR_MANY_CHARS for % placeholder Likexp LX_TYPE_STRING for "hello " Likexp LX_TYPE_N_CHARS for ____ (four _ placeholders) Likexp LX_TYPE_ONE_CHAR_IN_SET for [abc0-9] Likexp LX_TYPE_STRING for "world" If LIKE expression is empty string '', parsing result is a nil lxb_list in Likexp_bundle. In the same way as equality operator (=), both operands are trimmed for trailing spaces: 'hello' LIKE 'hello' is true 'hello ' LIKE 'hello ' is true 'hello ' LIKE 'hello ' is true Usage: - Parse_likexp() parses the LIKE expression, and returns a Likexp_bundle object, containing the "compiled" LIKE expression. - Match() determines whether string matches the LIKE expression.
Index ¶
Constants ¶
const ( NO_ESCAPE_RUNE rune = -1 // passed as ec argument in Parse_likexp(..., NO_ESCAPE_RUNE), to disable escape character SPEC_MAX_PERCENT_PLACEHOLDER_COUNT int = 5 // we want to limit the number of % because % tries every possible length for remaining substring, and this can take long. SPEC_MAX_LIKEXP_COUNT int = 30 // we want to avoid too complex LIKE expressions. )
const ( RESULT_END_OF_RUNE_SET restype_t = 0 RESULT_RUNE restype_t = 2 RESULT_RANGE restype_t = 4 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Likexp_bundle ¶
type Likexp_bundle struct {
// contains filtered or unexported fields
}
Likexp_bundle contains the parsing result of a LIKE expression.
func (*Likexp_bundle) Equal ¶
func (likexp_bundle_a *Likexp_bundle) Equal(likexp_bundle_b *Likexp_bundle) bool
func (*Likexp_bundle) Hash ¶
func (likexp_bundle *Likexp_bundle) Hash() uint32
func (*Likexp_bundle) Parse_likexp ¶
func (likexp_bundle *Likexp_bundle) Parse_likexp(s string, ec rune) (err error)
Parse_likexp is the main function that parses a LIKE expression s, and write the compiled result into the input variable likexp_bundle. ec is the escape character. If % _ [ ^ - is preceded by the escape character, it will be considered as a normal character. To disable ec, pass the constant like.NO_ESCAPE_RUNE. An error is returned if too many % placeholders, because it is usually a mistake to put too many of them.
func (*Likexp_bundle) String ¶
func (likexp_bundle *Likexp_bundle) String() string
type Lx_type_t ¶
type Lx_type_t int
Lx_type_t is the type of a Likexp element.
const ( LX_TYPE_STRING Lx_type_t = 1 << iota // literal string fragment LX_TYPE_N_CHARS // one or many underscore placeholders _ LX_TYPE_ONE_CHAR_IN_SET // rune set [ ] LX_TYPE_ONE_CHAR_NOT_IN_SET // rune set [^ ] LX_TYPE_ZERO_OR_MANY_CHARS // one or many % placeholders LX_TYPE_INVALID // error occurred during parsing, the whole LIKE expression must be considered as invalid )