diff options
author | Hans Bolinder <[email protected]> | 2018-03-13 10:18:44 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2018-03-13 10:18:44 +0100 |
commit | 3fa85a8e858e1c8300967e0eda347697c0940188 (patch) | |
tree | e76cc27b36f09ed9743afb154b74f2a245f2047d /lib/stdlib/src/io_lib_format.erl | |
parent | a4d14013823bd35b46b7c8ca7845e3df22527d80 (diff) | |
parent | 9c1cb443a22679f038451b4491c4c50ec53f77a2 (diff) | |
download | otp-3fa85a8e858e1c8300967e0eda347697c0940188.tar.gz otp-3fa85a8e858e1c8300967e0eda347697c0940188.tar.bz2 otp-3fa85a8e858e1c8300967e0eda347697c0940188.zip |
Merge pull request #1743 from richcarl/io-format-multiple-modifiers
Allow multiple modifier characters in io:format control sequences
OTP-14971
Diffstat (limited to 'lib/stdlib/src/io_lib_format.erl')
-rw-r--r-- | lib/stdlib/src/io_lib_format.erl | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/stdlib/src/io_lib_format.erl b/lib/stdlib/src/io_lib_format.erl index 2ef4e517d8..64edbf1824 100644 --- a/lib/stdlib/src/io_lib_format.erl +++ b/lib/stdlib/src/io_lib_format.erl @@ -127,25 +127,23 @@ collect_cseq(Fmt0, Args0) -> {F,Ad,Fmt1,Args1} = field_width(Fmt0, Args0), {P,Fmt2,Args2} = precision(Fmt1, Args1), {Pad,Fmt3,Args3} = pad_char(Fmt2, Args2), - {Encoding,Fmt4,Args4} = encoding(Fmt3, Args3), - {Strings,Fmt5,Args5} = strings(Fmt4, Args4), - {C,As,Fmt6,Args6} = collect_cc(Fmt5, Args5), - FormatSpec = #{control_char => C, args => As, width => F, adjust => Ad, - precision => P, pad_char => Pad, encoding => Encoding, - strings => Strings}, - {FormatSpec,Fmt6,Args6}. - -encoding([$t|Fmt],Args) -> - true = hd(Fmt) =/= $l, - {unicode,Fmt,Args}; -encoding(Fmt,Args) -> - {latin1,Fmt,Args}. - -strings([$l|Fmt],Args) -> - true = hd(Fmt) =/= $t, - {false,Fmt,Args}; -strings(Fmt,Args) -> - {true,Fmt,Args}. + Spec0 = #{width => F, + adjust => Ad, + precision => P, + pad_char => Pad, + encoding => latin1, + strings => true}, + {Spec1,Fmt4} = modifiers(Fmt3, Spec0), + {C,As,Fmt5,Args4} = collect_cc(Fmt4, Args3), + Spec2 = Spec1#{control_char => C, args => As}, + {Spec2,Fmt5,Args4}. + +modifiers([$t|Fmt], Spec) -> + modifiers(Fmt, Spec#{encoding => unicode}); +modifiers([$l|Fmt], Spec) -> + modifiers(Fmt, Spec#{strings => false}); +modifiers(Fmt, Spec) -> + {Spec, Fmt}. field_width([$-|Fmt0], Args0) -> {F,Fmt,Args} = field_value(Fmt0, Args0), |