Unicode Normalization and Text Equality

Normalization produces a prescribed form for canonically equivalent text so independently stored spellings can compare consistently.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Compare a decomposed spelling
  2. Keep normalization deliberate
  3. Check composed and decomposed spellings
  4. Keep different equivalence policies visible

Compare a decomposed spelling

The precomposed code point for é and the sequence of e followed by a combining acute have different code point lists. Normalizing both to NFC gives the same form for this example. Code points and visible characters explain why ordinary length can differ beforehand.

Keep normalization deliberate

Normalize both sides of a comparison if application rules expect canonical equivalence. Preserve original text when its exact bytes or spelling have a separate purpose. Canonical label keys can live beside the original visible label.[1]

Check composed and decomposed spellings

The letter é can be represented by one code point or by e followed by a combining acute accent. Direct code-point comparison distinguishes those sequences. Normalizing both to NFC can give the same composed representation. If the application preserves submitted text for display, store it alongside a normalized lookup key. Test both spellings as search input and stored data because either side may be the decomposed form. See Unicode positions.

Keep different equivalence policies visible

Case folding and compatibility normalization can merge distinctions beyond canonical normalization. A technical identifier policy may choose exact comparison while a free-text search can be more permissive. When building an index, apply the same transformations to stored keys and queries. Test a value whose visual similarity should not imply equality in the chosen domain. Preserve separate record identities when display spellings collide. See case-folded comparisons.

References

  1. Unicode Consortium, Unicode Standard Annex 15: Unicode Normalization Forms ↩