Add character boundary check

Fixes a bug when parsing unicode.