Алгоритмы

NFC (Canonical Composition)

Normalization Form C: декомпозиция с последующей канонической рекомпозицией, дающая кратчайшую форму. Рекомендуется для хранения и обмена данными; стандартная веб-форма.

· Updated

NFC: The Web's Default Normal Form

NFC (Normalization Form C — Canonical Composition) is the most widely used Unicode normalization form. It works in two passes: first, it decomposes all characters into their canonical base + combining mark sequences (like NFD), then it recomposes them back into precomposed characters wherever the Unicode standard defines a canonical composition.

The result is the shortest canonical representation of a string. For most Latin-script text, NFC means characters like é, ü, and ñ are stored as single code points rather than two-code-point sequences. For text that is already in NFC (pure ASCII, for instance), normalization is a no-op.

The W3C mandates NFC for all web content in the Character Model for the World Wide Web. Most databases, APIs, and programming environments assume NFC. HTTP headers, JSON payloads, and HTML source files are all expected to use NFC.

macOS user-space applications generally use NFC (despite HFS+ using NFD internally — the OS translates at the file system boundary). Windows and Linux also default to NFC in most contexts. If you are writing text to a file, database, or API and you want maximum interoperability, NFC is the right choice.

Python Examples

import unicodedata

# e + combining acute → é (one code point)
decomposed = "e\u0301"      # NFD form: 2 code points
composed = unicodedata.normalize("NFC", decomposed)

print(repr(decomposed))     # 'e\u0301'
print(repr(composed))       # '\xe9'  (which is é, U+00E9)
print(len(decomposed))      # 2
print(len(composed))        # 1

# Normalize user input before storing
def store_text(text: str) -> str:
    return unicodedata.normalize("NFC", text)

# NFC is idempotent
s = "caf\u00e9"
assert unicodedata.normalize("NFC", s) == s
assert unicodedata.is_normalized("NFC", s)

NFC does NOT fold compatibility characters. The fi ligature (U+FB01) remains under NFC. For search and identifier normalization where you want == fi, use NFKC instead.

Quick Facts

Property Value
Full name Normalization Form Canonical Composition
Algorithm NFD first, then canonical composition
Typical use Web content, databases, API responses, user input storage
W3C standard Required for all web content (Character Model for the WWW)
Python unicodedata.normalize("NFC", s)
Handles compatibility chars? No — use NFKC for that
Idempotent? Yes
Comparison to NFD Usually equal or shorter (composed chars save one code point each)

Связанные термины

Ещё в Алгоритмы

Case Folding

Mapping characters to a common case form for case-insensitive comparison. More comprehensive …

Grapheme Cluster Boundary

Rules (UAX#29) for determining where one user-perceived character ends and another begins. …

NFD (Canonical Decomposition)

Normalization Form D: полная декомпозиция без рекомпозиции. Используется файловой системой macOS HFS+. …

NFKC (Compatibility Composition)

Normalization Form KC: совместимая декомпозиция с последующей канонической композицией. Объединяет визуально похожие …

NFKD (Compatibility Decomposition)

Normalization Form KD: совместимая декомпозиция без рекомпозиции. Самая агрессивная нормализация с максимальной …

String Comparison

Comparing Unicode strings requires normalization (NFC/NFD) and optionally collation (locale-aware sorting). Binary …

Алгоритм переноса строки

Правила определения мест переноса текста на следующую строку с учетом свойств символов, …

Алгоритм сортировки

Стандартный алгоритм сравнения и сортировки строк Unicode с многоуровневым сравнением: базовый символ …

Граница предложения

Позиция между предложениями по правилам Unicode. Сложнее разделения по точкам — учитывает …

Граница слова

Позиция между словами согласно правилам Unicode. Не простое разделение по пробелам — …