25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Enforce module_name/1

This commit is contained in:
Christophe Romain 2017-10-31 12:06:40 +01:00
parent e697a3e262
commit e24e05c6af

View File

@ -157,11 +157,20 @@ module_name([Dir, _, <<H,_/binary>> | _] = Mod) when H >= 65, H =< 90 ->
end,
misc:binary_to_atom(<<Prefix/binary, Module/binary>>);
module_name([<<"ejabberd">> | _] = Mod) ->
misc:binary_to_atom(str:join(Mod,$_));
Module = str:join([erlang_name(M) || M<-Mod], $_),
misc:binary_to_atom(Module);
module_name(Mod) when is_list(Mod) ->
misc:binary_to_atom(str:join(tl(Mod),$_)).
Module = str:join([erlang_name(M) || M<-tl(Mod)], $_),
misc:binary_to_atom(Module).
elixir_name(Atom) when is_atom(Atom) ->
elixir_name(misc:atom_to_binary(Atom));
elixir_name(<<H,T/binary>>) when H >= 65, H =< 90 ->
<<H, T/binary>>;
elixir_name(<<H,T/binary>>) ->
<<(H-32), T/binary>>.
erlang_name(Atom) when is_atom(Atom) ->
misc:atom_to_binary(Atom);
erlang_name(Bin) when is_binary(Bin) ->
Bin.