A lightweight Korean alphabet manipulation library for Rust. No external crates are used.
Only modern, composable Korean unicode blocks are supported (AC00
βD7AF
, 1100
β11FF
, 3130
β318F
).
[dependencies]
hangeul = "0.4.0"
extern crate hangeul;
fn main() {
// literally: pikachu transliterated
let subject = "νΌμΉ΄μΈ";
// Korean marks the topic of the sentence with a post position
// particle: μ΄ follows consonants, and κ° follows vowels.
let post_position = match hangeul::ends_in_consonant(subject).unwrap() {
true => "μ΄",
false => "κ°"
};
// -> A wild pikachu has appeared!
let sentence = format!("μΌμμ {}{} λνλ¬λ€!", subject, post_position);
println!("{}", sentence); // μΌμμ νΌμΉ΄μΈκ° λνλ¬λ€!
// get_lead is an alias of get_choseong, to get the first character
// of a Hangeul syllable.
let sentence_in_choseong = sentence.chars()
.map(|c| hangeul::get_lead(&c).unwrap_or(c))
.collect::<String>();
println!("{}", sentence_in_choseong); // γ
γ
γ
γ
γ
γ
γ± γ΄γ
γ΄γ·!
}
Distributed under MIT License