1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! Core width resolution logic for grapheme clusters.
//!
//! This module defines low-level width computation used by all public APIs.
//!
//! It supports:
//! - Terminal-style default width (`get_display_width`)
//! - Customizable policy-based width (`get_display_width_with_policy`)
//!
//! Widths are resolved to 0, 1, or 2 columns, depending on:
//! - Control characters
//! - ASCII
//! - CJK, Hangul, Kana, fullwidth symbols
//! - Emoji (including ZWJ)
//!
//! Feature `policy` enables runtime policy customization.
use crateWidthPolicy;
use crateis_cjk;
use crateis_emoji;
use crateis_hangul;
use crateis_kana;
use crateis_fullwidth_punct;
use crateis_fullwidth_variant;
//
// ─── Public API Entrypoints ─────────────────────────────────────────
//
/// Returns the display width of a grapheme cluster for terminal environments.
///
/// This API is always available, and automatically falls back to a built-in strategy
/// if the `policy` feature is not enabled.
///
/// This function determines how many columns a grapheme cluster (i.e., a user-perceived character)
/// occupies when rendered in a monospace terminal or console. It follows Unicode-aware rules with
/// fullwidth handling for East Asian scripts and emoji combinations.
///
/// The evaluation order is carefully structured to minimize misclassification:
///
/// 1. **Control characters** (e.g. `\x01`) → width = `0`
/// 2. **ASCII characters** (<= U+007F) → width = `1`
/// 3. **Fullwidth single characters** (exact match in lookup tables):
/// - CJK Unified Ideographs
/// - Japanese Kana (Hiragana/Katakana)
/// - Hangul syllables
/// - Fullwidth symbol variants (e.g. `A`, `!`)
/// - Fullwidth punctuations (e.g. `。`, `、`)
/// → width = `2`
/// 4. **Emoji** (including multi-codepoint ZWJ sequences) → width = `2`
///
/// Characters not matching any of the above are treated as width `1`.
///
/// # Arguments
///
/// * `s` - A string slice, typically one grapheme cluster (`&str`)
///
/// # Returns
///
/// A `usize` indicating the display width: `0`, `1`, or `2`.
///
/// # Example (internal usage only)
///
/// ```rust,ignore
/// // Example usage:
/// // Widths follow terminal-style behavior (CJK = 2, emoji = 2)
/// assert_eq!(get_display_width("R"), 1);
/// assert_eq!(get_display_width("語"), 2);
/// assert_eq!(get_display_width("🦀"), 2);
/// assert_eq!(get_display_width("\x00"), 0);
/// ```
///
/// # Note
///
/// If the `policy` feature is enabled, prefer using [`get_display_width_with_policy()`]
/// instead of [`get_display_width()`] to apply environment-specific width rules.
pub
/// Returns the display width of a grapheme cluster using [`WidthPolicy::terminal()`].
///
/// Requires `policy` feature.
pub
/// Grapheme width lookup using a custom width policy.
///
/// Requires enabling `--features policy`.
///
/// # Parameters
/// - `s`: grapheme cluster (as `&str`)
/// - `policy`: custom `WidthPolicy`, or fallback to `.terminal()` if `None`
///
/// # Use Case
/// Supports runtime customization of width behavior,
/// enabling environment-specific layout strategies (e.g. markdown, TUI, logs).
///
/// # Returns
/// - width = `0`, `1`, or `2`
///
/// # Strategy
/// - Each rule uses `policy.cjk`, `policy.emoji`, `policy.variant`, etc.
//
// ─── Width Resolution for Policy (Feature = "policy") ──────────────
//
//
// ─── Internal Fallback (No Policy) ─────────────────────────────────
//
/// Internal default width resolver used when `policy` is disabled.
;