diff options
author | Paul Joseph Davis <davisp@apache.org> | 2009-06-25 03:59:47 +0000 |
---|---|---|
committer | Paul Joseph Davis <davisp@apache.org> | 2009-06-25 03:59:47 +0000 |
commit | c3437ff4648454607e17c7356536e857dfe87ae1 (patch) | |
tree | 0e4f914b8fedaf6dc92c578084ffa1628b2e3e34 /src/couchdb/couch_util.erl | |
parent | c3c51fae0ccec121b4dfbc37d6baefd64e2631c7 (diff) |
Adding tests for couch_task_status.erl
Thanks Bob Dionne
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@788246 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_util.erl')
-rw-r--r-- | src/couchdb/couch_util.erl | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index 0a715520..1a2929e4 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -13,11 +13,12 @@ -module(couch_util). -export([start_driver/1,terminate_linked/1]). --export([should_flush/0, should_flush/1, to_existing_atom/1, to_binary/1]). +-export([should_flush/0, should_flush/1, to_existing_atom/1]). -export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]). -export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]). -export([encodeBase64/1, decodeBase64/1, to_hex/1,parse_term/1,dict_find/3]). -export([file_read_size/1]). +-export([to_binary/1, to_list/1]). -include("couch_db.hrl"). -include_lib("kernel/include/file.hrl"). @@ -67,19 +68,6 @@ to_digit(N) when N < 10 -> $0 + N; to_digit(N) -> $a + N-10. -to_binary(V) when is_binary(V) -> - V; -to_binary(V) when is_list(V) -> - try list_to_binary(V) - catch - _ -> list_to_binary(io_lib:format("~p", [V])) - end; -to_binary(V) when is_atom(V) -> - list_to_binary(atom_to_list(V)); -to_binary(V) -> - list_to_binary(io_lib:format("~p", [V])). - - parse_term(Bin) when is_binary(Bin)-> parse_term(binary_to_list(Bin)); parse_term(List) -> @@ -301,3 +289,26 @@ file_read_size(FileName) -> FileInfo#file_info.size; Error -> Error end. + +to_binary(V) when is_binary(V) -> + V; +to_binary(V) when is_list(V) -> + try + list_to_binary(V) + catch + _ -> + list_to_binary(io_lib:format("~p", [V])) + end; +to_binary(V) when is_atom(V) -> + list_to_binary(atom_to_list(V)); +to_binary(V) -> + list_to_binary(io_lib:format("~p", [V])). + +to_list(V) when is_list(V) -> + V; +to_list(V) when is_binary(V) -> + binary_to_list(V); +to_list(V) when is_atom(V) -> + atom_to_list(V); +to_list(V) -> + lists:flatten(io_lib:format("~p", [V])). |