Open the context
Choose the project folder and name the files or behavior involved.
Map every code-point boundary in text of at most 4096 characters to its UTF-16 code-unit offset. Test emoji and combining marks, rejecting isolated surrogate code points without normalizing the text.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def utf16_offsets(text):
if type(text) is not str or len(text) > 4096:
raise ValueError("bounded text")
offsets = [0]
for char in text:
value = ord(char)
if 0xD800 <= value <= 0xDFFF:
raise ValueError("unpaired surrogate")
offsets.append(offsets[-1] + (2 if value > 0xFFFF else 1))
return offsetsThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.