All Downloads are FREE. Search and download functionalities are using the official Maven repository.

replpp.shaded.os.GlobInterpolator.scala Maven / Gradle / Ivy

There is a newer version: 0.1.98
Show newest version
package replpp.shaded
package os

object GlobInterpolator {
  class Interped(parts: Seq[String]) {
    def unapplySeq(s: String) = {
      val Seq(head, tail @ _*) = parts.map(java.util.regex.Pattern.quote)

      val regex = head + tail.map("(.*)" + _).mkString
      regex.r.unapplySeq(s)
    }
  }
}

/**
 * Lets you pattern match strings with interpolated glob-variables
 */
class GlobInterpolator(sc: StringContext) {
  def g(parts: Any*) = new StringContext(sc.parts: _*).s(parts: _*)
  def g = new GlobInterpolator.Interped(sc.parts)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy