From 3babca112cdca239649646fdd82b4135d45ccbf7 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Mon, 29 Aug 2011 12:31:03 -0400 Subject: [PATCH] Make sure atoms needing quoting are quoted. --- src/lager_trunc_io.erl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lager_trunc_io.erl b/src/lager_trunc_io.erl index 189be17..0a682b4 100644 --- a/src/lager_trunc_io.erl +++ b/src/lager_trunc_io.erl @@ -214,7 +214,11 @@ print(Tuple, Max) when is_tuple(Tuple) -> %% print(Atom, _Max) when is_atom(Atom) -> L = atom_to_list(Atom), - {L, length(L)}; + R = case atom_needs_quoting_start(L) of + true -> lists:flatten([$', L, $']); + false -> L + end, + {R, length(R)}; print(<<>>, _Max) -> {"<<>>", 4}; @@ -319,6 +323,20 @@ alist(L, Max) -> {R, Len} = list_body(L, Max-3), {[$", $[, R, $]], Len + 3}. +%% is the first character in the atom alphabetic & lowercase? +atom_needs_quoting_start([H|T]) when H >= $a, H =< $z -> + atom_needs_quoting(T); +atom_needs_quoting_start(_) -> + true. + +atom_needs_quoting([]) -> + false; +atom_needs_quoting([H|T]) when (H >= $a andalso H =< $z); + (H >= $A andalso H =< $Z); + H == $@; H == $_ -> + atom_needs_quoting(T); +atom_needs_quoting(_) -> + true. -ifdef(TEST). %%--------------------