瀏覽代碼

ft:模块融合

master
SisMaker 4 年之前
父節點
當前提交
29222a138e
共有 2 個檔案被更改,包括 27 行新增23 行删除
  1. +23
    -15
      src/eFmt.erl
  2. +4
    -8
      src/eFmtPretty.erl

+ 23
- 15
src/eFmt.erl 查看文件

@ -487,12 +487,12 @@ ctlLimited($s, Args, Width, Adjust, Precision, PadChar, Encoding, _Strings, Char
case Encoding of
latin1 ->
BinStr = erlang:iolist_to_binary(Args);
_ ->
BinStr = case catch unicode:characters_to_binary(Args, unicode) of
Str when is_binary(Str) -> Str;
_ -> toBinary(Args)
end
BinStr =
case catch unicode:characters_to_binary(Args, unicode) of
Str when is_binary(Str) -> Str;
_ -> toBinary(Args)
end
end,
TemBinStr = strToChars(BinStr, Width, CharsLimit),
string(TemBinStr, ?IIF(CharsLimit < 0 orelse Width =:= none, Width, max(3, min(Width, CharsLimit))), Adjust, Precision, PadChar, Encoding);
@ -533,14 +533,21 @@ term(BinStrOrIoList, Width, Adjust, Precision, PadChar) ->
print(Term, Depth, Width, _Adjust, Precision, _PadChar, Encoding, Strings, CharsLimit, I) ->
if
Width == none -> NewWidth = 80;
true -> NewWidth = Width
end,
if
Precision == none -> NewPrecision = I + 1;
true -> NewPrecision = Precision
end,
eFmtPretty:print(Term, NewPrecision, NewWidth, Depth, -1, CharsLimit, no_fun, Encoding, Strings).
Width == none ->
if
Precision == none ->
eFmtPretty:print(Term, I + 1, 80, Depth, -1, CharsLimit, no_fun, Encoding, Strings);
true ->
eFmtPretty:print(Term, Precision, 80, Depth, -1, CharsLimit, no_fun, Encoding, Strings)
end;
true ->
if
Precision == none ->
eFmtPretty:print(Term, I + 1, Width, Depth, -1, CharsLimit, no_fun, Encoding, Strings);
true ->
eFmtPretty:print(Term, Precision, Width, Depth, -1, CharsLimit, no_fun, Encoding, Strings)
end
end.
floatE(Float, Width, Adjust, Precision, PadChar) ->
case Precision of
@ -609,8 +616,9 @@ string(Str, Width, Adjust, Precision, PadChar, Encoding) ->
StrLen = charsLen(Str),
if
Width > Precision ->
if StrLen > Precision ->
adjust(Adjust, flatTrunc(Str, Precision, Encoding), makePadChars(PadChar, Width - Precision, <<>>));
if
StrLen > Precision ->
adjust(Adjust, flatTrunc(Str, Precision, Encoding), makePadChars(PadChar, Width - Precision, <<>>));
StrLen < Precision ->
adjust(Adjust, [Str | makePadChars(PadChar, Precision - StrLen, <<>>)], makePadChars(PadChar, Width - Precision, <<>>));
true -> % N == P

+ 4
- 8
src/eFmtPretty.erl 查看文件

@ -93,6 +93,8 @@ pPrint(Term, Col, Ll, D, M, RecDefFun) ->
%% Col = current column, default 1
%% Ll = line length/~p field width, default 80
%% M = CHAR_MAX (-1 if no max, 60 when printing from shell)
%%Term, Precision, Width, Depth, -1, CharsLimit, no_fun, Encoding, Strings
print(_, _, _, 0, _M, _T, _RF, _Enc, _Str) -> "...";
print(_, _, _, _D, _M, 0, _RF, _Enc, _Str) -> "...";
print(Term, Col, Ll, D, M, T, RecDefFun, Enc, Str) when Col =< 0 ->
@ -100,10 +102,7 @@ print(Term, Col, Ll, D, M, T, RecDefFun, Enc, Str) when Col =< 0 ->
print(Term, 1, Ll, D, M, T, RecDefFun, Enc, Str);
print(Atom, _Col, _Ll, _D, _M, _T, _RF, Enc, _Str) when is_atom(Atom) ->
write_atom(Atom, Enc);
print(Term, Col, Ll, D, M0, T, RecDefFun, Enc, Str) when is_tuple(Term);
is_list(Term);
is_map(Term);
is_bitstring(Term) ->
print(Term, Col, Ll, D, M0, T, RecDefFun, Enc, Str) when is_tuple(Term); is_list(Term); is_map(Term); is_bitstring(Term) ->
%% preprocess and compute total number of chars
{_, Len, _Dots, _} = If =
case T < 0 of
@ -539,10 +538,7 @@ print_length(<<_/bitstring>> = Bin, 1, _T, RF, Enc, Str) ->
print_length(<<_/bitstring>> = Bin, D, T, RF, Enc, Str) ->
D1 = D - 1,
case
Str andalso
(bit_size(Bin) rem 8) =:= 0 andalso
printable_bin0(Bin, D1, tsub(T, 6), Enc)
of
Str andalso (bit_size(Bin) rem 8) =:= 0 andalso printable_bin0(Bin, D1, tsub(T, 6), Enc) of
{true, List} when is_list(List) ->
S = io_lib:write_string(List, $"), %"
{[$<, $<, S, $>, $>], 4 + length(S), 0, no_more};

Loading…
取消
儲存