Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created January 20, 2013 21:04
Show Gist options
  • Save Sciss/4581778 to your computer and use it in GitHub Desktop.
Save Sciss/4581778 to your computer and use it in GitHub Desktop.
string interpolation test for hex (css style) colors
implicit class HexColor(val sc: StringContext) extends AnyVal {
def rgb(args: Any*) = sc.parts match {
case Seq(t) =>
require(t.length == 6, "must have length 6")
val i = Integer.parseInt(t, 16)
new java.awt.Color(i)
case _ => sys.error("Parts are unsupported")
}
}
rgb"141f2e"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment