-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use JS-based regexes. It fixes year 2015 (which contains a NBSP, whic…
…h wasn't matched by \s regex). Additionally, it should decrease the output JS size
- Loading branch information
Showing
3 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
client/src/main/scala/com/v6ak/scalajs/regex/JsPattern.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,22 @@ | ||
package com.v6ak.scalajs.regex | ||
|
||
import scala.scalajs.js | ||
import scala.language.implicitConversions | ||
|
||
|
||
class JsPattern(val regex: js.RegExp) extends AnyVal { | ||
def unapplySeq(s: String): Option[Seq[String]] = regex.exec(s) match { | ||
case null => None | ||
case parts => Some(parts.toSeq.drop(1).asInstanceOf[Seq[String]]) | ||
} | ||
} | ||
|
||
object JsPattern { | ||
|
||
class JsPatternFactory(val s: String) extends AnyVal { | ||
@inline def jsr: JsPattern = new JsPattern(new js.RegExp(s)) | ||
} | ||
|
||
@inline implicit def wrapString(s: String): JsPatternFactory = new JsPatternFactory(s) | ||
|
||
} |
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