-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Expr.RegexMatches, DSL method, and unit tests (#98)
- Add support for .matchesRegex, .findFirstMatch, and .findAllMatches - Add unit tests for one, multiple, and zero RegexMatches - Add documentation
- Loading branch information
Showing
15 changed files
with
506 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.rallyhealth.vapors.v1 | ||
|
||
package data | ||
|
||
import scala.util.matching.Regex | ||
|
||
/** | ||
* Represents the data provided from a regular expression matched within some input string. | ||
* | ||
* @see [[Regex.Match]] | ||
* | ||
* @param matched the string that was matched in the original input | ||
* @param slice the slice range of the matched string | ||
* @param groups a map of group names AND group indexes to their matched strings | ||
*/ | ||
final case class RegexMatch( | ||
matched: String, | ||
slice: SliceRange.Absolute, | ||
groups: Map[String, String], | ||
) | ||
|
||
object RegexMatch { | ||
|
||
def unapply(m: RegexMatch): Some[(String, Map[String, String])] = Some((m.matched, m.groups)) | ||
def unapply(m: Regex.Match): Some[(String, Map[String, String])] = unapply(from(m)) | ||
|
||
def from(m: Regex.Match): RegexMatch = | ||
RegexMatch( | ||
m.matched, | ||
SliceRange.Absolute(m.start, m.end), | ||
(1 to m.groupCount).map(_.toString).zip(m.subgroups).toMap.withDefault { k => | ||
Option(m.group(k)).getOrElse("") | ||
}, | ||
) | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.