Skip to content

Commit 1705290

Browse files
committed
Merge pull request #1291 from pguyot/w39/add-io_lib-latin1_char_list
Add support for `io_lib:latin1_char_list/1` These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 1e5e1e9 + d4343a0 commit 1705290

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ also non string parameters (e.g. `Enum.join([1, 2], ",")`
2525
- Support for Elixir `List.Chars` protocol
2626
- Support for `gen_server:start_monitor/3,4`
2727
- Support for `code:ensure_loaded/1`
28+
- Support for `io_lib:latin1_char_list/1`
2829

2930
### Changed
3031

libs/estdlib/src/io_lib.erl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
%%-----------------------------------------------------------------------------
2828
-module(io_lib).
2929

30-
-export([format/2]).
30+
-export([format/2, latin1_char_list/1]).
3131

3232
%%-----------------------------------------------------------------------------
3333
%% @param Format format string
@@ -50,6 +50,20 @@ format(Format, Args) ->
5050
error(badarg)
5151
end.
5252

53+
%%-----------------------------------------------------------------------------
54+
%% @param Term term to test
55+
%% @returns true if Term is a list of latin1 characters, false otherwise.
56+
%% @doc Determine if passed term is a list of ISO-8859-1 characters (0-255).
57+
%% @end
58+
%%-----------------------------------------------------------------------------
59+
-spec latin1_char_list(Term :: any()) -> boolean().
60+
latin1_char_list([H | T]) when is_integer(H) andalso H >= 0 andalso H =< 255 ->
61+
latin1_char_list(T);
62+
latin1_char_list([]) ->
63+
true;
64+
latin1_char_list(_) ->
65+
false.
66+
5367
%%
5468
%% internal operations
5569
%%

tests/libs/estdlib/test_io_lib.erl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
-define(FLT(L), lists:flatten(L)).
2828

2929
test() ->
30+
test_format(),
31+
test_latin1_char_list(),
32+
ok.
33+
34+
test_format() ->
3035
?ASSERT_MATCH(?FLT(io_lib:format("", [])), ""),
3136
?ASSERT_MATCH(?FLT(io_lib:format("foo", [])), "foo"),
3237
?ASSERT_MATCH(?FLT(io_lib:format("foo~n", [])), "foo\n"),
@@ -240,5 +245,16 @@ test() ->
240245

241246
ok.
242247

248+
test_latin1_char_list() ->
249+
true = io_lib:latin1_char_list([]),
250+
false = io_lib:latin1_char_list(foo),
251+
false = io_lib:latin1_char_list(<<>>),
252+
false = io_lib:latin1_char_list(<<"hello">>),
253+
true = io_lib:latin1_char_list("hello"),
254+
true = io_lib:latin1_char_list("été"),
255+
false = io_lib:latin1_char_list(["hello"]),
256+
false = io_lib:latin1_char_list([$h, $e, $l, $l | $o]),
257+
ok.
258+
243259
id(X) ->
244260
X.

0 commit comments

Comments
 (0)