This could also be done using regex, though I'm not sure if that would introduce extra overhead.