Skip to content

Commit

Permalink
Merge pull request #12 from basho/adt-fix-print-bugs
Browse files Browse the repository at this point in the history
Adt fix print bugs
  • Loading branch information
Vagabond committed Aug 30, 2011
2 parents dadd0cf + 0cc9e25 commit 4cfa3ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
29 changes: 23 additions & 6 deletions src/lager_trunc_io.erl
Expand Up @@ -101,8 +101,14 @@ format([[$~|H]| T], [AH | AT], Max, Acc, ArgAcc) when length(H) == 1 ->
{String, Length} ->
{Value, RealLen} = case H of
"s" ->
% strip off the doublequotes
{string:substr(String, 2, length(String) -2), Length -2};
% strip off the doublequotes, if applicable
Trimmed = case {hd(String), lists:last(String)} == {$", $"} of
true ->
string:strip(String, both, $");
_ ->
String
end,
{Trimmed, length(Trimmed)};
_ ->
{String, Length}
end,
Expand Down Expand Up @@ -303,10 +309,10 @@ list_bodyc(X,Max) -> %% improper list
%%
alist_start([], _) -> {"[]", 2};
alist_start(_, Max) when Max < 4 -> {"...", 3};
alist_start([H|T], Max) when H >= 16#20, H =< 16#7e -> % definitely printable
alist_start([H|T], Max) when is_integer(H), H >= 16#20, H =< 16#7e -> % definitely printable
{L, Len} = alist([H|T], Max-1),
{[$"|L], Len + 1};
alist_start([H|T], Max) when H == 9; H == 10; H == 13 -> % show as space
alist_start([H|T], Max) when H =:= 9; H =:= 10; H =:= 13 -> % show as space
{L, Len} = alist(T, Max-1),
{[$ |L], Len + 1};
alist_start(L, Max) ->
Expand All @@ -315,10 +321,10 @@ alist_start(L, Max) ->

alist([], _) -> {"\"", 1};
alist(_, Max) when Max < 5 -> {"...\"", 4};
alist([H|T], Max) when H >= 16#20, H =< 16#7e -> % definitely printable
alist([H|T], Max) when is_integer(H), H >= 16#20, H =< 16#7e -> % definitely printable
{L, Len} = alist(T, Max-1),
{[H|L], Len + 1};
alist([H|T], Max) when H == 9; H == 10; H == 13 -> % show as space
alist([H|T], Max) when H =:= 9; H =:= 10; H =:= 13 -> % show as space
{L, Len} = alist(T, Max-1),
{[$ |L], Len + 1};
alist(L, Max) ->
Expand Down Expand Up @@ -428,4 +434,15 @@ sane_float_printing_test() ->
?assertEqual("0.1234567", lists:flatten(format("~p", [0.1234567], 50))),
ok.

float_inside_list_test() ->
?assertEqual("\"a\"[38.233913133184835,99]", lists:flatten(format("~p", [[$a, 38.233913133184835, $c]], 50))),
?assertEqual("\"a\"[38.233913133184835,99]", lists:flatten(format("~s", [[$a, 38.233913133184835, $c]], 50))),
ok.

quote_strip_test() ->
?assertEqual("\"hello\"", lists:flatten(format("~p", ["hello"], 50))),
?assertEqual("hello", lists:flatten(format("~s", ["hello"], 50))),
?assertEqual("hello", lists:flatten(format("~s", [hello], 50))),
?assertEqual("hello", lists:flatten(format("~p", [hello], 50))),
ok.
-endif.
1 change: 0 additions & 1 deletion test/lager_test_backend.erl
Expand Up @@ -647,7 +647,6 @@ error_logger_redirect_test_() ->
safe_format_test() ->
?assertEqual("foo bar", lists:flatten(lager:safe_format("~p ~p", [foo, bar], 1024))),
?assertEqual("FORMAT ERROR: \"~p ~p ~p\" [foo,bar]", lists:flatten(lager:safe_format("~p ~p ~p", [foo, bar], 1024))),
?assertEqual("FORMAT ERROR: \"~s\" [1]", lists:flatten(lager:safe_format("~s", [1], 1024))),
ok.

-endif.
Expand Down

0 comments on commit 4cfa3ee

Please sign in to comment.