-
Notifications
You must be signed in to change notification settings - Fork 73
update replace' to reflect the existence of optional capturing groups #126
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-- | Wraps Javascript's `RegExp` object that enables matching strings with | ||
-- | patternes defined by regular expressions. | ||
-- | patterns defined by regular expressions. | ||
-- | For details of the underlying implementation, see [RegExp Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp). | ||
module Data.String.Regex | ||
( Regex(..) | ||
|
@@ -95,18 +95,25 @@ foreign import _match | |
match :: Regex -> String -> Maybe (NonEmptyArray (Maybe String)) | ||
match = _match Just Nothing | ||
|
||
-- | Replaces occurences of the `Regex` with the first string. The replacement | ||
-- | Replaces occurrences of the `Regex` with the first string. The replacement | ||
-- | string can include special replacement patterns escaped with `"$"`. | ||
-- | See [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace). | ||
foreign import replace :: Regex -> String -> String -> String | ||
|
||
-- | Transforms occurences of the `Regex` using a function of the matched | ||
-- | substring and a list of submatch strings. | ||
-- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter). | ||
replace' :: Regex -> (String -> Array String -> String) -> String -> String | ||
replace' = replaceBy | ||
foreign import _replaceBy | ||
:: (forall r. r -> Maybe r) | ||
-> (forall r. Maybe r) | ||
-> Regex | ||
-> (String -> Array (Maybe String) -> String) | ||
-> String | ||
-> String | ||
Comment on lines
+103
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this import above the line that references it, for consistency with the placement of |
||
|
||
foreign import replaceBy :: Regex -> (String -> Array String -> String) -> String -> String | ||
-- | Transforms occurrences of the `Regex` using a function of the matched | ||
-- | substring and a list of captured substrings of type `Maybe String`, | ||
-- | where `Nothing` represents an unmatched optional capturing group. | ||
-- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter). | ||
replace' :: Regex -> (String -> Array (Maybe String) -> String) -> String -> String | ||
replace' = _replaceBy Just Nothing | ||
|
||
foreign import _search | ||
:: (forall r. r -> Maybe r) | ||
|
@@ -120,5 +127,5 @@ foreign import _search | |
search :: Regex -> String -> Maybe Int | ||
search = _search Just Nothing | ||
|
||
-- | Split the string into an array of substrings along occurences of the `Regex`. | ||
-- | Split the string into an array of substrings along occurrences of the `Regex`. | ||
foreign import split :: Regex -> String -> Array String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
typeof
check looks odd, but is necessary to handle both possible cases:match, group1, group2, ..., offset, string
(r
contains no named capturing groups); andmatch, group1, group2, ..., offset, string, groups
(r
contains named capturing groups).