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

scalan.util.ScalaNameUtil.scala Maven / Gradle / Ivy

The newest version!
package scalan.util

object ScalaNameUtil {
  val opChars = Set('+', '-', '*', '/', ':', '>', '<', '=', '!', '@', '#', '%',
    '&', '~', '?', '|', '\\', '^')
  
  def cleanNestedClassName(className: String): String =
    cleanScalaName(className.substring(className.lastIndexOf("$") + 1))

  def cleanScalaName(name: String): String = {
    name.replace("$plus", "+").replace("$minus", "-").
      replace("$times", "*").replace("$div", "/").
      replace("$colon", ":").replace("$greater", ">").
      replace("$less", "<").replace("$eq", "=").
      replace("$bang", "!").replace("$at", "@").
      replace("$hash", "#").replace("$percent", "%").
      replace("$amp", "&").replace("$tilde", "~").
      replace("$qmark", "?").replace("$bar", "|").
      replace("$bslash", "\\").replace("$up", "^")
  }
  
  def isOpName(name: String) = !name.isEmpty && opChars.contains(name.last)

  object PackageAndName {
    def unapply(name: String): Option[(List[String], String)] = {
      val parts = name.split('.')
      if (parts.length > 1)
        Some((parts.slice(0, parts.length - 1).toList, parts.last))
      else
        None
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy