It is all neat but it does not scale that nicely if there are a number of possible leading characters. It looks like a good use case for regular expressions to me.