คุณสมบัติ

กลุ่มกราฟีม

อักขระที่ผู้ใช้รับรู้ได้ — สิ่งที่รู้สึกเหมือนหน่วยเดียว อาจประกอบด้วยหลายจุดรหัส (ฐาน + เครื่องหมายรวม หรือลำดับ emoji ZWJ) 👩‍💻 = 3 จุดรหัส, 1 grapheme

· Updated

What Is a Grapheme Cluster?

A grapheme cluster is what a user perceives as a single "character" on screen—what you see when you tap the delete key once or advance the cursor by one position. Unicode code points and user-perceived characters are not the same: a single grapheme cluster may consist of multiple code points.

The Unicode Standard defines Extended Grapheme Clusters (EGC) in Unicode Standard Annex #29. The boundary rules specify when adjacent code points form a single cluster:

  • A base character plus any number of combining marks (e.g., a + ́ → á)
  • Hangul syllable sequences (L + V + T clusters, e.g., ㄱ + ㅏ + ㄴ → 간)
  • Emoji modifier sequences (👋 + skin-tone modifier 🏽 → 👋🏽)
  • Flag sequences (regional indicator J + P → 🇯🇵)
  • Emoji ZWJ sequences (👨 + ZWJ + 👩 + ZWJ + 👧 → 👨‍👩‍👧)
  • Emoji presentation sequences (digit + U+FE0F variation selector → 1️⃣)

Grapheme Cluster Iteration in Python

# Python's len() counts code points, not grapheme clusters
flag = "\U0001F1EF\U0001F1F5"   # 🇯🇵 Japan flag (J + P regional indicators)
print(len(flag))                 # 2 code points

family = "\U0001F468\u200D\U0001F469\u200D\U0001F467"  # 👨‍👩‍👧
print(len(family))               # 5 code points

# For grapheme-aware string operations, use the 'grapheme' package
# pip install grapheme
try:
    import grapheme
    print(grapheme.length(flag))    # 1
    print(grapheme.length(family))  # 1

    # Grapheme-safe slicing
    text = "café"  # If stored as c + a + f + e + combining acute
    nfd = "cafe\u0301"
    print(grapheme.length(nfd))     # 4 (user sees 4 characters)
    print(len(nfd))                 # 5 (5 code points)
except ImportError:
    print("Install 'grapheme' package for EGC support")

# Hangul example
hangul = "\u0067\u0041\u002F"   # Not Hangul — just example of combining
syllable = "\uAC00"             # 가 — precomposed Hangul syllable
jamo = "\u1100\u1161"           # ᄀ + ᅡ — jamo sequence = same grapheme
import unicodedata
print(unicodedata.normalize("NFC", jamo) == syllable)  # True

Why Grapheme Clusters Matter

Cursor movement and text editing: A text editor must advance the cursor by one grapheme cluster, not one code point. Moving one code point through 👋🏽 (two code points) would split the emoji in half, leaving a broken sequence.

String truncation: Truncating a string to 10 "characters" for display must count grapheme clusters. text[:10] in Python counts code points and may split an emoji sequence.

Regular expressions: The regex \X in PCRE2 and the Python regex package matches a single extended grapheme cluster, enabling grapheme-aware patterns.

Quick Facts

Property Value
Concept Extended Grapheme Cluster (EGC)
Defined by Unicode Standard Annex #29 (UAX #29)
Python built-in No (use grapheme package or regex \X)
Common pitfall len(s) counts code points, not clusters
Emoji clusters ZWJ sequences, modifier sequences, flag sequences
Hangul Jamo sequences form single grapheme clusters

คำศัพท์ที่เกี่ยวข้อง

เพิ่มเติมใน คุณสมบัติ

East Asian Width

Unicode property (UAX#11) classifying characters as Narrow, Wide, Fullwidth, Halfwidth, Ambiguous, or …

Joining Type

Unicode property controlling how Arabic and Syriac characters connect to adjacent characters. …

Script Extensions

Unicode property listing all scripts that use a character, broader than the …

การแมปตัวพิมพ์

กฎสำหรับแปลงอักขระระหว่างตัวพิมพ์ใหญ่ ตัวพิมพ์เล็ก และตัวพิมพ์หัวเรื่อง อาจขึ้นอยู่กับ locale (ปัญหาตัว I ในภาษาตุรกี) และอาจเป็นแบบหนึ่ง-ต่อ-หลาย (ß → SS)

การแยกส่วน

การแมปอักขระเป็นส่วนประกอบย่อย การแยกส่วนแบบ canonical รักษาความหมาย (é → e + ́) ในขณะที่การแยกส่วนแบบ compatibility อาจเปลี่ยนความหมาย …

คลาสการรวม

ค่าตัวเลข (0–254) ที่ควบคุมลำดับของเครื่องหมายรวมระหว่างการแยกส่วนแบบ canonical กำหนดว่าเครื่องหมายรวมใดสามารถเรียงลำดับใหม่ได้

ความสมมูลความเข้ากันได้

ลำดับอักขระสองชุดที่มีเนื้อหาเชิงนามธรรมเดียวกันแต่อาจแตกต่างในรูปลักษณ์ กว้างกว่าความเท่าเทียมแบบ canonical ตัวอย่าง: fi ≈ fi, ² ≈ 2

ความสมมูลมาตรฐาน

ลำดับอักขระสองชุดที่มีความหมายเหมือนกันและควรถือว่าเท่าเทียมกัน ตัวอย่าง: é (U+00E9) ≡ e + ◌́ (U+0065 + U+0301)

คุณสมบัติการสะท้อน

อักขระที่รูปร่างควรสะท้อนในแนวนอนในบริบท RTL ตัวอย่าง: ( → ), [ → ], { → }, …

คุณสมบัติเวอร์ชัน

เวอร์ชัน Unicode ที่มีการกำหนดอักขระเป็นครั้งแรก มีประโยชน์สำหรับการตรวจสอบการรองรับอักขระในระบบและซอฟต์แวร์เวอร์ชันต่างๆ