Description
Shift a Unicode-source offset by a supplied number of source code units.
Unicode text has several distinct length and position bases: UTF-16 code units, code points, grapheme clusters and rendered glyphs. An edit offset in source text need not equal an offset in decoded text. Unicode properties also belong to a specific version; recording a property value is distinct from looking it up or validating it.
Shift a Unicode-source offset by a supplied number of source code units.
When to use this tool
Use Unicode Escape Source Offset Shift when you already have sourceOffset, insertedSourceCodeUnits and need to shift a Unicode-source offset by a supplied number of source code units.
How to use the tool and how it works
- Enter sourceOffset, insertedSourceCodeUnits. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read shiftedOffset. Use the output convention below.
Require nonnegative safe whole sourceOffset and signed safe whole insertedSourceCodeUnits, with exact BigInt sum>=0; export the sum as a number.1
UTF-16 represents supplementary code points with two code units. Source offsets must retain their code-unit basis rather than being treated as decoded-character counts.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| sourceOffset | Source Offset | Required. Safe integer; minimum 0. |
| insertedSourceCodeUnits | Signed change in source UTF-16 code units, not decoded characters. | Required. Safe integer. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| shiftedOffset | Nonnegative safe integer after exact addition; an unsafe output is rejected. | Required. Safe integer. |
{
"input": {
"sourceOffset": 12,
"insertedSourceCodeUnits": 5
},
"output": {
"shiftedOffset": 17
}
} Limitations and assumptions
- Offsets count source UTF-16 code units, not decoded characters or code points. An output beyond the safe-integer range is rejected.
- Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
- Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.
Alternative or Complementary methods
Use a Unicode property database for the stated version when an actual property lookup is needed. For source edits, map offsets in the original text and keep UTF-16 positions separate from decoded code points, grapheme boundaries and display widths.
References
-
Calculation and input contract: text/unicode-escape-source-offset-shift — tool.io
-
Unicode 17.0: characters and encoding forms — Unicode Consortium
Similar or alternative tools
- text/line-column-to-utf16-offset
Map one-based logical line/UTF-16 content column to offset; columns inside separators are intentionally not accepted.
- text/utf16-offset-to-line-column
Map a UTF-16 offset to one-based line/column with CRLF treated as one line separator; offsets inside CRLF retain their physical column.