aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2013-05-17 11:49:48 +0200
committerBjörn-Egil Dahlberg <[email protected]>2014-01-28 15:56:27 +0100
commitd6b62db709a9e8e80689416bd7a5e5444ac3d3bf (patch)
tree04354b815e22198c619ec154d3fd4605987ec3aa /lib/stdlib
parentbc0960c095e9482ba0f452c9df3623f5c9c54e1f (diff)
downloadotp-d6b62db709a9e8e80689416bd7a5e5444ac3d3bf.tar.gz
otp-d6b62db709a9e8e80689416bd7a5e5444ac3d3bf.tar.bz2
otp-d6b62db709a9e8e80689416bd7a5e5444ac3d3bf.zip
stdlib: Update printing to handle Maps
Diffstat (limited to 'lib/stdlib')
-rw-r--r--lib/stdlib/src/io_lib.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl
index 375d05f359..886939761c 100644
--- a/lib/stdlib/src/io_lib.erl
+++ b/lib/stdlib/src/io_lib.erl
@@ -257,7 +257,9 @@ write(T, D) when is_tuple(T) ->
[write(element(1, T), D-1)|
write_tail(tl(tuple_to_list(T)), D-1, $,)],
$}]
- end.
+ end;
+%write(Term, D) when is_map(Term) -> write_map(Term, D);
+write(Term, D) -> write_map(Term, D).
%% write_tail(List, Depth, CharacterBeforeDots)
%% Test the terminating case first as this looks better with depth.
@@ -275,6 +277,18 @@ write_port(Port) ->
write_ref(Ref) ->
erlang:ref_to_list(Ref).
+write_map(Map, D) when is_integer(D) ->
+ [$#,${,write_map_body(map:to_list(Map), D),$}].
+
+write_map_body(_, 0) -> "...";
+write_map_body([],_) -> [];
+write_map_body([{K,V}],D) -> write_map_assoc(K,V,D);
+write_map_body([{K,V}|KVs], D) ->
+ [write_map_assoc(K,V,D),$, | write_map_body(KVs,D-1)].
+
+write_map_assoc(K,V,D) ->
+ [write(K,D - 1),"=>",write(V,D-1)].
+
write_binary(B, D) when is_integer(D) ->
[$<,$<,write_binary_body(B, D),$>,$>].