Skip to content

make match safe #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

flags :: Regex -> RegexFlags

match :: Regex -> String -> [String]
match :: Regex -> String -> Maybe [String]

parseFlags :: String -> RegexFlags

Expand Down
16 changes: 10 additions & 6 deletions src/Data/String/Regex.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module Data.String.Regex (
split
) where

import Data.Function
import Data.Maybe
import Data.String (indexOf)

foreign import data Regex :: *
Expand Down Expand Up @@ -84,12 +86,14 @@ foreign import test
\ };\
\}" :: Regex -> String -> Boolean

foreign import match
"function match(r) {\
\ return function (s) {\
\ return s.match(r); \
\ };\
\}" :: Regex -> String -> [String]
foreign import _match
"function _match(r, s, Just, Nothing) {\
\ var m = s.match(r);\
\ return m == null ? Nothing : Just(m);\
\}" :: forall r. Fn4 Regex String ([String] -> r) r r

match :: Regex -> String -> Maybe [String]
match r s = runFn4 _match r s Just Nothing

foreign import replace
"function replace(r) {\
Expand Down