mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-15 20:17:50 +08:00
Add builtins has-{pre,suf}fix.
This commit is contained in:
parent
8b960a0315
commit
99f1c061f2
|
@ -63,6 +63,8 @@ func init() {
|
||||||
|
|
||||||
&BuiltinFn{"++", WrapFn(join)},
|
&BuiltinFn{"++", WrapFn(join)},
|
||||||
&BuiltinFn{"//", WrapFn(split)},
|
&BuiltinFn{"//", WrapFn(split)},
|
||||||
|
&BuiltinFn{"has-prefix", WrapFn(hasPrefix)},
|
||||||
|
&BuiltinFn{"has-suffix", WrapFn(hasSuffix)},
|
||||||
|
|
||||||
&BuiltinFn{"to-json", WrapFn(toJSON)},
|
&BuiltinFn{"to-json", WrapFn(toJSON)},
|
||||||
&BuiltinFn{"from-json", WrapFn(fromJSON)},
|
&BuiltinFn{"from-json", WrapFn(fromJSON)},
|
||||||
|
@ -390,6 +392,18 @@ func split(ec *EvalCtx, s, sep String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasPrefix(ec *EvalCtx, s, prefix String) {
|
||||||
|
if !strings.HasPrefix(string(s), string(prefix)) {
|
||||||
|
throw(ErrFalse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasSuffix(ec *EvalCtx, s, suffix String) {
|
||||||
|
if !strings.HasSuffix(string(s), string(suffix)) {
|
||||||
|
throw(ErrFalse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// toJSON converts a stream of Value's to JSON data.
|
// toJSON converts a stream of Value's to JSON data.
|
||||||
func toJSON(ec *EvalCtx, iterate func(func(Value))) {
|
func toJSON(ec *EvalCtx, iterate func(func(Value))) {
|
||||||
out := ec.ports[1].File
|
out := ec.ports[1].File
|
||||||
|
|
Loading…
Reference in New Issue
Block a user