NFD (Canonical Decomposition)
정규화 형식 D: 재합성 없이 완전히 분해합니다. macOS HFS+ 파일 시스템에서 사용됩니다. é (U+00E9) → e + ◌́ (U+0065 + U+0301).
NFD: Decomposing Characters to Their Components
NFD (Normalization Form D — Canonical Decomposition) is the form where every composed character is broken down into its constituent parts: a base character followed by one or more combining marks in canonical order. Unlike NFC which recomposes after decomposing, NFD leaves everything decomposed.
For é (U+00E9, LATIN SMALL LETTER E WITH ACUTE), NFD yields the two-code-point sequence e (U+0065) + ́ (U+0301, COMBINING ACUTE ACCENT). For a string like "über", NFD yields u + combining diaeresis + b + e + r — five code points for a four-character word.
When NFD is Used
NFD is the internal form used by Apple's HFS+ and APFS file systems. When macOS writes a filename to disk, it stores it in NFD. This is why filenames created on a Mac can cause issues when transferred to Linux systems: the file café is stored as 5 code points (NFD) on HFS+ but most Linux applications expect 4 code points (NFC). Python's os module will give you the NFD filename on macOS unless you normalize it.
NFD is also useful when you need to strip diacritics:
import unicodedata
def strip_accents(text: str) -> str:
# Decompose to base + combining marks, then remove all combining marks
nfd = unicodedata.normalize("NFD", text)
return "".join(
c for c in nfd
if unicodedata.category(c) != "Mn" # Mn = Mark, Nonspacing
)
print(strip_accents("naïve")) # naive
print(strip_accents("résumé")) # resume
print(strip_accents("über")) # uber
Combining Mark Order
A subtle but important aspect of NFD: when multiple combining marks follow a base character, Unicode specifies their Canonical Combining Class (CCC) order. Marks with lower CCC values come first (CCC=0 is the base character). The acute accent has CCC=230, the cedilla has CCC=202. NFD ensures combining marks are always in this canonical order, which is necessary for correct canonical equivalence testing.
import unicodedata
# Check combining class of a character
print(unicodedata.combining("\u0301")) # 230 (COMBINING ACUTE ACCENT)
print(unicodedata.combining("\u0327")) # 202 (COMBINING CEDILLA)
print(unicodedata.combining("a")) # 0 (not a combining mark)
Quick Facts
| Property | Value |
|---|---|
| Full name | Normalization Form Canonical Decomposition |
| Algorithm | Recursive canonical decomposition, then CCC sorting |
| macOS HFS+ | Filenames stored in NFD |
| Typical use | Diacritic stripping, internal processing, canonical comparison |
| Python | unicodedata.normalize("NFD", s) |
| Handles compatibility chars? | No |
| Relation to NFC | NFD then compose = NFC |
| String length | Equal or longer than NFC (decomposed forms use more code points) |
관련 용어
알고리즘의 더 많은 용어
Mapping characters to a common case form for case-insensitive comparison. More comprehensive …
Rules (UAX#29) for determining where one user-perceived character ends and another begins. …
정규화 형식 C: 분해 후 정규 재합성하여 가장 짧은 형식을 생성합니다. 데이터 …
정규화 형식 KC: 호환 분해 후 정규 합성. 시각적으로 유사한 문자를 통합합니다(fi→fi, …
정규화 형식 KD: 재합성 없이 호환 분해. 가장 강력한 정규화 방식으로 서식 …
Comparing Unicode strings requires normalization (NFC/NFD) and optionally collation (locale-aware sorting). Binary …
유니코드 단어 경계 규칙에 따라 결정된 단어 사이의 위치. 단순히 공백으로 분리하는 …
유니코드 규칙에 따른 문장 사이의 위치. 마침표로만 분리하는 것보다 복잡하며, 약어(Mr.), 생략 …
문자 양방향 범주와 명시적 방향 재정의를 사용하여 혼합 방향 텍스트(예: 영어 + …
유니코드 텍스트를 표준 정규 형식으로 변환하는 과정. 네 가지 형식: NFC(합성), NFD(분해), …