aboutsummaryrefslogtreecommitdiffstats
path: root/src/rcl_util.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rcl_util.erl')
-rw-r--r--src/rcl_util.erl28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/rcl_util.erl b/src/rcl_util.erl
index f6427ae..61e1392 100644
--- a/src/rcl_util.erl
+++ b/src/rcl_util.erl
@@ -1,4 +1,4 @@
-%% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*-
+%% -*- erlang-indent-level: 4; indent-tabs-mode: nil; fill-column: 80 -*-
%%% Copyright 2012 Erlware, LLC. All Rights Reserved.
%%%
%%% This file is provided to you under the Apache License,
@@ -23,7 +23,11 @@
-export([mkdir_p/1,
to_binary/1,
- indent/1]).
+ to_string/1,
+ is_error/1,
+ error_reason/1,
+ indent/1,
+ optional_to_string/1]).
-define(ONE_LEVEL_INDENT, " ").
%%============================================================================
@@ -54,7 +58,27 @@ to_binary(String) when erlang:is_list(String) ->
erlang:iolist_to_binary(String);
to_binary(Bin) when erlang:is_binary(Bin) ->
Bin.
+to_string(Atom) when erlang:is_atom(Atom) ->
+ erlang:atom_to_list(Atom);
+to_string(Else) when erlang:is_list(Else) ->
+ Else.
+%% @doc get the reason for a particular relcool error
+-spec error_reason(relcool:error()) -> any().
+error_reason({error, {_, Reason}}) ->
+ Reason.
+%% @doc check to see if the value is a relcool error
+-spec is_error(relcool:error() | any()) -> boolean().
+is_error({error, _}) ->
+ true;
+is_error(_) ->
+ false.
+
+%% @doc convert optional argument to empty string if undefined
+optional_to_string(undefined) ->
+ "";
+optional_to_string(Value) when is_list(Value) ->
+ Value.
%%%===================================================================
%%% Test Functions