Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/stdlib/src/io_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,22 @@ string_bin_escape_latin1(_, Orig, _, Acc, Skip, Len) ->
false -> [Acc | binary_part(Orig, Skip, Len)]
end.

string_bin_escape_unicode(<<16#C2, Byte, Rest/binary>>, Orig, Q, Acc, Skip0, Len)
when Byte >= 16#80, Byte =< 16#9F ->
%% C1 control characters (U+0080-U+009F) - octal escape to match list path.
C1 = (Byte bsr 6) + $0,
C2 = ((Byte bsr 3) band 7) + $0,
C3 = (Byte band 7) + $0,
Escape = [$\\,C1,C2,C3],
case Len =:= 0 of
true ->
Skip = Skip0 + 2,
string_bin_escape_unicode(Rest, Orig, Q, [Acc | Escape], Skip, 0);
false ->
Skip = Skip0 + Len + 2,
Part = binary_part(Orig, Skip0, Len),
string_bin_escape_unicode(Rest, Orig, Q, [Acc, Part | Escape], Skip, 0)
end;
string_bin_escape_unicode(<<Byte, Rest/binary>>, Orig, Q, Acc, Skip0, Len) when Byte > 127 ->
string_bin_escape_unicode(Rest, Orig, Q, Acc, Skip0, Len+1);
string_bin_escape_unicode(<<Byte, Rest/binary>>, Orig, Q, Acc, Skip0, Len) ->
Expand Down
66 changes: 34 additions & 32 deletions lib/stdlib/src/io_lib_format.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ build(Cs) ->

build(Cs, Options) ->
CharsLimit = get_option(chars_limit, Options, -1),
Res1 = build_small(Cs),
Res1 = build_small(Cs, CharsLimit),
{P, S, W, Other} = count_small(Res1),
case P + S + W of
0 ->
Expand All @@ -128,7 +128,7 @@ build_bin(Cs) ->

build_bin(Cs, Options) ->
CharsLimit = get_option(chars_limit, Options, -1),
Res1 = build_small_bin(Cs),
Res1 = build_small_bin(Cs, CharsLimit),
{P, S, W, Other} = count_small(Res1),
case P + S + W of
0 ->
Expand Down Expand Up @@ -262,7 +262,12 @@ field_width(F, Fmt, Args) when F >= 0 ->
{F,right,Fmt,Args}.

precision([$.|Fmt], Args) ->
field_value(Fmt, Args);
case field_value(Fmt, Args) of
{P, _, _} when is_integer(P), P < 0 ->
error(badarg);
Result ->
Result
end;
precision(Fmt, Args) ->
{none,Fmt,Args}.

Expand Down Expand Up @@ -344,13 +349,13 @@ count_small([], #{p := P, s := S, w := W, other := Other}) ->
%% be smart when calculating indentation for characters in format.

build_small([#{control_char := C, args := As, width := F, adjust := Ad,
precision := P, pad_char := Pad, encoding := Enc}=CC | Cs]) ->
case control_small(C, As, F, Ad, P, Pad, Enc) of
not_small -> [CC | build_small(Cs)];
S -> lists:flatten(S) ++ build_small(Cs)
precision := P, pad_char := Pad, encoding := Enc}=CC | Cs], CL) ->
case control_small(C, As, limit_field(F, CL), Ad, P, Pad, Enc) of
not_small -> [CC | build_small(Cs, CL)];
S -> lists:flatten(S) ++ build_small(Cs, CL)
end;
build_small([C|Cs]) -> [C|build_small(Cs)];
build_small([]) -> [].
build_small([C|Cs], CL) -> [C|build_small(Cs, CL)];
build_small([], _CL) -> [].

