정규 동치
의미상 동일하여 동등하게 처리해야 하는 두 문자 시퀀스. 예: é (U+00E9) ≡ e + ◌́ (U+0065 + U+0301).
What Is Canonical Equivalence?
Two Unicode strings are canonically equivalent if they represent the same abstract character sequence and should be treated as identical in all Unicode-conforming operations. They look the same, are pronounced the same, and have the same semantic value—the only difference is how the code points are arranged.
The canonical equivalence. The most common example is a precomposed character versus a base letter followed by a combining diacritic:
- U+00F1 LATIN SMALL LETTER N WITH TILDE (ñ) — a single code point
- U+006E LATIN SMALL LETTER N + U+0303 COMBINING TILDE — two code points
These two sequences are canonically equivalent. They must render identically and compare as equal after normalization.
Canonical Normalization Forms
Unicode defines two canonical normalization forms:
| Form | Description |
|---|---|
| NFD (Canonical Decomposition) | Break all precomposed characters into base + combining marks; apply canonical ordering |
| NFC (Canonical Composition) | Apply NFD, then recompose into precomposed characters where possible |
import unicodedata
# Two ways to write Spanish "ñ"
precomposed = "\u00F1" # ñ as single code point
decomposed = "\u006E\u0303" # n + combining tilde
# They look the same:
print(precomposed, decomposed)
# ñ ñ
# But they are NOT equal as raw Python strings:
print(precomposed == decomposed)
# False
print(len(precomposed), len(decomposed))
# 1 2
# After NFC normalization they are equal:
nfc_pre = unicodedata.normalize("NFC", precomposed)
nfc_dec = unicodedata.normalize("NFC", decomposed)
print(nfc_pre == nfc_dec)
# True
# After NFD normalization they are also equal:
nfd_pre = unicodedata.normalize("NFD", precomposed)
nfd_dec = unicodedata.normalize("NFD", decomposed)
print(nfd_pre == nfd_dec)
# True
print(len(nfd_pre), len(nfd_dec))
# 2 2 (both are now decomposed)
Why This Matters
String comparison: Any application that compares user input against stored data must normalize both sides to the same form. Passwords, usernames, and search queries can silently differ due to canonical equivalence. The Python unicodedata.normalize("NFC", s) call is the standard fix.
Database storage: PostgreSQL uses NFC internally for text; MySQL's behavior depends on collation. Storing NFD strings in a NFC-collating database can cause subtle lookup failures.
File systems: macOS HFS+ normalizes filenames to NFD; Windows NTFS and Linux ext4 are normalization-agnostic. A file named ñ.txt may be stored differently on different systems, causing sync tools to create duplicates.
Quick Facts
| Property | Value |
|---|---|
| Concept | Canonical equivalence |
| Normalization forms | NFD, NFC |
| Python function | unicodedata.normalize("NFC", s) / "NFD" |
| Common pitfall | Comparing strings without normalizing first |
| Opposite concept | Compatibility equivalence (looser, NFKD/NFKC) |
| Spec reference | Unicode Standard Annex #15 (UAX #15) |
관련 용어
속성의 더 많은 용어
Unicode property (UAX#11) classifying characters as Narrow, Wide, Fullwidth, Halfwidth, Ambiguous, or …
Unicode property controlling how Arabic and Syriac characters connect to adjacent characters. …
Unicode property listing all scripts that use a character, broader than the …
정규 분해 과정에서 결합 기호의 순서를 제어하는 수치 값(0~254)으로, 어떤 결합 기호를 …
마침표, 쉼표, 대시, 따옴표 등 문어를 구성하고 명료하게 하는 데 사용되는 문자. …
지원하지 않는 프로세스에서 눈에 보이는 효과 없이 무시할 수 있는 문자로, 이형 …
문자가 처음 할당된 유니코드 버전. 시스템 및 소프트웨어 버전 간의 문자 지원 …
문자를 대문자, 소문자, 제목 대문자로 변환하는 규칙. 로케일에 따라 달라질 수 있으며(터키어 …
RTL 문맥에서 글리프를 수평으로 반전해야 하는 문자. 예: ( → ), [ …
문자가 속한 문자 체계(예: 라틴, 키릴, 한자). Unicode 16.0은 168개의 문자 체계를 …