-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
compat/src/main/scala-2.11_2.12/scala/util/matching/compat/package.scala
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,30 @@ | ||
/* | ||
* Scala (https://www.scala-lang.org) | ||
* | ||
* Copyright EPFL and Lightbend, Inc. | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package scala.util.matching | ||
|
||
package object compat { | ||
final implicit class RegexOps(val regex: Regex) extends AnyVal { | ||
|
||
/** Returns whether this `Regex` matches the given character sequence. | ||
* | ||
* Like the extractor, this method takes anchoring into account. | ||
* | ||
* @param source The text to match against | ||
* @return true if and only if `source` matches this `Regex`. | ||
* @see [[Regex#unanchored]] | ||
* @example {{{"""\d+""".r matches "123" // returns true}}} | ||
*/ | ||
def matches(source: CharSequence): Boolean = regex.pattern.matcher(source).matches() | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
compat/src/main/scala-2.13/scala/util/matching/compat/package.scala
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,18 @@ | ||
/* | ||
* Scala (https://www.scala-lang.org) | ||
* | ||
* Copyright EPFL and Lightbend, Inc. | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package scala.util.matching | ||
|
||
package object compat { | ||
type Regex = scala.util.matching.Regex | ||
val Regex = scala.util.matching.Regex | ||
} |
26 changes: 26 additions & 0 deletions
26
compat/src/test/scala/scala/util/matching/compat/RegexOpsTest.scala
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,26 @@ | ||
/* | ||
* Scala (https://www.scala-lang.org) | ||
* | ||
* Copyright EPFL and Lightbend, Inc. | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package scala.util.matching.compat | ||
|
||
import org.junit.Assert._ | ||
import org.junit.Test | ||
|
||
class RegexOpsTest { | ||
|
||
@Test | ||
def testMatches(): Unit = { | ||
assertTrue(".*hello.*".r.matches("hey hello")) | ||
assertFalse(".*hello.*".r.matches("hey hop")) | ||
} | ||
|
||
} |