build_limited([#{control_char := C, args := As, width := F, adjust := Ad,
precision := P, pad_char := Pad, encoding := Enc,
Expand Down Expand Up @@ -390,22 +395,22 @@ decr_pc($P, Pc) -> Pc - 1;
decr_pc(_, Pc) -> Pc.

build_small_bin([#{control_char := C, args := As, width := F, adjust := Ad,
precision := P, pad_char := Pad, encoding := Enc}=CC | Cs]) ->
case control_small(C, As, F, Ad, P, Pad, Enc) of
precision := P, pad_char := Pad, encoding := Enc}=CC | Cs], CL) ->
case control_small(C, As, limit_field(F, CL), Ad, P, Pad, Enc) of
not_small ->
[CC | build_small_bin(Cs)];
[CC | build_small_bin(Cs, CL)];
[$\n|_] = NL ->
[NL | build_small_bin(Cs)];
[NL | build_small_bin(Cs, CL)];
S ->
SBin = unicode:characters_to_binary(S, Enc, unicode),
true = is_binary(SBin),
[SBin | build_small_bin(Cs)]
[SBin | build_small_bin(Cs, CL)]
end;
build_small_bin([$\t|Cs]) ->
[$\t | build_small_bin(Cs)];
build_small_bin([C|Cs]) ->
[C | build_small_bin(Cs)];
build_small_bin([]) ->
build_small_bin([$\t|Cs], CL) ->
[$\t | build_small_bin(Cs, CL)];
build_small_bin([C|Cs], CL) ->
[C | build_small_bin(Cs, CL)];
build_small_bin([], _CL) ->
[].

