Advertisement
Data Processing

The Elastic Length: When One Visible Character Has Many Sizes

Ask a program how long a piece of text is and the answer sounds like it should be a fact about the text. In practice it is a fact about the...

Ask a program how long a piece of text is and the answer sounds like it should be a fact about the text. In practice it is a fact about the counter. Count one way and a short string of faces and flags stretches far beyond a plain sentence of letters. Count another way and the two can look almost the same. Interfaces truncate and validators reject based on whichever count a developer called length. This article follows a controlled run in which the same strings were measured two ways, and the gap between the two answers turned out to be the rule rather than the exception.

What The Elastic Length means

The Elastic Length is the property of a displayed string whose measured length changes with the counting unit applied to it, because a single visible character can be built from several underlying code points. A code point is one unit in the encoded sequence. A grapheme, in the sense used here, is one visible unit as a reader perceives it: one letter, one flag, one joined family portrait. When the two counts agree, length feels solid. When they disagree, length behaves like elastic. The run behind this article states its presentation plainly: it works with 600 display strings in five categories of 120 each, namely plain ASCII, combining accents, family emoji, flags, and skin-tone emoji (Source: evidence/sd_batch12_results.json, group AC1). Those category labels are the table headers of the result set, and the qualifiers attached to them matter, because the effect is not spread evenly across ordinary text. It concentrates exactly where visible characters are assembled from parts.

The nearest neighbour is The Twin Glyphs. That concept concerns two characters that look the same while being different code points, a case of identical appearance hiding different identity. The Elastic Length runs in the opposite direction: one visible character that is genuinely one thing to the reader is several code points underneath, a case of single appearance built from multiple identity. Confusing the two leads to the wrong fix: deduplication addresses the first problem, while choosing the right counting unit addresses the second.

Where the two counts part

The headline result is stark. Across the full set, code point count and grapheme count disagreed for 480 of the 600 strings, which is 80.00% (derived: 480 / 600 x 100) (Source: evidence/sd_batch12_results.json, group AC1). Disagreement was the outcome for four out of every five strings. The category averages show where the stretch lives. Plain ASCII averaged 8.8000 code points and 8.8000 graphemes (Source: evidence/sd_batch12_results.json, group AC1), a perfect agreement, as expected for text where each visible character is a single unit. Combining accents averaged 9.8083 code points against 8.8083 graphemes (Source: evidence/sd_batch12_results.json, group AC1), a modest stretch caused by marks that attach to a base letter instead of standing alone.

The assembled emoji stretch much further. Family emoji averaged 16.7750 code points against 10.7750 graphemes (Source: evidence/sd_batch12_results.json, group AC1). Flags averaged 11.7750 code points against 10.7750 graphemes (Source: evidence/sd_batch12_results.json, group AC1). Skin-tone emoji averaged 11.7250 code points against 10.7250 graphemes (Source: evidence/sd_batch12_results.json, group AC1). The single clearest illustration is the family group itself: a family emoji built from four people joined by three zero-width joiners contains 7 code points yet forms 1 grapheme (Source: evidence/sd_batch12_results.json, group AC1). The stretch is what composition costs when the bill is counted in code points and the reader counts in pictures.

The Elastic Length: When One Visible Character Has Many Sizes

How the strings were counted

The method needs to be stated exactly, because the value of the run depends on what it is and what it is not. This was a synthetic-data exercise: the strings were generated for the test, not harvested from a product, a customer database, or live traffic. The run used seed 42, so the same generation produces the same set again. The counting followed the script's own deterministic logic, applied uniformly to every string, rather than the behaviour of any named commercial product. It is therefore not a commercial product measurement, and no result here should be read as a claim about how a particular editor, platform, or vendor library counts. What the run supports is narrower: under one consistent counting rule, the two lengths diverge in the proportions recorded. Synthetic data allows balanced categories, but a real corpus would produce a different overall mismatch rate.

What truncation does with the gap

Counting differences would be a curiosity if nothing acted on the counts. Truncation acts on them. When the strings in this run were cut at a limit of 12 code points, the cut landed inside a grapheme cluster in 60 places (Source: evidence/sd_batch12_results.json, group AC1). Every one of those mid-cluster cuts fell in the family emoji category (Source: evidence/sd_batch12_results.json, group AC1). A cut there does not merely shorten text. It breaks a picture into pieces never meant to appear separately.

A limit applied in the other direction behaved better in this run. A ceiling of 20 code points produced 0 false rejections (Source: evidence/sd_batch12_results.json, group AC1), meaning no string that should have passed under that rule was wrongly turned away. It shows, within this run, that harm appeared at the tighter cut as broken clusters, while the looser ceiling produced no false rejections. The danger is not length checking in general, but cutting before asking what a character is.

Questions, answered

How often did the two counts disagree? They disagreed for 480 of the 600 strings, or 80.00% (derived: 480 / 600 x 100) (Source: evidence/sd_batch12_results.json, group AC1). The disagreement was driven by the assembled categories, since plain ASCII agreed exactly on average, at 8.8000 by both measures (Source: evidence/sd_batch12_results.json, group AC1).

What makes a family emoji so long underneath? Its construction. A family emoji in this run joins four people with three zero-width joiners, giving 7 code points for 1 grapheme (Source: evidence/sd_batch12_results.json, group AC1). Each person and each joiner is a separate code point, while the reader sees a single composed picture.

Did truncation actually break anything? Yes, at the tighter limit tested. Cutting at 12 code points landed inside a cluster in 60 places, all of them in the family emoji category (Source: evidence/sd_batch12_results.json, group AC1). A ceiling of 20 code points, by contrast, produced 0 false rejections in the same run (Source: evidence/sd_batch12_results.json, group AC1).

Is this how commercial products count text? That is not what was measured. The run used synthetic data, seed 42, and the script's own deterministic logic, and it is not a commercial product measurement (Source: evidence/sd_batch12_results.json, group AC1). It demonstrates what the two counting units do to these categories, not what any specific product chooses to do.

Summary

The Elastic Length is a reminder that length is a measurement, not a property sitting inside the text waiting to be read off. In this balanced run of 600 strings, the two natural measurements disagreed four times out of five, agreed perfectly for plain letters, and diverged most sharply exactly where visible characters are assembled from joiners, modifiers, and regional parts. The consequences were concrete rather than theoretical: a code point cut broke clusters dozens of times, always in the same category, while a looser ceiling rejected nothing. Teams that display, limit, or store user text do not need to abandon code point counts, which remain the right unit for storage and transmission. They need to stop mistaking that unit for what a reader sees, and to cut and validate on the unit that matches the promise the interface makes.

Sources

Know someone who needs this? Share it.

Advertisement