Skip to content

Instantly share code, notes, and snippets.

@beatty
Created November 28, 2009 07:24
Show Gist options
  • Save beatty/244429 to your computer and use it in GitHub Desktop.
Save beatty/244429 to your computer and use it in GitHub Desktop.
/**
* A RouteInfo generated by a RegexRoute. We hold the matcher that was used to verify the match
* so that we can capture the groups. We also lug along the paramNames list. We lazily evaluate
* param names as this is probably cheaper/faster than building a map of names->values up front.
*/
class RegexRouteInfo(val matcher: Matcher, val paramNames: List[String]) extends RouteInfo {
def param(name: String): String = {
val idx = paramNames.findIndexOf(_ == name)
if (idx > -1 && idx < matcher.groupCount) matcher.group(idx + 1) else throw new IllegalArgumentException("bad paramName: " + name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment