I'm not sure what this code does... Asian input methods, I think. If so it may be hard to test.  Are you confident that symbols will always be plain text with no HTML &entitties; ?