From 96367559f0495919831e0694a46cad3874c52ac4 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 11 Jun 2013 23:52:51 +0200 Subject: numerous small bugfixes --- src/rlx_util.erl | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/rlx_util.erl') diff --git a/src/rlx_util.erl b/src/rlx_util.erl index c2b2081..ac6af5c 100644 --- a/src/rlx_util.erl +++ b/src/rlx_util.erl @@ -24,6 +24,7 @@ -export([mkdir_p/1, to_binary/1, to_string/1, + to_atom/1, is_error/1, error_reason/1, indent/1, @@ -59,6 +60,7 @@ to_binary(String) when erlang:is_list(String) -> to_binary(Bin) when erlang:is_binary(Bin) -> Bin. +-spec to_string(binary() | string() | atom()) -> string(). to_string(Binary) when erlang:is_binary(Binary) -> erlang:binary_to_list(Binary); to_string(Atom) when erlang:is_atom(Atom) -> @@ -66,6 +68,17 @@ to_string(Atom) when erlang:is_atom(Atom) -> to_string(Else) when erlang:is_list(Else) -> Else. +-spec to_atom(atom() | string() | binary()) -> atom(). +to_atom(Binary) + when erlang:is_binary(Binary) -> + erlang:list_to_atom(to_string(Binary)); +to_atom(String) + when erlang:is_list(String) -> + erlang:list_to_atom(String); +to_atom(Atom) + when erlang:is_atom(Atom) -> + Atom. + %% @doc get the reason for a particular relx error -spec error_reason(relx:error()) -> any(). error_reason({error, {_, Reason}}) -> -- cgit v1.2.3