This bit of code implements a mini string matching language - which understands two symbols (?=match any char, *=match one or more char). This code seems to work just fine, but it seems a little bit inelegant.
object Re {
def check(search: String, input: String):Boolean = {
search match {
case `input` => true
case x if x.startsWith("?") =>
check(x.stripPrefix("?"), input.tail)
case x if x.startsWith("*") => input match {
case "" => false
case i => check(x.stripPrefix("*"), i.tail) | check(x, i.tail)
}
case _ => false
}
}
}
Specifically, I dislike the cases where I say x if x.startswith(something) and then have to strip that something.
Does scala have a more idiomatic way to do this? Something along the lines of how the Seq matcher works so that I don't need startsWith or stripPrefix.