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
//! The Unicode `East_Asian_Width` property (UAX #11).
/// The `East_Asian_Width` of a codepoint (UAX #11).
///
/// Codepoints that are unassigned — or that fall outside the compiled range
/// tier — report [`EastAsianWidth::Neutral`], the property's default value.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum EastAsianWidth {
/// `N` — Neutral (non-East-Asian; also the default).
Neutral = 0,
/// `A` — Ambiguous (width depends on context).
Ambiguous,
/// `H` — Halfwidth.
Halfwidth,
/// `W` — Wide.
Wide,
/// `F` — Fullwidth.
Fullwidth,
/// `Na` — Narrow.
Narrow,
}
impl EastAsianWidth {
/// The property-value abbreviation, e.g. `"W"` for [`EastAsianWidth::Wide`].
#[inline]
#[must_use]
pub const fn abbr(self) -> &'static str {
match self {
EastAsianWidth::Neutral => "N",
EastAsianWidth::Ambiguous => "A",
EastAsianWidth::Halfwidth => "H",
EastAsianWidth::Wide => "W",
EastAsianWidth::Fullwidth => "F",
EastAsianWidth::Narrow => "Na",
}
}
/// `true` if this width is rendered as two columns in a typical fixed-width
/// East-Asian context: [`Wide`](EastAsianWidth::Wide) or
/// [`Fullwidth`](EastAsianWidth::Fullwidth).
///
/// [`Ambiguous`](EastAsianWidth::Ambiguous) is *not* counted as wide here;
/// its width is context-dependent and the caller must decide.
#[inline]
#[must_use]
pub const fn is_wide(self) -> bool {
matches!(self, EastAsianWidth::Wide | EastAsianWidth::Fullwidth)
}
}
/// The [`EastAsianWidth`] of `c`.
#[inline]
#[must_use]
pub const fn east_asian_width(c: char) -> EastAsianWidth {
super::generated::east_asian_width::east_asian_width(c as u32)
}
/// The [`EastAsianWidth`] of an arbitrary Unicode scalar value.
#[inline]
#[must_use]
pub const fn east_asian_width_u32(cp: u32) -> EastAsianWidth {
super::generated::east_asian_width::east_asian_width(cp)
}