I am currently working with Scanners and Parsers and need a Parser that accepts characters that are ASCII letters - so I can't use char.isLetter
.
I came up with two solutions myself. I don't like both of them.
Regex
def letter = elem("ascii letter", _.toString.matches("""[a-zA-Z]"""))
This seems rather "overkill" to check such a simple thing with a regex.
Range check
def letter = elem("ascii letter", c => ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
In my opinion, this would be the way to go in Java. But it's not really readable.
Is there a cleaner, more Scala-like solution to this problem? I do not really worry about performance, as it doesn't matter in this case.