diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2018-01-10 16:34:03 +0100 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2018-01-10 16:34:03 +0100 |
commit | a8fb763c8b43d0b04238db48649495f964737c97 (patch) | |
tree | 7c31950fa1164f4a1bbcc3b6abafc297a23aa8a9 /re.go | |
parent | a19cef3a067381ff3b38de722411d618ea87500c (diff) |
handle false regexps
Diffstat (limited to 're.go')
-rw-r--r-- | re.go | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -1,23 +1,26 @@ package main import ( + "errors" "regexp" "strings" ) -func re(s, r string, global bool) string { +var ErrNotRE = errors.New("not re") + +func re(s, r string, global bool) (string, error) { // min: at least two separators if len(r) < 2 { - return "" + return "", ErrNotRE } z := strings.Split(r[1:], string(r[0])) // match // and /// if len(z) < 2 || len(z) > 3 { - return "" + return "", ErrNotRE } re, err := regexp.Compile(z[0]) if err != nil { - return "" + return "", err } i := 1 if global { @@ -29,5 +32,5 @@ func re(s, r string, global bool) string { return z[1] } return b - }) + }), nil } |