Description
Validate codePoint as a Unicode scalar and return one, two, three, or four UTF-8 bytes at the 0x7F, 0x7FF, and 0xFFFF boundaries.
Unicode text can be counted as code points, UTF-16 units, encoded bytes, or grapheme clusters. A literal character transformation follows a specific mapping and may preserve distinctions that a broader normalization would remove.
Validate codePoint as a Unicode scalar and return one, two, three, or four UTF-8 bytes at the 0x7F, 0x7FF, and 0xFFFF boundaries.
When to use this tool
Use UTF-8 Codepoint Byte Budget when you need one explicitly bounded Unicode mapping, count, or encoding component.
How to use the tool and how it works
- Enter codePoint. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read byteCount. Use the output convention below.
Validate codePoint as a Unicode scalar and return one, two, three, or four UTF-8 bytes at the 0x7F, 0x7FF, and 0xFFFF boundaries.1
UTF-8 encodes a Unicode scalar in one through four bytes. Surrogate code points are excluded, so they cannot be treated as individually encodable Unicode scalars.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| codePoint | Integer Unicode scalar from U+0000 to U+10FFFF, excluding U+D800-U+DFFF. | Required. Safe integer. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| byteCount | UTF-8 bytes for this one scalar; not a grapheme count or UTF-16 length. | Required. Safe integer. |
{
"input": {
"codePoint": 128578
},
"output": {
"byteCount": 4
}
} Limitations and assumptions
- Surrogate code points are rejected; the count covers one scalar rather than a grapheme, complete string, or BOM.
- 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
Choose normalization and comparison rules for the intended language and preserve the original text when creating a search variant.
References
-
Calculation and input contract: text/utf8-codepoint-byte-budget — tool.io
-
UTF-8, a transformation format of ISO 10646, RFC 3629 — RFC Editor / IETF
Similar or alternative tools
- text/utf8-byte-offset-to-codepoint-index
Convert UTF-8 byte offset to zero-based Unicode scalar index; reject unpaired surrogates and offsets inside multibyte encodings.
- 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.