浏览代码

Smarter doublequote stripping when printing strings with ~s

pull/12/head
Andrew Thompson 13 年前
父节点
当前提交
a0440a9d60
共有 1 个文件被更改,包括 14 次插入2 次删除
  1. +14
    -2
      src/lager_trunc_io.erl

+ 14
- 2
src/lager_trunc_io.erl 查看文件

@ -101,8 +101,14 @@ format([[$~|H]| T], [AH | AT], Max, Acc, ArgAcc) when length(H) == 1 ->
{String, Length} -> {String, Length} ->
{Value, RealLen} = case H of {Value, RealLen} = case H of
"s" -> "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} {String, Length}
end, end,
@ -428,4 +434,10 @@ sane_float_printing_test() ->
?assertEqual("0.1234567", lists:flatten(format("~p", [0.1234567], 50))), ?assertEqual("0.1234567", lists:flatten(format("~p", [0.1234567], 50))),
ok. 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. -endif.

正在加载...
取消
保存