-module(glint@internal@utils). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([max_string_length/1, wordwrap/2]). -spec max_string_length(list(binary())) -> integer(). max_string_length(Strings) -> gleam@list:fold(Strings, 0, fun(Max, F) -> _pipe = F, _pipe@1 = gleam@string:length(_pipe), gleam@int:max(_pipe@1, Max) end). -spec do_wordwrap(list(binary()), integer(), binary(), list(binary())) -> list(binary()). do_wordwrap(Tokens, Max_width, Line, Lines) -> case Tokens of [Token | Tokens@1] -> Token_length = gleam@string:length(Token), Line_length = gleam@string:length(Line), case {Line, ((Line_length + 1) + Token_length) =< Max_width} of {<<""/utf8>>, _} -> do_wordwrap(Tokens@1, Max_width, Token, Lines); {_, true} -> do_wordwrap( Tokens@1, Max_width, <<<>/binary, Token/binary>>, Lines ); {_, false} -> do_wordwrap(Tokens@1, Max_width, Token, [Line | Lines]) end; [] when Line =:= <<""/utf8>> -> lists:reverse(Lines); [] -> lists:reverse([Line | Lines]) end. -spec wordwrap(binary(), integer()) -> list(binary()). wordwrap(S, Max_width) -> gleam@list:flat_map( gleam@string:split(S, <<"\n"/utf8>>), fun(Line) -> _pipe = Line, _pipe@1 = gleam@string:split(_pipe, <<" "/utf8>>), do_wordwrap(_pipe@1, Max_width, <<""/utf8>>, []) end ).