1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-29 22:07:14 +02:00
ferret/pkg/stdlib/path/match.go

46 lines
958 B
Go
Raw Normal View History

package path
import (
"context"
"path"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
// Match reports whether name matches the pattern.
// @param pattern (String) - The pattern.
// @param name (String) - The name.
2020-07-10 07:30:50 +10:00
// @returns (Boolean) - True if the name matches the pattern.
func Match(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)
if err != nil {
return values.False, err
}
err = core.ValidateType(args[0], types.String)
if err != nil {
return values.False, err
}
err = core.ValidateType(args[1], types.String)
if err != nil {
return values.False, err
}
pattern := args[0].String()
name := args[1].String()
matched, err := path.Match(pattern, name)
if err != nil {
return values.False, core.Error(err, "match")
}
return values.NewBoolean(matched), nil
}