-module(bucbinary). -export([ join/2, trim/2 ]). %% @doc %% join a list of binaries with the given separator %% %% Example: %% %%
%% <<"toto-tata-titi">> = bucbinary:join([<<"toto">>, <<"tata">>, <<"titi">>], <<"-">>).
%%
%% @end
-spec join([binary()], binary()) -> binary().
join([], _) ->
<<>>;
join([Bin], _) when is_binary(Bin) ->
Bin;
join(List, Sep) when is_list(List), is_binary(Sep) ->
lists:foldr(fun
(<<>>, <<>>) -> <<>>;
(A, <<>>) -> A;
(<<>>, B) -> B;
(A, B) -> <>
end, <<>>, List);
join(Bin, _) when is_binary(Bin) ->
Bin.
- spec trim(binary(), left | right | both) -> binary().
trim(Binary, left) ->
trim_left(Binary);
trim(Binary, right) ->
trim_right(Binary);
trim(Binary, both) ->
trim_left(trim_right(Binary)).
trim_left(<