OOffsetIlex
Workflows

Coding workflows · UTF-16 boundary offsets

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

UTF-16 boundary offsets

A concrete starting point
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 offsets

The 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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