This isn't checking the case of trailing whitespace. It also looks like the code doesn't handle that case.