[−][src]Trait hangul::HangulExt
Extension trait to define additional methods on primitive type char
.
Required methods
fn is_syllable(self) -> bool
fn is_open(self) -> Result<bool, ParseSyllableError>
fn is_closed(self) -> Result<bool, ParseSyllableError>
fn choseong(self) -> Result<char, ParseSyllableError>
fn jungseong(self) -> Result<char, ParseSyllableError>
fn jongseong(self) -> Result<Option<char>, ParseSyllableError>
fn to_jamo(self) -> Result<(char, char, Option<char>), ParseSyllableError>
fn jamos(self) -> Result<Jamos, ParseSyllableError>
Implementations on Foreign Types
impl HangulExt for char
[src]
fn is_syllable(self) -> bool
[src]
Tests whether the char
is a Hangul syllable.
Example
use hangul::HangulExt; assert_eq!('냐'.is_syllable(), true); assert_eq!('猫'.is_syllable(), false); // 猫 is a Chinese character
fn is_open(self) -> Result<bool, ParseSyllableError>
[src]
Tests whether char
is an open syllable, i.e., doesn't have jongseong.
Errors
If it's not a syllable, returns ParseSyllableError
.
use hangul::{HangulExt, ParseSyllableError}; assert!('Ж'.is_open().is_err(), "`Ж` is not a Hangul Syllable"); // Ж is a Cyrillic alphabet
Example
use hangul::HangulExt; assert_eq!('해'.is_open().unwrap(), true); // 해 is open because it doesn't have any jongseong. assert_eq!('달'.is_open().unwrap(), false); // 달 is open because it has a jongseong ㄹ.
fn is_closed(self) -> Result<bool, ParseSyllableError>
[src]
Tests whether char
is a closed syllable, i.e., has jongseong.
Errors
If it's not a syllable, returns ParseSyllableError
.
use hangul::{HangulExt, ParseSyllableError}; assert!('א'.is_closed().is_err(), "`א` is not a Hangul Syllable"); // א is a Hebrew alphabet
Example
use hangul::HangulExt; assert_eq!('물'.is_closed().unwrap(), true); // 물 is closed because it has a jongseong ㄹ. assert_eq!('무'.is_closed().unwrap(), false); // 무 is open because it doesn't have any jongseong.
fn choseong(self) -> Result<char, ParseSyllableError>
[src]
Returns compatibility jamo choseong of a given char
.
Errors
If it's not a syllable, returns ParseSyllableError
.
use hangul::{HangulExt, ParseSyllableError}; assert!('🥑'.choseong().is_err(), "`🥑` is not a Hangul Syllable");
Examples
use hangul::HangulExt; assert_eq!('항'.choseong().unwrap(), 'ㅎ');
Note that compatibility jamo is different from jamo. This crate only deals with the compatibility jamo.
use hangul::HangulExt; // Jamo let p = 'ᄑ'; assert_eq!(p as u32, 0x1111); // Compatibility jamo let p_compat = '푸'.choseong().unwrap(); assert_eq!(p_compat, 'ㅍ'); assert_eq!(p_compat as u32, 0x314D); assert_ne!(p_compat, p);
fn jungseong(self) -> Result<char, ParseSyllableError>
[src]
Returns compatibility jamo jungseong of a given char
.
Errors
If it's not a syllable, returns ParseSyllableError
.
use hangul::{HangulExt, ParseSyllableError}; assert!('L'.jungseong().is_err(), "`L` is not a Hangul Syllable");
Examples
use hangul::HangulExt; assert_eq!('괴'.jungseong().unwrap(), 'ㅚ');
Note that compatibility jamo is different from jamo. This crate only deals with the compatibility jamo.
use hangul::HangulExt; // Jamo let u = 'ᅲ'; assert_eq!(u as u32, 0x1172); // Compatibility jamo let u_compat = '퓨'.jungseong().unwrap(); assert_eq!(u_compat, 'ㅠ'); assert_eq!(u_compat as u32, 0x3160); assert_ne!(u_compat, u);
fn jongseong(self) -> Result<Option<char>, ParseSyllableError>
[src]
Returns Option
of a compatibility jamo jongseong of a given char
.
Errors
If it's not a syllable, returns ParseSyllableError
.
use hangul::{HangulExt, ParseSyllableError}; assert!('か'.jongseong().is_err(), "`か` is not a Hangul Syllable"); // か is a katakana
Examples
use hangul::HangulExt; assert_eq!('말'.jongseong().unwrap(), Some('ㄹ')); assert_eq!('소'.jongseong().unwrap(), None);
Note that compatibility jamo is different from jamo. This crate only deals with the compatibility jamo.
use hangul::HangulExt; // Jamo let rg = 'ᆰ'; assert_eq!(rg as u32, 0x11B0); // Compatibility jamo let rg_compat = '닭'.jongseong().unwrap().unwrap(); assert_eq!(rg_compat, 'ㄺ'); assert_eq!(rg_compat as u32, 0x313A); assert_ne!(rg_compat, rg);
fn to_jamo(self) -> Result<(char, char, Option<char>), ParseSyllableError>
[src]
Examples
use hangul::{HangulExt, ParseSyllableError}; assert_eq!('결'.to_jamo(), Ok(('ㄱ', 'ㅕ', Some('ㄹ')))); assert_eq!('씨'.to_jamo(), Ok(('ㅆ', 'ㅣ', None))); assert!('a'.to_jamo().is_err(), "`a` is not a Hangul Syllable");
fn jamos(self) -> Result<Jamos, ParseSyllableError>
[src]
Returns an iterator over the jamos of the syllable.
Errors
If given char
is not a syllable, returns ParseSyllableError
.
use hangul::{HangulExt, ParseSyllableError}; assert!('K'.jamos().is_err(), "`K` is not a Hangul Syllable");
Examples
Basic usage:
use hangul::{HangulExt}; let mut jamos = '활'.jamos().unwrap(); assert_eq!(jamos.next(), Some('ㅎ')); assert_eq!(jamos.next(), Some('ㅘ')); assert_eq!(jamos.next(), Some('ㄹ')); assert_eq!(jamos.next(), None);
You can use it with iterator
methods like flat_map
or fold
to decompose Hangul String.
use hangul::{HangulExt}; assert_eq!( "첫사랑" .chars() .flat_map(|c| c.jamos().unwrap()) .collect::<String>(), "ㅊㅓㅅㅅㅏㄹㅏㅇ" ); assert_eq!( "첫사랑은 두 번 다시 겪을 수 없다." .chars() .fold("".to_owned(), |acc, c| acc + &c .jamos() .map(|j| j.collect::<String>()) .unwrap_or(c.to_string())), "ㅊㅓㅅㅅㅏㄹㅏㅇㅇㅡㄴ ㄷㅜ ㅂㅓㄴ ㄷㅏㅅㅣ ㄱㅕㄲㅇㅡㄹ ㅅㅜ ㅇㅓㅄㄷㅏ." );