UNICODE TEXT

Inspecting two spellings of an accented character

An accented letter can be stored as one precomposed code point or as a base letter followed by a combining mark. The two strings look alike on screen and differ in code points and in bytes.

Two ways to write é

Unicode includes a precomposed character for many accented letters. For é it is U+00E9, LATIN SMALL LETTER E WITH ACUTE. Unicode also allows the same visible result to be built from two characters: the plain letter e, U+0065, followed by the combining acute accent, U+0301. A combining mark attaches itself to the character before it, and a font draws the pair as a single é. The first form is called composed and the second decomposed. Both are valid, and which one you receive depends on the keyboard, the operating system, the application and sometimes the file the text came from.

The precomposed code point

The first case enters the single character é, and the Unicode converter returns U+00E9. There is one scalar value in this text, so any count of code points gives 1, and no separate accent character exists to inspect. In UTF-8 the character takes two bytes, C3 A9. This is the form that most Western European keyboards produce directly, and the form that the Latin-1 character set already had. When a system says it stores text in normalization form C, it prefers this composed version wherever one exists.

The decomposed sequence

The second case enters the letter e followed by U+0301, and the converter returns two code points: U+0065 and U+0301. The text is displayed as é but contains two scalar values. In UTF-8 the letter e is one byte, 65, and the combining accent takes two bytes, CC 81. The total is three bytes, which the third case confirms with the byte length calculator. This form is what normalization form D produces, and it is common in file names created on macOS and in text exported from some linguistic tools. The byte count differs by one from the composed form, a small change that can matter for strict limits, and the code point count differs by one as well.

Why equal-looking strings compare as different

A program that compares strings code point by code point sees é and e followed by the accent as different, although a reader sees the same word. Searching for the composed form in a document that holds the decomposed one finds nothing. A database may hold two entries for what a person considers one name. A hash of the text changes, and so does the length reported by a language that counts code points. The cure is to normalize both sides to one form before comparing, and that step is separate from what this converter does.

What normalization is

Unicode Standard Annex 15 defines four normalization forms. NFC composes characters where possible and NFD decomposes them. NFKC and NFKD also apply compatibility mappings, which fold characters such as the ligature fi into the letters f and i. Under NFC, e followed by U+0301 becomes U+00E9, and under NFD, U+00E9 becomes e followed by U+0301. Normalizing is a transformation with consequences, especially the compatibility forms, which can discard distinctions. Apply it deliberately, name the form you use and apply it consistently, for example to every username before storage and comparison. The web platform and most programming languages offer a normalize function, such as String.prototype.normalize in JavaScript and unicodedata.normalize in Python, and using a library routine is safer than writing replacements by hand. The converter on this site reports the sequence and leaves the choice of normalization form to you.

Counting bytes and characters

The two spellings differ in length by every measure. Composed é has 1 code point and 2 UTF-8 bytes. Decomposed é has 2 code points and 3 UTF-8 bytes. In UTF-16, as used by JavaScript strings, the composed form has length 1 and the decomposed form has length 2. A field limit stated in bytes, code points or user-perceived characters will treat the pair differently. For the user-perceived count, which is one in both cases, an application needs the grapheme cluster rules of Unicode Standard Annex 29, not the code-point or byte counts shown here.

The byte counter measures the exact sequence

The UTF-8 byte length calculator counts the bytes of whatever sequence it receives. For the decomposed input it returns 3, and for the composed one it would return 2. It does not normalize first. This matters when you check a limit, such as a 20-byte column in a database: a name of ten decomposed accented letters takes more bytes than the same name typed in composed form. If a limit is tight, the form of the text can decide whether a value fits, so check the real input rather than a version you retyped.

Other letters with the same pair of forms

The pattern is general. The letter ñ is U+00F1 or n followed by U+0303. The letter ü is U+00FC or u followed by U+0308. Many Vietnamese letters carry two marks and have several equivalent spellings, such as ệ, which can be built from e, a dot below and a circumflex in either order of attachment or from one precomposed character, and normalization puts the marks in a canonical order. A few letters have no precomposed form at all and exist only as a base plus a combining mark. Languages that rely on stacked marks, such as Hindi or Thai, make combining sequences unavoidable. The inspection method here applies to every one of them.

Practical steps when strings misbehave

When two strings that look identical will not match, display their code points. Differences like U+00E9 against U+0065 U+0301 explain the problem at once, and the byte counts of 2 against 3 confirm that the stored data really differs. Then choose a normal form for storage, convert at the boundary where text enters your system and keep the original if you need an exact record. Be careful with copy and paste from documents and websites, which can carry either form. The sample strings in this guide are useful because they can be verified: the composed form must show one code point, and the decomposed form must show two. Typing the decomposed form by hand is not possible on most keyboards, so copy it from a trusted source or use an escape such as e followed by \u0301 in code. A pasted sample that quietly turns into the composed form on its way into a web page shows that some editors normalize on input, and the page you use for the check should keep the sequence you typed. Verify with the code-point list before concluding.

Reproduce the checks

Precomposed form

Open the Unicode Converter and enter:

Calculation mode
encode
Text or encoded input
é

Expected output:

Code points

U+00E9

The text contains one scalar value.

Decomposed form

Open the Unicode Converter and enter:

Calculation mode
encode
Text or encoded input
é

Expected output:

Code points

U+0065 U+0301

The base letter and accent are separate scalar values.

Byte length of the decomposed form

Open the Utf8 Byte Length Calculator and enter:

Text or encoded input
é

Expected output:

Bytes

3

These bytes differ from the two-byte precomposed spelling.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks