Quellcode durchsuchen

ft:bug fix

master
lijie vor 2 Jahren
Ursprung
Commit
d2ce0f6526
1 geänderte Dateien mit 52 neuen und 22 gelöschten Zeilen
  1. +52
    -22
      src/eFmt.erl

+ 52
- 22
src/eFmt.erl Datei anzeigen

@ -157,6 +157,17 @@ write(Term, Depth, IsPretty) ->
writeTerm(Term, Depth, latin1)
end.
splitPart(Term)when is_map(Term) ->
<<",...}">>;
splitPart(Term)when is_tuple(Term) ->
<<",...}">>;
splitPart(Term)when is_list(Term) ->
<<",...]">>;
splitPart(Term) when is_binary(Term) ->
<<",...>>">>;
splitPart(_Term) ->
<<",...">>.
-spec write(Term :: term(), Depth :: depth(), Encoding :: encoding(), CharsLimit :: charsLimit()) -> chars().
write(Term, Depth, Encoding, CharsLimit) ->
if
@ -165,13 +176,13 @@ write(Term, Depth, Encoding, CharsLimit) ->
CharsLimit < 0 ->
writeTerm(Term, Depth, Encoding);
true ->
BinTerm = writeTerm(Term, Depth, ?LineCCnt, Encoding, false),
BinTerm = writeTerm(Term, Depth, Encoding),
BinTermSize = byte_size(BinTerm),
if
CharsLimit < 0 ->
BinTerm;
BinTermSize > CharsLimit ->
<<(part(BinTerm, 0, CharsLimit))/binary, "...">>;
<<(part(BinTerm, 0, CharsLimit))/binary, (splitPart(Term))/binary>>;
true ->
BinTerm
end
@ -188,7 +199,7 @@ write(Term, Depth, Width, CharsLimit, Encoding, Strings) ->
CharsLimit < 0 ->
BinTerm;
BinTermSize > CharsLimit ->
<<(part(BinTerm, 0, CharsLimit))/binary, "...">>;
<<(part(BinTerm, 0, CharsLimit))/binary, (splitPart(Term))/binary>>;
true ->
BinTerm
end
@ -333,7 +344,7 @@ writeList([One], Depth, Width, Encoding, Strings, SumLC, BinAcc) ->
TermBin = writeTerm(One, Depth, Width, Encoding, Strings),
TermBinBinSize = byte_size(TermBin),
NewSumLC = SumLC + TermBinBinSize,
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
<<BinAcc/binary, TermBin/binary, "]\n">>;
_ ->
@ -347,7 +358,7 @@ writeList([One | List], Depth, Width, Encoding, Strings, SumLC, BinAcc) ->
TermBin = writeTerm(One, Depth, Width, Encoding, Strings),
TermBinBinSize = byte_size(TermBin),
NewSumLC = SumLC + TermBinBinSize,
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
writeList(List, Depth - 1, Width, Encoding, Strings, 0, <<BinAcc/binary, TermBin/binary, ",\n">>);
_ ->
@ -359,7 +370,7 @@ writeList(Other, Depth, Width, Encoding, Strings, SumLC, BinAcc) ->
TermBinBinSize = byte_size(TermBin),
NewSumLC = SumLC + TermBinBinSize,
NewBinAcc = part(BinAcc, 0, byte_size(BinAcc) - 1),
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
<<NewBinAcc/binary, "|", TermBin/binary, "]\n">>;
_ ->
@ -375,7 +386,7 @@ writeTuple(Tuple, Depth, Width, Encoding, Strings, Index, TupleSize, SumLC, BinA
TermBin = writeTerm(element(Index, Tuple), Depth, Width, Encoding, Strings),
TermBinBinSize = byte_size(TermBin),
NewSumLC = SumLC + TermBinBinSize,
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
writeTuple(Tuple, Depth - 1, Width, Encoding, Strings, Index + 1, TupleSize, 0, <<BinAcc/binary, TermBin/binary, ",\n">>);
_ ->
@ -385,7 +396,7 @@ writeTuple(Tuple, Depth, Width, Encoding, Strings, Index, TupleSize, SumLC, BinA
TermBin = writeTerm(element(Index, Tuple), Depth, Width, Encoding, Strings),
TermBinBinSize = byte_size(TermBin),
NewSumLC = SumLC + TermBinBinSize,
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
<<BinAcc/binary, TermBin/binary, "}\n">>;
_ ->
@ -415,7 +426,7 @@ writeMapBody(I, Depth, Width, Encoding, Strings, SumLC, BinAcc) ->
ValueTermBin = writeTerm(V, -1, Width, Encoding, Strings),
TermBinBinSize = byte_size(KeyTermBin) + byte_size(ValueTermBin),
NewSumLC = SumLC + TermBinBinSize,
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
<<BinAcc/binary, KeyTermBin/binary, " => ", ValueTermBin/binary, "}\n">>;
_ ->
@ -426,7 +437,7 @@ writeMapBody(I, Depth, Width, Encoding, Strings, SumLC, BinAcc) ->
ValueTermBin = writeTerm(V, -1, Width, Encoding, Strings),
TermBinBinSize = byte_size(KeyTermBin) + byte_size(ValueTermBin),
NewSumLC = SumLC + TermBinBinSize,
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
writeMapBody(NextI, Depth - 1, Width, Encoding, Strings, 0, <<BinAcc/binary, KeyTermBin/binary, " => ", ValueTermBin/binary, ",\n">>);
_ ->
@ -461,7 +472,7 @@ writeBinary(Bin, Depth, Width, Encoding, Strings, SumLC, BinAcc) ->
TermBin = integer_to_binary(Int),
TermBinBinSize = byte_size(TermBin),
NewSumLC = SumLC + TermBinBinSize,
case NewSumLC >= Width of
case Width /= 0 andalso NewSumLC >= Width of
true ->
writeBinary(LeftBin, Depth - 1, Width, Encoding, Strings, 0, <<BinAcc/binary, TermBin/binary, ",\n">>);
_ ->
@ -538,7 +549,7 @@ doCollect(FmtBinStr, Args, Acc) ->
true = [] == Args,
?IIF(NotMatch == <<>>, Acc, [NotMatch | Acc]);
[FPart, LPart] ->
doCollWidth(LPart, Args, 0, right, ?IIF(FPart == <<>>, Acc, [FPart | Acc]))
doCollWidth(LPart, Args, none, right, ?IIF(FPart == <<>>, Acc, [FPart | Acc]))
end.
doCollWidth(<<>>, _Args, _Width, _Adjust, Acc) ->
@ -547,23 +558,41 @@ doCollWidth(LPart, Args, Width, Adjust, Acc) ->
case LPart of
<<"-*", LeftLPart/binary>> ->
[WidthArgs | LeftArgs] = Args,
doCollPrecision(LeftLPart, LeftArgs, WidthArgs, left, Acc);
if
WidthArgs == 0 ->
NewWidth = WidthArgs,
NewAdjust = left;
WidthArgs < 0 ->
NewWidth = -WidthArgs,
NewAdjust = right;
true ->
NewWidth = WidthArgs,
NewAdjust = left
end,
doCollPrecision(LeftLPart, LeftArgs, NewWidth, NewAdjust, Acc);
<<"-", LeftLPart/binary>> ->
doCollWidth(LeftLPart, Args, Width, left, Acc);
<<"*", LeftLPart/binary>> ->
[WidthArgs | LeftArgs] = Args,
doCollPrecision(LeftLPart, LeftArgs, WidthArgs, right, Acc);
if
WidthArgs == 0 ->
NewWidth = WidthArgs,
NewAdjust = left;
WidthArgs < 0 ->
NewWidth = -WidthArgs,
NewAdjust = left;
true ->
NewWidth = WidthArgs,
NewAdjust = right
end,
doCollPrecision(LeftLPart, LeftArgs, NewWidth, NewAdjust, Acc);
<<WidthInt:8/integer, LeftLPart/binary>> ->
case WidthInt >= $0 andalso WidthInt =< $9 of
true ->
doCollWidth(LeftLPart, Args, 10 * Width + (WidthInt - $0), Adjust, Acc);
NewWidth = ?IIF(Width == none, WidthInt - $0, 10 * Width + (WidthInt - $0)),
doCollWidth(LeftLPart, Args, NewWidth, Adjust, Acc);
_ ->
case Width == 0 of
true ->
doCollPrecision(LPart, Args, none, left, Acc);
_ ->
doCollPrecision(LPart, Args, Width, Adjust, Acc)
end
doCollPrecision(LPart, Args, Width, Adjust, Acc)
end
end.
@ -579,7 +608,8 @@ doCollPrecision(LPart, Args, Width, Adjust, Precision, Acc) ->
case LPart of
<<"*", LeftLPart/binary>> ->
[PrecisionArgs | LeftArgs] = Args,
doCollPadChar(LeftLPart, LeftArgs, Width, Adjust, PrecisionArgs, Acc);
NewPrecision = ?IIF(PrecisionArgs == 0, none, PrecisionArgs),
doCollPadChar(LeftLPart, LeftArgs, Width, Adjust, NewPrecision, Acc);
<<PrecisionInt:8/integer, LeftLPart/binary>> ->
case PrecisionInt >= $0 andalso PrecisionInt =< $9 of
true ->

Laden…
Abbrechen
Speichern