Skip to content

Commit 74c20e8

Browse files
committed
TODO -1: Use Pattern.compile
1 parent 4a0dbc3 commit 74c20e8

File tree

1 file changed

+1
-17
lines changed
  • extra/src/main/scala/japgolly/scalajs/react/extra/router

1 file changed

+1
-17
lines changed

extra/src/main/scala/japgolly/scalajs/react/extra/router/Dsl.scala

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ import scala.util.matching.Regex
1717
*/
1818
object StaticDsl {
1919

20-
private val regexEscape1 = """([-()\[\]{}+?*.$\^|,:#<!\\])""".r
21-
private val regexEscape2 = """\x08""".r
22-
23-
// TODO: Replace with Pattern.quote after Scala.JS 1.6.x
24-
/**
25-
* Pattern.quote doesn't work in Scala.JS.
26-
*
27-
* http://stackoverflow.com/questions/2593637/how-to-escape-regular-expression-in-javascript
28-
*/
29-
def regexEscape(s: String): String = {
30-
var r = s
31-
r = regexEscape1.replaceAllIn(r, """\\$1""")
32-
r = regexEscape2.replaceAllIn(r, """\\x08""")
33-
r
34-
}
35-
3620
/**
3721
* Route builder. Allows you to specify routes like `"user" / int / "display"`.
3822
* Once complete, [[RouteB]] will become a [[Route]].
@@ -98,7 +82,7 @@ object StaticDsl {
9882
private val someUnit = Some(())
9983

10084
def literal(s: String): RouteB[Unit] =
101-
new RouteB(regexEscape(s), 0, _ => someUnit, _ => s)
85+
new RouteB(Pattern.quote(s), 0, _ => someUnit, _ => s)
10286

10387
val / = literal("/")
10488
}

0 commit comments

Comments
 (0)