-module(internal@regexing). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([glingify_by_regex/3]). -spec glingify_by_regex(binary(), binary(), fun((binary()) -> binary())) -> binary(). glingify_by_regex(Str, Re_str, Glingify_word_fn) -> _assert_subject = gleam@regex:from_string(Re_str), {ok, Re} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail, module => <<"internal/regexing"/utf8>>, function => <<"glingify_by_regex"/utf8>>, line => 15}) end, _pipe = gleam@regex:scan(Re, Str), gleam@list:fold( _pipe, <<""/utf8>>, fun(Str@1, M) -> New_str = case M of {match, _, [{some, Word}, {some, Nonword}]} -> gleam@string:append(Glingify_word_fn(Word), Nonword); {match, _, [{some, Word@1}, none]} -> Glingify_word_fn(Word@1); {match, _, [none, {some, Nonword@1}]} -> Nonword@1; {match, _, [none, none]} -> <<""/utf8>>; {match, _, []} -> <<""/utf8>>; _ -> erlang:error(#{gleam_error => panic, message => <<"regex did not match exactly two groups"/utf8>>, module => <<"internal/regexing"/utf8>>, function => <<"glingify_by_regex"/utf8>>, line => 25}) end, gleam@string:append(Str@1, New_str) end ).