build_limited_bin([#{control_char := C, args := As, width := F, adjust := Ad,
Expand Down Expand Up @@ -465,12 +470,12 @@ indentation([], I) ->
indentation_bin(Bin, I) ->
indentation_bin(Bin, Bin, 0, 0, I).

indentation_bin(<<$\n, Cs/binary>>, Orig, _Start, N,_I) ->
indentation_bin(Cs, Orig, N+1, 0, 0);
indentation_bin(<<$\n, Cs/binary>>, Orig, Start, N, _I) ->
indentation_bin(Cs, Orig, Start+N+1, 0, 0);
indentation_bin(<<$\t, Cs/binary>>, Orig, Start, N, I0) ->
Part = binary:part(Orig, Start, N),
PSz = string:length(Part),
indentation_bin(Cs, Orig, N+1, N+1, ((I0+PSz + 8) div 8) * 8);
indentation_bin(Cs, Orig, Start+N+1, 0, ((I0+PSz + 8) div 8) * 8);
indentation_bin(<<_, Cs/binary>>, Orig, Start, N, I) ->
indentation_bin(Cs, Orig, Start, N+1, I);
indentation_bin(<<>>, Orig, Start, N, I) ->
Expand Down Expand Up @@ -539,13 +544,13 @@ control_limited($s, [L0], F, Adj, P, Pad, Enc, _Str, _Ord, CL, _I) ->
end;
control_limited($w, [A], F, Adj, P, Pad, Enc, _Str, Ord, CL, _I) ->
Chars = io_lib:write(A, -1, Enc, Ord, CL),
term(Chars, F, Adj, P, Pad, Enc);
term(Chars, limit_field(F, CL), Adj, P, Pad, Enc);
control_limited($p, [A], F, Adj, P, Pad, Enc, Str, Ord, CL, I) ->
print(A, -1, F, Adj, P, Pad, Enc, list, Str, Ord, CL, I);
control_limited($W, [A,Depth], F, Adj, P, Pad, Enc, _Str, Ord, CL, _I)
when is_integer(Depth) ->
Chars = io_lib:write(A, Depth, Enc, Ord, CL),
term(Chars, F, Adj, P, Pad, Enc);
term(Chars, limit_field(F, CL), Adj, P, Pad, Enc);
control_limited($P, [A,Depth], F, Adj, P, Pad, Enc, Str, Ord, CL, I)
when is_integer(Depth) ->
print(A, Depth, F, Adj, P, Pad, Enc, list, Str, Ord, CL, I).
Expand All @@ -555,13 +560,13 @@ control_limited_bin($s, [L0], F, Adj, P, Pad, Enc, _Str, _Ord, CL, _I) ->
string_bin(B, Sz, limit_field(F, CL), Adj, P, Pad, Enc);
control_limited_bin($w, [A], F, Adj, P, Pad, Enc, _Str, Ord, CL, I) ->
{Chars, Sz} = io_lib:write_bin(A, -1, Enc, Ord, CL),
term_bin(Chars, F, Adj, P, Pad, Enc, Sz, I);
term_bin(Chars, limit_field(F, CL), Adj, P, Pad, Enc, Sz, I);
control_limited_bin($p, [A], F, Adj, P, Pad, Enc, Str, Ord, CL, I) ->
print(A, -1, F, Adj, P, Pad, Enc, binary, Str, Ord, CL, I);
control_limited_bin($W, [A,Depth], F, Adj, P, Pad, Enc, _Str, Ord, CL, I)
when is_integer(Depth) ->
{Chars, Sz} = io_lib:write_bin(A, Depth, Enc, Ord, CL),
term_bin(Chars, F, Adj, P, Pad, Enc, Sz, I);
term_bin(Chars, limit_field(F, CL), Adj, P, Pad, Enc, Sz, I);
control_limited_bin($P, [A,Depth], F, Adj, P, Pad, Enc, Str, Ord, CL, I)
when is_integer(Depth) ->
print(A, Depth, F, Adj, P, Pad, Enc, binary, Str, Ord, CL, I).
Expand Down Expand Up @@ -1061,14 +1066,11 @@ adjust(Data, Pad, right) -> [Pad|Data].

%% Flatten and truncate a deep list to at most N elements.

flat_trunc(List, N, latin1) when is_list(List), is_integer(N), N >= 0 ->
{S, _} = lists:split(N, lists:flatten(List)),
S;
flat_trunc(Str, N, unicode) when is_integer(N), N >= 0 ->
string:slice(Str, 0, N);
flat_trunc(Bin, N, latin1) when is_binary(Bin), is_integer(N), N >= 0 ->
{B, _} = split_binary(Bin, N),
B.
B;
flat_trunc(Str, N, _) when is_integer(N), N >= 0 ->
string:slice(Str, 0, N).

%% A deep version of lists:duplicate/2

Expand Down
73 changes: 42 additions & 31 deletions lib/stdlib/src/io_lib_pretty.erl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ pp_binary(S, N, _N0, Ind) ->
end.


-define(IND(Spaces), (list_to_binary(Spaces))/binary).
-define(IND(Spaces), Spaces/binary).

pp_bin({_S,Len,_,_} = If, Col, Ll, M, _TInd, _Ind, LD, NL, W, Pos, Acc)
when Len < Ll - Col - LD, Len + W + LD =< M ->
Expand Down Expand Up @@ -489,29 +489,33 @@ pp_map_bin([], _Col, _Ll, _M, _TInd, _Ind, _LD, NL, _W, Pos, Acc) ->
{<<Acc/binary, $}>>, NL, Pos+1}; % cannot happen
pp_map_bin({dots, _, _, _}, _Col, _Ll, _M, _TInd, _Ind, _LD, NL, _W, Pos, Acc) ->
{<<Acc/binary, "...}">>, NL, Pos+4}; % cannot happen
pp_map_bin([P | Ps], Col, Ll, M, TInd, Ind, LD, NL0, W, Pos0, Acc) ->
{PS, NL, Pos, PW} = pp_pair_bin(P, Col, Ll, M, TInd, Ind, last_depth(Ps, LD), NL0, W, Pos0, Acc),
pp_pairs_tail_bin(Ps, Col, Col+PW, Ll, M, TInd, Ind, LD, NL, PW, Pos, PS).
pp_map_bin([P | Ps], Col, Ll, M, TInd, Ind0, LD, NL0, W, Pos0, Acc) ->
I = map_value_indent(TInd),
Ind = iolist_to_binary(Ind0),
ValInd = iolist_to_binary(indent(I, Ind)),
{PS, NL, Pos, PW} = pp_pair_bin(P, Col, Ll, M, TInd, Ind, I, ValInd, last_depth(Ps, LD), NL0, W, Pos0, Acc),
pp_pairs_tail_bin(Ps, Col, Col+PW, Ll, M, TInd, Ind, I, ValInd, LD, NL, PW, Pos, PS).

pp_pairs_tail_bin([], _Col0, _Col, _Ll, _M, _TInd, _Ind, _LD, NL, _W, Pos, Acc) ->
pp_pairs_tail_bin([], _Col0, _Col, _Ll, _M, _TInd, _Ind, _I, _ValInd, _LD, NL, _W, Pos, Acc) ->
{<<Acc/binary, $}>>, NL, Pos+1};
pp_pairs_tail_bin({dots, _, _, _}, _Col0, _Col, _M, _Ll, _TInd, _Ind, _L, NL, _W, Pos, Acc) ->
pp_pairs_tail_bin({dots, _, _, _}, _Col0, _Col, _M, _Ll, _TInd, _Ind, _I, _ValInd, _L, NL, _W, Pos, Acc) ->
{<<Acc/binary, ",...}">>, NL, Pos+5};
pp_pairs_tail_bin([{_, Len, _, _}=P | Ps], Col0, Col, Ll, M, TInd, Ind, LD, NL0, W, Pos, Acc) ->
pp_pairs_tail_bin([{_, Len, _, _}=P | Ps], Col0, Col, Ll, M, TInd, Ind0, I, ValInd, LD, NL0, W, Pos, Acc) ->
LD1 = last_depth(Ps, LD),
ELen = 1+Len,
if
LD1 =:= 0, ELen+1 < Ll-Col, W+ELen+1 =< M, ?ATM_PAIR(P);
LD1 > 0, ELen < Ll-Col-LD1, W+ELen+LD1 =< M, ?ATM_PAIR(P) ->
pp_pairs_tail_bin(Ps, Col0, Col+ELen, Ll, M, TInd, Ind, LD, NL0, W+ELen, Pos+ELen,
pp_pairs_tail_bin(Ps, Col0, Col+ELen, Ll, M, TInd, Ind0, I, ValInd, LD, NL0, W+ELen, Pos+ELen,
write_bin(P, <<Acc/binary, $,>>));
true ->
{PS, NL, Pos1, PW} = pp_pair_bin(P, Col0, Ll, M, TInd, Ind, LD1, NL0+1, 0, Col0,
Ind = iolist_to_binary(Ind0),
{PS, NL, Pos1, PW} = pp_pair_bin(P, Col0, Ll, M, TInd, Ind, I, ValInd, LD1, NL0+1, 0, Col0,
<<Acc/binary, $,, $\n, ?IND(Ind)>>),
pp_pairs_tail_bin(Ps, Col0, Col0+PW, Ll, M, TInd, Ind, LD, NL, PW, Pos1, PS)
pp_pairs_tail_bin(Ps, Col0, Col0+PW, Ll, M, TInd, Ind, I, ValInd, LD, NL, PW, Pos1, PS)
end.

pp_pair_bin({_, Len, _, _}=Pair, Col, Ll, M, _TInd, _Ind, LD, NL, W, Pos, Acc)
pp_pair_bin({_, Len, _, _}=Pair, Col, Ll, M, _TInd, _Ind, _I, _ValInd, LD, NL, W, Pos, Acc)
when Len < Ll - Col - LD, Len+W+LD =< M ->
{write_bin(Pair, Acc),
NL,
Expand All @@ -522,12 +526,10 @@ pp_pair_bin({_, Len, _, _}=Pair, Col, Ll, M, _TInd, _Ind, LD, NL, W, Pos, Acc)
true ->
Ll % force nl
end};
pp_pair_bin({{map_pair, K, V}, _Len, _, _}, Col0, Ll, M, TInd, Ind0, LD, NL0, W, Pos0, Acc0) ->
I = map_value_indent(TInd),
Ind = indent(I, Ind0),
pp_pair_bin({{map_pair, K, V}, _Len, _, _}, Col0, Ll, M, TInd, Ind0, I, ValInd, LD, NL0, W, Pos0, Acc0) ->
{Acc1, NL1, _} = pp_bin(K, Col0, Ll, M, TInd, Ind0, LD, NL0, W, Pos0, Acc0),
{Acc2, NL, Pos} = pp_bin(V, Col0+I, Ll, M, TInd, Ind, LD, NL1+1, 0, Col0+I,
<<Acc1/binary, " =>\n", ?IND(Ind)>>),
{Acc2, NL, Pos} = pp_bin(V, Col0+I, Ll, M, TInd, ValInd, LD, NL1+1, 0, Col0+I,
<<Acc1/binary, " =>\n", ?IND(ValInd)>>),
{Acc2, NL, Pos, Ll}.

pp_record_bin([], _Nlen, _Col, _Ll, _M, _TInd, _Ind, _LD, NL, _W, Pos, Acc) ->
Expand All @@ -536,7 +538,8 @@ pp_record_bin({dots, _, _, _}, _Nlen, _Col, _Ll, _M, _TInd, _Ind, _LD, NL, _W, P
{<<Acc/binary, "...}">>, NL, Pos+4};
pp_record_bin([F | Fs], Nlen, Col0, Ll, M, TInd, Ind0, LD, NL0, W0, Pos0, Acc) ->
Nind = Nlen+1,
{Col, Ind, S, W} = rec_indent(Nind, TInd, Col0, Ind0, W0),
{Col, Ind, S0, W} = rec_indent(Nind, TInd, Col0, Ind0, W0),
S = iolist_to_binary(S0),
{Pos1, NL1} = if W == 0 -> {Col, NL0+1}; true -> {Pos0, NL0} end,
{FS, NL, Pos, FW} = pp_field_bin(F, Col, Ll, M, TInd, Ind, last_depth(Fs, LD), NL1, W, Pos1,
<<Acc/binary, ?IND(S)>>),
Expand All @@ -546,15 +549,16 @@ pp_fields_tail_bin([], _Col0, _Col, _Ll, _M, _TInd, _Ind, _LD, NL, _W, Pos, Acc)
{<<Acc/binary, $}>>, NL, Pos+1};
pp_fields_tail_bin({dots, _, _ ,_}, _Col0, _Col, _M, _Ll, _TInd, _Ind, _LD, NL, _W, Pos, Acc) ->
{<<Acc/binary, ",...}">>, NL, Pos+5};
pp_fields_tail_bin([{_, Len, _, _}=F | Fs], Col0, Col, Ll, M, TInd, Ind, LD, NL0, W, Pos0, Acc) ->
pp_fields_tail_bin([{_, Len, _, _}=F | Fs], Col0, Col, Ll, M, TInd, Ind0, LD, NL0, W, Pos0, Acc) ->
LD1 = last_depth(Fs, LD),
ELen = 1+Len,
if
LD1 =:= 0, ELen+1 < Ll-Col, W+ELen+1 =< M, ?ATM_FLD(F);
LD1 > 0, ELen < Ll-Col-LD1, W+ELen+LD1 =< M, ?ATM_FLD(F) ->
pp_fields_tail_bin(Fs, Col0, Col+ELen, Ll, M, TInd, Ind, LD, NL0, W+ELen, Pos0+ELen,
pp_fields_tail_bin(Fs, Col0, Col+ELen, Ll, M, TInd, Ind0, LD, NL0, W+ELen, Pos0+ELen,
write_field_bin(F, <<Acc/binary, $,>>));
true ->
Ind = iolist_to_binary(Ind0),
{FS, NL, Pos, FW} = pp_field_bin(F, Col0, Ll, M, TInd, Ind, LD1, NL0+1, 0, Col0,
<<Acc/binary, $,, $\n, ?IND(Ind)>>),
pp_fields_tail_bin(Fs, Col0, Col0+FW, Ll, M, TInd, Ind, LD, NL, FW, Pos, FS)
Expand All @@ -570,7 +574,8 @@ pp_field_bin({_, Len, _, _}=Fl, Col, Ll, M, _TInd, _Ind, LD, NL, W, Pos, Acc)
true -> Ll % force nl
end};
pp_field_bin({{field, Name0, NameL, F},_,_, _}, Col0, Ll, M, TInd, Ind0, LD, NL0, W0, Pos0, Acc0) ->
{Col, Ind, S, W} = rec_indent(NameL, TInd, Col0, Ind0, W0+NameL),
{Col, Ind, S0, W} = rec_indent(NameL, TInd, Col0, Ind0, W0+NameL),
S = iolist_to_binary(S0),
Name = unicode:characters_to_binary(Name0),
{Acc, NL, Pos} =
case W of
Expand All @@ -591,15 +596,16 @@ pp_list_bin([E | Es], Col0, Ll, M, TInd, Ind, LD, S, C, NL0, W, Pos0, Acc) ->

pp_tail_bin([], _Col0, _Col, _Ll, _M, _TInd, _Ind, _LD, _S, C, NL, _W, Pos, Acc) ->
{<<Acc/binary, C>>, NL, Pos+1};
pp_tail_bin([{_, Len, _, _}=E | Es], Col0, Col, Ll, M, TInd, Ind, LD, S, C, NL0, W, Pos0, Acc) ->
pp_tail_bin([{_, Len, _, _}=E | Es], Col0, Col, Ll, M, TInd, Ind0, LD, S, C, NL0, W, Pos0, Acc) ->
LD1 = last_depth(Es, LD),
ELen = 1+Len,
if
LD1 =:= 0, ELen+1 < Ll-Col, W+ELen+1 =< M, ?ATM(E);
LD1 > 0, ELen < Ll-Col-LD1, W+ELen+LD1 =< M, ?ATM(E) ->
pp_tail_bin(Es, Col0, Col+ELen, Ll, M, TInd, Ind, LD, S, C, NL0, W+ELen, Pos0+ELen,
pp_tail_bin(Es, Col0, Col+ELen, Ll, M, TInd, Ind0, LD, S, C, NL0, W+ELen, Pos0+ELen,
write_bin(E, <<Acc/binary, $,>>));
true ->
Ind = iolist_to_binary(Ind0),
{ES, NL, Pos, WE} = pp_element_bin(E, Col0, Ll, M, TInd, Ind, LD1, NL0+1, 0, Col0,
<<Acc/binary, $,, $\n, ?IND(Ind)>>),
pp_tail_bin(Es, Col0, Col0+WE, Ll, M, TInd, Ind, LD, S, C, NL, WE, Pos, ES)
Expand All @@ -612,7 +618,8 @@ pp_tail_bin({_, Len, _, _}=E, _Col0, Col, Ll, M, _TInd, _Ind, LD, S, C, NL, W, P
?ATM(E) ->
Acc1 = write_bin(E, <<Acc/binary, S>>),
{<<Acc1/binary, C>>, NL, Pos+1+Len};
pp_tail_bin(E, Col0, _Col, Ll, M, TInd, Ind, LD, S, C, NL0, _W, _Pos0, Acc) ->
pp_tail_bin(E, Col0, _Col, Ll, M, TInd, Ind0, LD, S, C, NL0, _W, _Pos0, Acc) ->
Ind = iolist_to_binary(Ind0),
{Acc1, NL, Pos} = pp_bin(E, Col0, Ll, M, TInd, Ind, LD+1, NL0+1, 0, Col0,
<<Acc/binary, S, $\n, ?IND(Ind)>>),
{<<Acc1/binary, C>>, NL, Pos+1}.
Expand All @@ -629,38 +636,41 @@ pp_binary_bin(Orig, Col, Ll, M, Ind, LD, NL, W, Pos, Acc) ->
<<$<,$<,Rest/binary>> = Orig,
pp_binary_bin_ind(Rest, Orig, Ind, 0, 2, N, N, NL, Pos, Acc).

pp_binary_bin_ind(<<_,$,, Rest/binary>>, Orig, Ind, S, I, N, N0, NL, Pos, Acc) ->
pp_binary_bin_ind(<<_,$,, Rest/binary>>, Orig, Ind0, S, I, N, N0, NL, Pos, Acc) ->
N1 = N-2,
case N1 < 0 of
false ->
pp_binary_bin_ind(Rest, Orig, Ind, S, I+2, N1, N0, NL, Pos, Acc);
pp_binary_bin_ind(Rest, Orig, Ind0, S, I+2, N1, N0, NL, Pos, Acc);
true ->
Part = binary:part(Orig, S, I),
Ind = iolist_to_binary(Ind0),
pp_binary_bin_ind(Rest, Orig, Ind, S+I, 2, N0-2, N0, NL+1, 0,
<<Acc/binary, Part/binary, $\n, ?IND(Ind)>>)
end;
pp_binary_bin_ind(<<_,_,$,, Rest/binary>>, Orig, Ind, S, I, N, N0, NL, Pos, Acc) ->
pp_binary_bin_ind(<<_,_,$,, Rest/binary>>, Orig, Ind0, S, I, N, N0, NL, Pos, Acc) ->
N1 = N-3,
case N1 < 0 of
false ->
pp_binary_bin_ind(Rest, Orig, Ind, S, I+3, N1, N0, NL, Pos, Acc);
pp_binary_bin_ind(Rest, Orig, Ind0, S, I+3, N1, N0, NL, Pos, Acc);
true ->
Part = binary:part(Orig, S, I),
Ind = iolist_to_binary(Ind0),
pp_binary_bin_ind(Rest, Orig, Ind, S+I, 3, N0-3, N0, NL+1, Pos,
<<Acc/binary, Part/binary, $\n, ?IND(Ind)>>)
end;
pp_binary_bin_ind(<<_,_,_,$,, Rest/binary>>, Orig, Ind, S, I, N, N0, NL, Pos, Acc) ->
pp_binary_bin_ind(<<_,_,_,$,, Rest/binary>>, Orig, Ind0, S, I, N, N0, NL, Pos, Acc) ->
N1 = N-4,
case N1 < 0 of
false ->
pp_binary_bin_ind(Rest, Orig, Ind, S, I+4, N1, N0, NL, Pos, Acc);
pp_binary_bin_ind(Rest, Orig, Ind0, S, I+4, N1, N0, NL, Pos, Acc);
true ->
Part = binary:part(Orig, S, I),
Ind = iolist_to_binary(Ind0),
pp_binary_bin_ind(Rest, Orig, Ind, S+I, 4, N0-4, N0, NL+1, Pos,
<<Acc/binary, Part/binary, $\n, ?IND(Ind)>>)
end;
pp_binary_bin_ind(Bin, Orig, Ind, S, I, N, _, NL, Pos0, Acc) ->
Col = iolist_size(Ind)+1,
pp_binary_bin_ind(Bin, Orig, Ind0, S, I, N, _, NL, Pos0, Acc) ->
Col = iolist_size(Ind0)+1,
Pos = if Pos0 =:= 0 -> Col; true -> Pos0 end,
case (byte_size(Bin)-2) > N of %% Don't count bin closing ">>"
false when S =:= 0 ->
Expand All @@ -674,6 +684,7 @@ pp_binary_bin_ind(Bin, Orig, Ind, S, I, N, _, NL, Pos0, Acc) ->
Part1 = binary:part(Orig, S, I),
Sz = byte_size(Orig) - (S+I),
Part2 = binary:part(Orig, S+I, Sz),
Ind = iolist_to_binary(Ind0),
{<<Acc/binary, Part1/binary, $\n, ?IND(Ind), Part2/binary>>,
NL+1, Col+Sz}
end.
Expand Down
Loading
Loading