Description
Encode the text prefix ending at codeUnitOffset as UTF-8 and return its byte length.
Text positions can be measured in UTF-16 code units, Unicode code points, grapheme clusters, or modeled display columns. These coordinates are not interchangeable. Invisible markers and delimiter policies can also affect interpretation even when a string looks unchanged, so the chosen representation needs to stay explicit.
Encode the text prefix ending at codeUnitOffset as UTF-8 and return its byte length.
When to use this tool
Use Text Slice Byte Code Unit Coordinate Pair when you need the stated marker, coordinate, delimiter, or normalization operation under an explicit text representation.
How to use the tool and how it works
- Enter text, codeUnitOffset. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read utf8ByteOffset, splitsSurrogate. Inspect splitsSurrogate before interpreting the associated values.
Encode the text prefix ending at codeUnitOffset as UTF-8 and return its byte length. Also flag splitsSurrogate when that UTF-16 boundary lies between a paired high and low surrogate.1
| Input field | Meaning and units | Accepted input |
|---|---|---|
| text | Text | Required. Text; maximum UTF-16 length 8192. |
| codeUnitOffset | UTF-16 prefix boundary from zero through text.length. | Required. Safe integer; minimum 0. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| utf8ByteOffset | Encoded prefix byte length; not an original-string byte boundary if a surrogate pair is split. | Required. Safe integer. |
| splitsSurrogate | Whether the supplied UTF-16 boundary splits a paired surrogate. | Required. Boolean. |
{
"input": {
"text": "a😀b",
"codeUnitOffset": 3
},
"output": {
"utf8ByteOffset": 5,
"splitsSurrogate": false
}
} Limitations and assumptions
- Offsets range from zero through text.length. The encoder replaces isolated surrogates with U+FFFD, so a split-pair prefix length is not a valid byte boundary in the original full string.
- The field tables state structural bounds; the mechanics also specify cross-field constraints. Malformed inputs and unsupported domains cause errors. A successful false flag, empty branch value, or zero placeholder has the meaning stated above and is distinct from an input error.
Alternative or Complementary methods
Choose the coordinate system required by the consumer. Use a full parser, renderer, or segmentation method when a local marker or delimiter rule cannot determine the complete text behavior.
References
Similar or alternative tools
- Grapheme Edge Slice Boundary
Slice caller-segmented grapheme clusters and report UTF-16 edge offsets; segmentation correctness belongs to the caller.
- Grapheme Cursor Mid Cluster Flag
Segment text using Intl.Segmenter with locale en and grapheme granularity.