Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const (
- x_y int8 = iota
- x_star
- star_y
- star_star
- )
- type cell func([]string, []string)bool
- func matchXY(a, b []string) bool {
- return a[0] == b[0] && a[1] == b[1]
- }
- func matchX(a, b []string) bool {
- return a[0] == b[0]
- }
- func matchY(a, b []string) bool {
- return a[1] == b[1]
- }
- func yes(a, b []string) bool {
- return true
- }
- func no(a, b []string) bool {
- return false
- }
- var (
- rules [4][4]cell = [4][4]cell {
- [4]cell{matchXY, matchX, matchY, yes},
- [4]cell{matchX, matchX, no, yes},
- [4]cell{matchY, no, matchY, yes},
- [4]cell{yes, yes, yes, yes},
- }
- )
- func kind(in []string)int8 {
- switch {
- case in[0] == "*" && in[1] == "*" : return star_star
- case in[0] == "*" : return star_y
- case in[1] == "*" : return x_star
- default : return x_y
- }
- return x_y
- }
- func match(required, provided string) (ok bool) {
- reqParts, provParts := strings.Split(required, "/"), strings.Split(provided, "/")
- if len(reqParts) == 2 && len(provParts) == 2{
- ok = rules[kind(reqParts)][kind(provParts)](reqParts,provParts)
- }
- return
- }
Add Comment
Please, Sign In to add comment