Utf8ledger

The method

One received string, three distinct counts

Utf8ledger measures the UTF-8 payload of the JavaScript string received from the input. It does not guess a file encoding or inspect a server. The text is not trimmed, normalized or shortened. An entered U+FEFF is counted rather than treated as a removable signature, and an unpaired UTF-16 surrogate produces an error rather than a replacement character.

Bytes, units and scalar values

A Unicode scalar value is a code point outside the surrogate range. JavaScript strings use UTF-16 code units: a scalar in the supplementary range occupies a pair of those units. UTF-8 instead encodes each scalar as one to four bytes. These counts do not equal a grapheme or user-perceived character count. A combined emoji or accented sequence can contain several scalars.

The fixed example A🐝é contains three scalar values and four UTF-16 units. A uses one UTF-8 byte, the bee uses four and é uses two, for seven bytes total. With an eight-byte payload budget, one byte remains.

Exact encoding arithmetic

A scalar through U+007F uses one byte; through U+07FF it uses two; through U+FFFF, excluding surrogates, it uses three; higher scalars through U+10FFFF use four. The per-scalar encoder distributes the value's bits into standard leading and continuation bytes. Summing those byte lengths gives the complete payload count. Byte offsets are prefix sums starting at zero.

UTF-16 decoding validates every high-surrogate and low-surrogate pair first. A missing or reversed pair rejects. This avoids quietly measuring a replacement character that differs from the entered string. The calculator accepts all scalar values, including controls, noncharacters and unassigned code points; acceptance is not a claim that a glyph will render.

The textarea boundary matters

Browsers can normalize pasted line endings before the script reads the textarea. A direct parser string containing a CRLF pair counts two scalar values and two bytes for that pair. If the actual textarea contains LF instead, the tool counts that one received LF. It cannot reconstruct original clipboard or file bytes. No Unicode normalization is performed after this boundary.

Budget and bounds

For payload N and your chosen budget B, remaining bytes are max(B − N, 0), excess bytes are max(N − B, 0), and the payload fits when N ≤ B. Empty text and a zero budget are valid. There is no division or percentage for a zero limit.

Text is limited to 100,000 UTF-16 units. The largest payload within that bound is 300,000 bytes, reached by three-byte BMP scalars. The budget is an integer from 0 to 1,000,000,000, with at most 16 raw input units. Only outer ASCII space, tab, CR and LF are trimmed from the budget; signs, fractions, leading zeroes and exponent notation reject.

The preview renders at most 100 scalar records per page. Summary exports include all current totals and model assumptions, not the pasted text or a partial table. The result excludes JSON escaping, file metadata, HTTP headers, compression and storage overhead, and does not guarantee an external service will accept the text.

Primary references

RFC 3629 defines UTF-8 byte ranges and excludes surrogate code points. The WHATWG UTF-8 encoder describes byte emission. The Unicode glossary distinguishes scalar values and encoding units. These support the declared model, not a universal visible-character or service-size promise.