hanguleam/batchim
Types
pub type BatchimError {
EmptyString
InvalidCharacter(String)
}
Constructors
-
EmptyString -
InvalidCharacter(String)
pub type BatchimOnlyFilter {
SingleOnly
DoubleOnly
}
Constructors
-
SingleOnly -
DoubleOnly
pub type HasBatchimOptions {
HasBatchimOptions(only: BatchimOnlyFilter)
AnyBatchim
}
Constructors
-
HasBatchimOptions(only: BatchimOnlyFilter) -
AnyBatchim
Values
pub fn get_batchim(
text: String,
) -> Result(types.BatchimInfo, BatchimError)
Extracts detailed batchim information from the last character of a Korean string.
Returns comprehensive information about the batchim including its type and components.
This is an enhanced version that provides more detail than has_batchim.
Return Value
Ok(BatchimInfo): Contains character, batchim type, and component breakdownError(EmptyString): Input string is emptyError(InvalidCharacter(char)): Last character is not complete Hangul
Examples
get_batchim("강")
// -> Ok(BatchimInfo(character: "강", batchim_type: Single, components: ["ㅇ"]))
get_batchim("값")
// -> Ok(BatchimInfo(character: "값", batchim_type: Double, components: ["ㅂ", "ㅅ"]))
get_batchim("가")
// -> Ok(BatchimInfo(character: "가", batchim_type: NoBatchim, components: []))
get_batchim("hello")
// -> Error(InvalidCharacter("o"))
get_batchim("")
// -> Error(EmptyString)
get_batchim("한글")
// -> Ok(BatchimInfo(character: "글", batchim_type: Single, components: ["ㄹ"]))
pub fn has_batchim(text: String) -> Bool
Checks if the last character of a Korean string has a batchim (final consonant).
Returns False for empty strings, non-Korean characters, or incomplete Hangul.
Examples
has_batchim("값")
// -> True
has_batchim("토")
// -> False
has_batchim("hello")
// -> False
pub fn has_batchim_with_options(
text: String,
options options: HasBatchimOptions,
) -> Bool
Checks if the last character of a Korean string has a batchim (final consonant) with filtering options.
Returns False for empty strings, non-Korean characters, or incomplete Hangul.
Options
AnyBatchim: Checks for any batchim (single or double)HasBatchimOptions(only: SingleOnly): Only single batchimHasBatchimOptions(only: DoubleOnly): Only double batchim
Examples
import hanguleam/batchim.{AnyBatchim, HasBatchimOptions, SingleOnly, DoubleOnly}
has_batchim_with_options("값", AnyBatchim)
// -> True
has_batchim_with_options("갑", HasBatchimOptions(only: SingleOnly))
// -> True
has_batchim_with_options("값", HasBatchimOptions(only: SingleOnly))
// -> False (값 has double batchim ㅂ+ㅅ)
has_batchim_with_options("값", HasBatchimOptions(only: DoubleOnly))
// -> True