Created
August 5, 2014 22:34
-
-
Save sam/0f3a2210eca47b0dfb55 to your computer and use it in GitHub Desktop.
Escape all in String
This file contains hidden or 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
object Lucene { | |
object Escape extends (String => String) { | |
private val prefix: Char => PartialFunction[Char, String] = c => { case `c` => s"\\$c" } | |
private val escapist: PartialFunction[Char, String] = prefix('\\') orElse | |
prefix('+') orElse | |
prefix('-') orElse | |
prefix('!') orElse | |
{ case c => s"$c" } | |
def apply(s: String): String = s map(escapist) mkString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just looking for a nice way to implement lucene.QueryParserUtil.escape