Skip to content

Commit 4e7f0d5

Browse files
committed
Merge pull request #14 from davidchambers/match
make match safe
2 parents 1804bed + 3dfeda2 commit 4e7f0d5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
flags :: Regex -> RegexFlags
8888

89-
match :: Regex -> String -> [String]
89+
match :: Regex -> String -> Maybe [String]
9090

9191
parseFlags :: String -> RegexFlags
9292

src/Data/String/Regex.purs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ module Data.String.Regex (
1414
split
1515
) where
1616

17+
import Data.Function
18+
import Data.Maybe
1719
import Data.String (indexOf)
1820

1921
foreign import data Regex :: *
@@ -84,12 +86,14 @@ foreign import test
8486
\ };\
8587
\}" :: Regex -> String -> Boolean
8688

87-
foreign import match
88-
"function match(r) {\
89-
\ return function (s) {\
90-
\ return s.match(r); \
91-
\ };\
92-
\}" :: Regex -> String -> [String]
89+
foreign import _match
90+
"function _match(r, s, Just, Nothing) {\
91+
\ var m = s.match(r);\
92+
\ return m == null ? Nothing : Just(m);\
93+
\}" :: forall r. Fn4 Regex String ([String] -> r) r r
94+
95+
match :: Regex -> String -> Maybe [String]
96+
match r s = runFn4 _match r s Just Nothing
9397

9498
foreign import replace
9599
"function replace(r) {\

0 commit comments

Comments
 (0)