diff options
author | Hans Bolinder <[email protected]> | 2013-02-14 08:12:34 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2013-02-14 08:12:34 +0100 |
commit | bbcf34d621d613046ea99eb5fafc01196c88e47f (patch) | |
tree | 55db363588e56892b813a9b3d6d2bcd72298bb5b /lib/stdlib/src | |
parent | fea2580dd33765f33f086404257b1654c280e840 (diff) | |
parent | 11a642476470712fee8d6f78424d56b8b6da92d7 (diff) | |
download | otp-bbcf34d621d613046ea99eb5fafc01196c88e47f.tar.gz otp-bbcf34d621d613046ea99eb5fafc01196c88e47f.tar.bz2 otp-bbcf34d621d613046ea99eb5fafc01196c88e47f.zip |
Merge branch 'hb/stdlib/extend_ts/OTP-10836'
* hb/stdlib/extend_ts/OTP-10836:
Extend ~ts to handle binaries with characters coded in ISO-latin-1
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/io_lib_format.erl | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/stdlib/src/io_lib_format.erl b/lib/stdlib/src/io_lib_format.erl index 6a06d9448b..64d19ccf48 100644 --- a/lib/stdlib/src/io_lib_format.erl +++ b/lib/stdlib/src/io_lib_format.erl @@ -185,8 +185,7 @@ control($s, [L0], F, Adj, P, Pad, latin1, _I) -> L = iolist_to_chars(L0), string(L, F, Adj, P, Pad); control($s, [L0], F, Adj, P, Pad, unicode, _I) -> - L = unicode:characters_to_list(L0), - true = is_list(L), + L = cdata_to_chars(L0), uniconv(string(L, F, Adj, P, Pad)); control($e, [A], F, Adj, P, Pad, _Enc, _I) when is_float(A) -> fwrite_e(A, F, Adj, P, Pad); @@ -558,6 +557,25 @@ iolist_to_chars([]) -> iolist_to_chars(B) when is_binary(B) -> binary_to_list(B). +%% cdata() :: clist() | cbinary() +%% clist() :: maybe_improper_list(char() | cbinary() | clist(), +%% cbinary() | nil()) +%% cbinary() :: unicode:unicode_binary() | unicode:latin1_binary() + +%% cdata_to_chars(cdata()) -> io_lib:deep_char_list() + +cdata_to_chars([C|Cs]) when is_integer(C), C >= $\000 -> + [C | cdata_to_chars(Cs)]; +cdata_to_chars([I|Cs]) -> + [cdata_to_chars(I) | cdata_to_chars(Cs)]; +cdata_to_chars([]) -> + []; +cdata_to_chars(B) when is_binary(B) -> + case catch unicode:characters_to_list(B) of + L when is_list(L) -> L; + _ -> binary_to_list(B) + end. + %% string(String, Field, Adjust, Precision, PadChar) string(S, none, _Adj, none, _Pad) -> S; |