For UTF-16, you always need to go to the byte position. Then you can check if a subsequent surrogate follows. If so, skip it, otherwise you are at the beginning of a well-formed sequence of UTF-16 code (always assuming that the file is well-formed, of course).
Unicode UTF-8 and UTF-16 encodings have been specifically designed for self-synchronization, and there are strong guarantees that you need to skip no more than a small number of code blocks.
source
share