in finagle-benchmark/src/main/scala/com/twitter/finagle/stats/GlobBenchmark.scala [14:42]
private def commaSeparatedGlob(glob: String): Option[Pattern] =
if (glob.isEmpty) None
else {
var i = 0
// We expand the resulting string to fit up to 8 regex characters w/o
// resizing the string builder.
val result = new StringBuilder(glob.length + 8)
while (i < glob.length) {
(glob.charAt(i): @switch) match {
case '[' => result.append("\\[")
case ']' => result.append("\\]")
case '|' => result.append("\\|")
case '^' => result.append("\\^")
case '$' => result.append("\\$")
case '.' => result.append("\\.")
case '?' => result.append("\\?")
case '+' => result.append("\\+")
case '(' => result.append("\\(")
case ')' => result.append("\\)")
case '{' => result.append("\\{")
case '}' => result.append("\\}")
case '*' => result.append(".*")
case c => result.append(c)
}
i += 1
}
commaSeparatedRegex(result.toString).map(_.pattern)
}