Current section
Files
Jump to
Current section
Files
src/hanguleam@validator.erl
-module(hanguleam@validator).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/hanguleam/validator.gleam").
-export([can_be_choseong/1, can_be_jungseong/1, can_be_jongseong/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/hanguleam/validator.gleam", 31).
?DOC(
" Checks if a given character can be used as a choseong (initial consonant) in Korean Hangul.\n"
" A choseong is the first consonant in a Korean syllable that appears at the beginning.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" can_be_choseong(\"ㄱ\")\n"
" // -> True\n"
"\n"
" can_be_choseong(\"ㅃ\")\n"
" // -> True\n"
"\n"
" can_be_choseong(\"ㄱㅅ\")\n"
" // -> False (multiple characters)\n"
"\n"
" can_be_choseong(\"ㅏ\")\n"
" // -> False (vowel, not consonant)\n"
"\n"
" can_be_choseong(\"가\")\n"
" // -> False (complete syllable, not individual jamo)\n"
" ```\n"
).
-spec can_be_choseong(binary()) -> boolean().
can_be_choseong(Char) ->
hanguleam@internal@unicode:is_modern_choseong(Char) orelse hanguleam@internal@unicode:is_compatibility_choseong(
Char
).
-file("src/hanguleam/validator.gleam", 60).
?DOC(
" Checks if a given character can be used as a jungseong (medial vowel) in Korean Hangul.\n"
" A jungseong is the vowel that appears in the middle of a Korean syllable.\n"
" This function supports both single vowels and complex vowels (diphthongs).\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" can_be_jungseong(\"ㅏ\")\n"
" // -> True\n"
"\n"
" can_be_jungseong(\"ㅗㅏ\")\n"
" // -> True (complex vowel ㅘ)\n"
"\n"
" can_be_jungseong(\"ㅏㅗ\")\n"
" // -> False (invalid vowel combination)\n"
"\n"
" can_be_jungseong(\"ㄱ\")\n"
" // -> False (consonant, not vowel)\n"
"\n"
" can_be_jungseong(\"ㄱㅅ\")\n"
" // -> False (consonants, not vowel)\n"
"\n"
" can_be_jungseong(\"가\")\n"
" // -> False (complete syllable, not individual jamo)\n"
" ```\n"
).
-spec can_be_jungseong(binary()) -> boolean().
can_be_jungseong(Char) ->
case string:length(Char) of
1 ->
hanguleam@internal@unicode:is_modern_jungseong(Char) orelse hanguleam@internal@unicode:is_compatibility_jungseong(
Char
);
2 ->
_pipe = hanguleam@internal@unicode:assemble_vowel_string(Char),
gleam@list:contains(
[<<"ㅏ"/utf8>>,
<<"ㅐ"/utf8>>,
<<"ㅑ"/utf8>>,
<<"ㅒ"/utf8>>,
<<"ㅓ"/utf8>>,
<<"ㅔ"/utf8>>,
<<"ㅕ"/utf8>>,
<<"ㅖ"/utf8>>,
<<"ㅗ"/utf8>>,
<<"ㅘ"/utf8>>,
<<"ㅙ"/utf8>>,
<<"ㅚ"/utf8>>,
<<"ㅛ"/utf8>>,
<<"ㅜ"/utf8>>,
<<"ㅝ"/utf8>>,
<<"ㅞ"/utf8>>,
<<"ㅟ"/utf8>>,
<<"ㅠ"/utf8>>,
<<"ㅡ"/utf8>>,
<<"ㅢ"/utf8>>,
<<"ㅣ"/utf8>>],
_pipe
);
_ ->
false
end.
-file("src/hanguleam/validator.gleam", 96).
?DOC(
" Checks if a given character can be used as a jongseong (final consonant) in Korean Hangul.\n"
" A jongseong is the final consonant that appears at the end of a Korean syllable.\n"
" This function supports single consonants, double consonants, and empty strings (no final consonant).\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" can_be_jongseong(\"ㄱ\")\n"
" // -> True\n"
"\n"
" can_be_jongseong(\"ㄱㅅ\")\n"
" // -> True (double consonant ㄳ)\n"
"\n"
" can_be_jongseong(\"\")\n"
" // -> True (no final consonant is valid)\n"
"\n"
" can_be_jongseong(\"ㅎㄹ\")\n"
" // -> False (invalid consonant combination)\n"
"\n"
" can_be_jongseong(\"가\")\n"
" // -> False (complete syllable, not individual jamo)\n"
"\n"
" can_be_jongseong(\"ㅏ\")\n"
" // -> False (vowel, not consonant)\n"
"\n"
" can_be_jongseong(\"ㅗㅏ\")\n"
" // -> False (vowels, not consonants)\n"
" ```\n"
).
-spec can_be_jongseong(binary()) -> boolean().
can_be_jongseong(Char) ->
case string:length(Char) of
0 ->
true;
1 ->
hanguleam@internal@unicode:is_modern_jongseong(Char) orelse hanguleam@internal@unicode:is_compatibility_jongseong(
Char
);
2 ->
_pipe = hanguleam@internal@unicode:assemble_consonant_string(Char),
gleam@list:contains(
[<<""/utf8>>,
<<"ㄱ"/utf8>>,
<<"ㄲ"/utf8>>,
<<"ㄳ"/utf8>>,
<<"ㄴ"/utf8>>,
<<"ㄵ"/utf8>>,
<<"ㄶ"/utf8>>,
<<"ㄷ"/utf8>>,
<<"ㄹ"/utf8>>,
<<"ㄺ"/utf8>>,
<<"ㄻ"/utf8>>,
<<"ㄼ"/utf8>>,
<<"ㄽ"/utf8>>,
<<"ㄾ"/utf8>>,
<<"ㄿ"/utf8>>,
<<"ㅀ"/utf8>>,
<<"ㅁ"/utf8>>,
<<"ㅂ"/utf8>>,
<<"ㅄ"/utf8>>,
<<"ㅅ"/utf8>>,
<<"ㅆ"/utf8>>,
<<"ㅇ"/utf8>>,
<<"ㅈ"/utf8>>,
<<"ㅊ"/utf8>>,
<<"ㅋ"/utf8>>,
<<"ㅌ"/utf8>>,
<<"ㅍ"/utf8>>,
<<"ㅎ"/utf8>>],
_pipe
);
_ ->
false
end.