Skip to content

Main content

Text Slice Byte Code Unit Coordinate Pair Tool

Compute text slice byte code unit coordinate pair from explicit bounded inputs.

Loading tool…

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

  1. Enter text, codeUnitOffset. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. 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 fieldMeaning and unitsAccepted input
textTextRequired. Text; maximum UTF-16 length 8192.
codeUnitOffsetUTF-16 prefix boundary from zero through text.length.Required. Safe integer; minimum 0.
Output fieldInterpretationReturned shape
utf8ByteOffsetEncoded prefix byte length; not an original-string byte boundary if a surrogate pair is split.Required. Safe integer.
splitsSurrogateWhether the supplied UTF-16 boundary splits a paired surrogate.Required. Boolean.
json
{
  "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

  1. Calculation and input contract: text/text-slice-byte-code-unit-coordinate-pair — tool.io

Similar or alternative tools