Handle surrogate pairs and combining characters correctly.