mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-16 12:58:48 +08:00
Add an experimental -match builtin.
This commit is contained in:
parent
344fddfb83
commit
8556834802
|
@ -86,6 +86,9 @@ func init() {
|
|||
&BuiltinFn{"has-prefix", WrapFn(hasPrefix)},
|
||||
&BuiltinFn{"has-suffix", WrapFn(hasSuffix)},
|
||||
|
||||
// Regular expression
|
||||
&BuiltinFn{"-match", WrapFn(match)},
|
||||
|
||||
// String comparison
|
||||
&BuiltinFn{"<s",
|
||||
wrapStrCompare(func(a, b string) bool { return a < b })},
|
||||
|
@ -576,6 +579,12 @@ func hasSuffix(ec *EvalCtx, s, suffix String) {
|
|||
ec.OutputChan() <- Bool(strings.HasSuffix(string(s), string(suffix)))
|
||||
}
|
||||
|
||||
func match(ec *EvalCtx, p, s String) {
|
||||
matched, err := regexp.MatchString(string(p), string(s))
|
||||
maybeThrow(err)
|
||||
ec.OutputChan() <- Bool(matched)
|
||||
}
|
||||
|
||||
// toJSON converts a stream of Value's to JSON data.
|
||||
func toJSON(ec *EvalCtx, iterate func(func(Value))) {
|
||||
out := ec.ports[1].File
|
||||
|
|
Loading…
Reference in New Issue
Block a user