-module(hanguleam@editor). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -define(FILEPATH, "src/hanguleam/editor.gleam"). -export([remove_last_character/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/editor.gleam", 48). -spec disassemble_complete_character(binary()) -> {ok, hanguleam@types:hangul_syllable()} | {error, nil}. disassemble_complete_character(Char) -> case hanguleam@internal@character:get_character_type(Char) of empty -> {error, nil}; non_hangul -> {error, nil}; {incomplete_hangul, _} -> {error, nil}; {complete_hangul, Char@1} -> {ok, Char@1} end. -file("src/hanguleam/editor.gleam", 57). -spec reduce_syllable(hanguleam@types:hangul_character()) -> binary(). reduce_syllable(Disassembled) -> case Disassembled of {simple_c_v, {choseong, Cho}, _} -> Cho; {compound_c_v, {choseong, Cho@1}, {jungseong, Jung}} -> hanguleam@composer:combine_character_unsafe( Cho@1, gleam@string:slice(Jung, 0, 1), <<""/utf8>> ); {simple_c_v_c, {choseong, Cho@2}, {jungseong, Jung@1}, {jongseong, _}} -> hanguleam@composer:combine_character_unsafe( Cho@2, Jung@1, <<""/utf8>> ); {compound_c_v_c, {choseong, Cho@3}, {jungseong, Jung@2}, {jongseong, _}} -> hanguleam@composer:combine_character_unsafe( Cho@3, Jung@2, <<""/utf8>> ); {complex_batchim, {choseong, Cho@4}, {jungseong, Jung@3}, {jongseong, Jong}} -> hanguleam@composer:combine_character_unsafe( Cho@4, Jung@3, gleam@string:slice(Jong, 0, 1) ); {compound_complex_batchim, {choseong, Cho@5}, {jungseong, Jung@4}, {jongseong, Jong@1}} -> hanguleam@composer:combine_character_unsafe( Cho@5, Jung@4, gleam@string:slice(Jong@1, 0, 1) ) end. -file("src/hanguleam/editor.gleam", 37). -spec remove_character_component(binary(), binary()) -> binary(). remove_character_component(Text, Last_char) -> Prefix = gleam@string:drop_end(Text, 1), _pipe = Last_char, _pipe@1 = disassemble_complete_character(_pipe), _pipe@2 = gleam@result:map( _pipe@1, fun hanguleam@internal@character:parse_hangul_syllable/1 ), _pipe@3 = gleam@result:map(_pipe@2, fun reduce_syllable/1), _pipe@4 = gleam@result:unwrap(_pipe@3, <<""/utf8>>), gleam@string:append(Prefix, _pipe@4). -file("src/hanguleam/editor.gleam", 30). ?DOC( " Removes the last character component from a Korean string, intelligently handling Korean syllable decomposition.\n" " This function removes the last \"logical\" character unit from the input string. For complete Korean syllables,\n" " it removes the last jamo component (consonant or vowel part) rather than the entire character, allowing for\n" " fine-grained text editing that matches Korean input method behavior.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " remove_last_character(\"안녕하세요 값\")\n" " // -> \"안녕하세요 갑\"\n" "\n" " remove_last_character(\"전화\")\n" " // -> \"전호\"\n" "\n" " remove_last_character(\"Hello\")\n" " // -> \"Hell\"\n" "\n" " remove_last_character(\"\")\n" " // -> \"\"\n" " ```\n" ). -spec remove_last_character(binary()) -> binary(). remove_last_character(Text) -> case gleam@string:last(Text) of {error, _} -> Text; {ok, Last_char} -> remove_character_component(Text, Last_char) end.