aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrik Nyblom <[email protected]>2013-02-14 15:33:00 +0100
committerPatrik Nyblom <[email protected]>2013-02-18 11:49:11 +0100
commitfe227eac8af30e646ade187eaf194bdd9c92b2c2 (patch)
treeb06b1c03d3b4cb76e88de975d92cc3517fce3ad0
parent1b4280cd2e8dcab457562bbaacc4e1d16d372185 (diff)
downloadotp-fe227eac8af30e646ade187eaf194bdd9c92b2c2.tar.gz
otp-fe227eac8af30e646ade187eaf194bdd9c92b2c2.tar.bz2
otp-fe227eac8af30e646ade187eaf194bdd9c92b2c2.zip
Make printing of UTF-8 in binaries behave like lists.
This means that only UTF-8 characters in binaries that conform to the printable_range are printed as <<"..."/utf8>> in io_lib_pretty.
-rw-r--r--lib/stdlib/src/io_lib_pretty.erl29
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/stdlib/src/io_lib_pretty.erl b/lib/stdlib/src/io_lib_pretty.erl
index 525b534249..4a61b033b0 100644
--- a/lib/stdlib/src/io_lib_pretty.erl
+++ b/lib/stdlib/src/io_lib_pretty.erl
@@ -485,7 +485,7 @@ printable_bin(Bin, Len, D, latin1) ->
false
end;
printable_bin(Bin, Len, D, _Uni) ->
- case printable_unicode(Bin, Len, []) of
+ case printable_unicode(Bin, Len, [], io:printable_range()) of
{_, <<>>, L} ->
{byte_size(Bin) =:= length(L), L};
{NC, Bin1, L} when D > 0, Len - NC >= D ->
@@ -522,24 +522,27 @@ printable_latin1_list([$\e | Cs], N) -> printable_latin1_list(Cs, N - 1);
printable_latin1_list([], _) -> all;
printable_latin1_list(_, N) -> N.
-printable_unicode(<<C/utf8, R/binary>>=Bin, I, L) when I > 0 ->
- case printable_char(C) of
+printable_unicode(<<C/utf8, R/binary>>=Bin, I, L, Range) when I > 0 ->
+ case printable_char(C,Range) of
true ->
- printable_unicode(R, I - 1, [C | L]);
+ printable_unicode(R, I - 1, [C | L],Range);
false ->
{I, Bin, lists:reverse(L)}
end;
-printable_unicode(Bin, I, L) ->
+printable_unicode(Bin, I, L,_) ->
{I, Bin, lists:reverse(L)}.
-printable_char($\n) -> true;
-printable_char($\r) -> true;
-printable_char($\t) -> true;
-printable_char($\v) -> true;
-printable_char($\b) -> true;
-printable_char($\f) -> true;
-printable_char($\e) -> true;
-printable_char(C) ->
+printable_char($\n,_) -> true;
+printable_char($\r,_) -> true;
+printable_char($\t,_) -> true;
+printable_char($\v,_) -> true;
+printable_char($\b,_) -> true;
+printable_char($\f,_) -> true;
+printable_char($\e,_) -> true;
+printable_char(C,latin1) ->
+ C >= $\s andalso C =< $~ orelse
+ C >= 16#A0 andalso C =< 16#FF;
+printable_char(C,unicode) ->
C >= $\s andalso C =< $~ orelse
C >= 16#A0 andalso C < 16#D800 orelse
C > 16#DFFF andalso C < 16#FFFE orelse