Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation in bopomofo module #582

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 64 additions & 49 deletions src/zhuyin/bopomofo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,94 +27,92 @@ pub enum BopomofoKind {

/// Zhuyin Fuhao, often shortened as zhuyin and commonly called bopomofo
///
/// TODO: refactor this to not use enum?
///
/// <https://simple.m.wikipedia.org/wiki/Zhuyin>
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Bopomofo {
/// ㄅ
/// Zhuyin Fuhao:
B,
/// ㄆ
/// Zhuyin Fuhao:
P,
/// ㄇ
/// Zhuyin Fuhao:
M,
/// ㄈ
/// Zhuyin Fuhao:
F,
/// ㄉ
/// Zhuyin Fuhao:
D,
/// ㄊ
/// Zhuyin Fuhao:
T,
/// ㄋ
/// Zhuyin Fuhao:
N,
/// ㄌ
/// Zhuyin Fuhao:
L,
/// ㄍ
/// Zhuyin Fuhao:
G,
/// ㄎ
/// Zhuyin Fuhao:
K,
/// ㄏ
/// Zhuyin Fuhao:
H,
/// ㄐ
/// Zhuyin Fuhao:
J,
/// ㄑ
/// Zhuyin Fuhao:
Q,
/// ㄒ
/// Zhuyin Fuhao:
X,
/// ㄓ
/// Zhuyin Fuhao:
ZH,
/// ㄔ
/// Zhuyin Fuhao:
CH,
/// ㄕ
/// Zhuyin Fuhao:
SH,
/// ㄖ
/// Zhuyin Fuhao:
R,
/// ㄗ
/// Zhuyin Fuhao:
Z,
/// ㄘ
/// Zhuyin Fuhao:
C,
/// ㄙ
/// Zhuyin Fuhao:
S,
/// 一
/// Zhuyin Fuhao:
I,
/// ㄨ
/// Zhuyin Fuhao:
U,
/// ㄩ
/// Zhuyin Fuhao:
IU,
/// ㄚ
/// Zhuyin Fuhao:
A,
/// ㄛ
/// Zhuyin Fuhao:
O,
/// ㄜ
/// Zhuyin Fuhao:
E,
/// ㄝ
/// Zhuyin Fuhao:
EH,
/// ㄞ
/// Zhuyin Fuhao:
AI,
/// ㄟ
/// Zhuyin Fuhao:
EI,
/// ㄠ
/// Zhuyin Fuhao:
AU,
/// ㄡ
/// Zhuyin Fuhao:
OU,
/// ㄢ
/// Zhuyin Fuhao:
AN,
/// ㄣ
/// Zhuyin Fuhao:
EN,
/// ㄤ
/// Zhuyin Fuhao:
ANG,
/// ㄥ
/// Zhuyin Fuhao:
ENG,
/// ㄦ
/// Zhuyin Fuhao:
ER,
/// ˙
/// Tonal mark: ˙
TONE5,
/// ˊ
/// Tonal mark: ˊ
TONE2,
/// ˇ
/// Tonal mark: ˇ
TONE3,
/// ˋ
/// Tonal mark: ˋ
TONE4,
/// ˉ
/// Tonal mark: ˉ
TONE1,
}

Expand All @@ -128,7 +126,8 @@ const RIME_MAP: [Bopomofo; 13] = [A, O, E, EH, AI, EI, AU, OU, AN, EN, ANG, ENG,
const TONE_MAP: [Bopomofo; 4] = [TONE5, TONE2, TONE3, TONE4];

impl Bopomofo {
/// TODO: docs
/// Returns [`BopomofoKind`] of the [`Bopomofo`] symbol. See [`BopomofoKind`] to know more about
/// each kind category.
pub const fn kind(&self) -> BopomofoKind {
match self {
B | P | M | F | D | T | N | L | G | K | H | J | Q | X | ZH | CH | SH | R | Z | C
Expand All @@ -138,28 +137,44 @@ impl Bopomofo {
TONE1 | TONE2 | TONE3 | TONE4 | TONE5 => BopomofoKind::Tone,
}
}
/// TODO: docs
/// Returns a [`Bopomofo`] that is categorized as initial sounds based on the index. It will
/// return [`None`] if the index is larger than 20. The index order is listed below starting
/// from 0.
///
/// - Initial sounds: ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙ
pub(super) const fn from_initial(index: u16) -> Option<Bopomofo> {
if index as usize >= INITIAL_MAP.len() {
return None;
}
Some(INITIAL_MAP[index as usize])
}
/// TODO: docs
/// Returns a [`Bopomofo`] that is categorized as medial glides based on the index. It will
/// return [`None`] if the index is larger than 2. The index order is listed below starting
/// from 0.
///
/// - Medial glides: ㄧㄨㄩ
pub(super) const fn from_medial(index: u16) -> Option<Bopomofo> {
if index as usize >= MEDIAL_MAP.len() {
return None;
}
Some(MEDIAL_MAP[index as usize])
}
/// TODO: docs
/// Returns a [`Bopomofo`] that is categorized as rimes based on the index. It will
/// return [`None`] if the index is larger than 12. The index order is listed below starting
/// from 0.
///
/// - Rimes: ㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦ
pub(super) const fn from_rime(index: u16) -> Option<Bopomofo> {
if index as usize >= RIME_MAP.len() {
return None;
}
Some(RIME_MAP[index as usize])
}
/// TODO: docs
/// Returns a [`Bopomofo`] that is categorized as tonal marks based on the index. It will
/// return [`None`] if the index is larger than 3. The index order is listed below starting
/// from 0.
///
/// - Tonal marks: ˙ˊˇˋ
pub(super) const fn from_tone(index: u16) -> Option<Bopomofo> {
if index as usize >= TONE_MAP.len() {
return None;
Expand Down