summaryrefslogtreecommitdiff
path: root/re.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-01-10 16:34:03 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-01-10 16:34:03 +0100
commita8fb763c8b43d0b04238db48649495f964737c97 (patch)
tree7c31950fa1164f4a1bbcc3b6abafc297a23aa8a9 /re.go
parenta19cef3a067381ff3b38de722411d618ea87500c (diff)
handle false regexps
Diffstat (limited to 're.go')
-rw-r--r--re.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/re.go b/re.go
index d2461ab..4d3fa48 100644
--- a/re.go
+++ b/re.go
@@ -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
}