aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gleam_stdlib.erl')
-rw-r--r--src/gleam_stdlib.erl21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 1b33126..376692b 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -8,7 +8,8 @@
decode_thunk/1, decode_atom/1, decode_list/1, decode_field/2,
decode_element/2, parse_int/1, parse_float/1, compare_strings/2,
string_pop_grapheme/1, string_starts_with/2, string_ends_with/2,
- string_pad/4, decode_tuple2/1, decode_map/1]).
+ string_pad/4, decode_tuple2/1, decode_map/1, binary_int_to_u32/1,
+ binary_int_from_u32/1, binary_append/2, binary_part_/3]).
should_equal(Actual, Expected) -> ?assertEqual(Expected, Actual).
should_not_equal(Actual, Expected) -> ?assertNotEqual(Expected, Actual).
@@ -139,3 +140,21 @@ string_pop_grapheme(String) ->
{ok, {unicode:characters_to_binary([Next]), unicode:characters_to_binary(Rest)}};
_ -> {error, nil}
end.
+
+binary_append(First, Second) ->
+ <<First/binary, Second/binary>>.
+
+binary_part_(Bin, Pos, Len) ->
+ try {ok, binary:part(Bin, Pos, Len)} catch
+ error:badarg -> {error, nil}
+ end.
+
+binary_int_to_u32(I) when 0 =< I, I < 4294967296 ->
+ {ok, <<I:32>>};
+binary_int_to_u32(_) ->
+ {error, nil}.
+
+binary_int_from_u32(<<I:32>>) ->
+ {ok, I};
+binary_int_from_u32(_) ->
+ {error, nil}.