I am currently working with scanners and analyzers and need a parser that accepts characters that are ASCII letters, so I cannot use it char.isLetter.
I myself came up with two solutions. I do not like both of them.
Regex
def letter = elem("ascii letter", _.toString.matches("""[a-zA-Z]"""))
It seems rather "redundant" to test such a simple thing with regex.
Range check
def letter = elem("ascii letter", c => ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
In my opinion, this would be a way to go in Java. But this is not entirely clear.
Is there a cleaner, more Scala-like solution to this problem? I'm really not worried about performance, as that doesn't matter in this case.
source
share