diff options
author | Stavros Aronis <[email protected]> | 2011-03-21 18:40:24 +0200 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2011-05-04 15:06:17 +0200 |
commit | eaead79fdd0df14db64cc0bbc6c345291b2bf958 (patch) | |
tree | 2c9bc3cd5a5f83a958ba5ab881930d835bc5839f /lib/dialyzer/test | |
parent | 1f1e0451e973c379ff402a5ce64c86ea80f110de (diff) | |
download | otp-eaead79fdd0df14db64cc0bbc6c345291b2bf958.tar.gz otp-eaead79fdd0df14db64cc0bbc6c345291b2bf958.tar.bz2 otp-eaead79fdd0df14db64cc0bbc6c345291b2bf958.zip |
Add small/file_open_encoding
Diffstat (limited to 'lib/dialyzer/test')
-rw-r--r-- | lib/dialyzer/test/small_SUITE_data/src/file_open_encoding.erl | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/dialyzer/test/small_SUITE_data/src/file_open_encoding.erl b/lib/dialyzer/test/small_SUITE_data/src/file_open_encoding.erl new file mode 100644 index 0000000000..4f1268eba8 --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/file_open_encoding.erl @@ -0,0 +1,26 @@ +%%----------------------------------------------------------------------- +%% Program that gave erroneous warnings due to missing information about +%% the {encoding, latin1 | unicode | utf8 | ...} option of file:open/3. +%%----------------------------------------------------------------------- +-module(file_open_encoding). + +-export([parse/1]). + +-type proplist() :: [{atom(), any()}]. + +-spec parse(string()) -> proplist(). +parse(FileName) -> + {ok, IoDevice} = file:open(FileName, [read, binary, {encoding, utf8}]), + do_parse(IoDevice, []). + +do_parse(IoDevice, ResultSoFar) -> + case io:get_line(IoDevice, "") of + eof -> + file:close(IoDevice), + ResultSoFar; + <<"--"/utf8, _Comment/binary>> -> + do_parse(IoDevice, ResultSoFar); + Line -> + [Key, Value] = binary:split(Line, [<<": ">>, <<"\n">>], [global, trim]), + do_parse(IoDevice, [{binary_to_atom(Key, utf8), Value} | ResultSoFar]) + end. |