fix bugs & support surrogate pairs on Windows