Function rustkorean::classify_korean
source · pub fn classify_korean(character: char) -> KoreanTypeExpand description
Classifies a given Hangul character into one of the defined Hangul types.
§Arguments
character- Acharrepresenting a single Hangul character.
§Returns
A HangulType indicating the classified type of the Hangul character.
§Examples
use rustkorean::{classify_korean, KoreanType};
assert_eq!(classify_korean('ㄱ'), KoreanType::Consonant);
assert_eq!(classify_korean('ㅏ'), KoreanType::Vowel);
assert_eq!(classify_korean('ㄲ'), KoreanType::ComplexConsonant);
assert_eq!(classify_korean('ㅐ'), KoreanType::ComplexVowel);
assert_eq!(classify_korean('x'), KoreanType::Unknown); // Non-Hangul exampleExamples found in repository?
examples/rustkorean_examples.rs (line 45)
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
fn main() {
// example of check korean
let korean_char = '한';
let non_korean_char = 'A';
println!("Is '{}' a Korean character? {}", korean_char, check_korean(korean_char));
println!("Is '{}' a Korean character? {}", non_korean_char, check_korean(non_korean_char));
// example of syllable_check
let examples = vec!['ㄱ', 'ㅏ', 'ㅣ', '1', 'a', 'ㄳ'];
for &example in &examples {
let syllable_type = syllable_check(example);
println!("{:?} is {:?}", example, syllable_type);
}
//example of first_letter_check, middle_letter_check, last_letter_check
let first_letter = 'ㄱ';
let middle_letter = 'ㅏ';
let last_letter = 'ㅎ';
let not_korean_letter = 'A';
if first_letter_check(first_letter) {
println!("'{}' is first letter.", first_letter);
}
if middle_letter_check(middle_letter) {
println!("'{}' is middle letter.", middle_letter);
}
if last_letter_check(last_letter) {
println!("'{}' is last_letter.", last_letter);
}
if !first_letter_check(not_korean_letter) && !middle_letter_check(not_korean_letter) && !last_letter_check(not_korean_letter) {
println!("'{}' is not_korean_letter.", not_korean_letter);
}
// example of classify_korean
let characters = vec!['ㄱ', 'ㅏ', 'ㄲ', 'ㅐ', 'x'];
for &char in &characters {
let korean_type = classify_korean(char);
println!("{:?} is classified as {:?}", char, korean_type);
}
}