aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2020-05-29 20:48:34 +0100
committerLouis Pilfold <louis@lpil.uk>2020-05-29 20:48:34 +0100
commit692a60c412ee61a440b28316ecf02b0c3a25b90a (patch)
tree17dfd9bae5f275eb717d7d046d60960dbb2f283b /src
parentc3be00d7c1a869c94236887bc539af4998e64cd2 (diff)
downloadgleam_stdlib-692a60c412ee61a440b28316ecf02b0c3a25b90a.tar.gz
gleam_stdlib-692a60c412ee61a440b28316ecf02b0c3a25b90a.zip
Merge Erlang modules
Diffstat (limited to 'src')
-rw-r--r--src/gleam/binary.gleam8
-rw-r--r--src/gleam/binary_native.erl20
-rw-r--r--src/gleam_stdlib.erl21
3 files changed, 24 insertions, 25 deletions
diff --git a/src/gleam/binary.gleam b/src/gleam/binary.gleam
index c83b5e1..d830273 100644
--- a/src/gleam/binary.gleam
+++ b/src/gleam/binary.gleam
@@ -19,7 +19,7 @@ pub external fn byte_size(Binary) -> Int =
/// "butterfly"
///
pub external fn append(first: Binary, second: Binary) -> Binary =
- "binary_native" "append"
+ "gleam_stdlib" "binary_append"
/// Extracts part of a binary.
///
@@ -30,16 +30,16 @@ pub external fn part(
position: Int,
length: Int,
) -> Result(Binary, Nil) =
- "binary_native" "part"
+ "gleam_stdlib" "binary_part_"
/// Convert an integer to unsigned 32 bits.
///
/// Returns an error if integer is less than zero or equal to or larger than 2^32.
pub external fn int_to_u32(Int) -> Result(Binary, Nil) =
- "binary_native" "int_to_u32"
+ "gleam_stdlib" "binary_int_to_u32"
/// Convert unsigned 32 bits to an integer
///
/// Returns an error if the binary is not 32 bits in length.
pub external fn int_from_u32(Binary) -> Result(Int, Nil) =
- "binary_native" "int_from_u32"
+ "gleam_stdlib" "binary_int_from_u32"
diff --git a/src/gleam/binary_native.erl b/src/gleam/binary_native.erl
deleted file mode 100644
index c7dfad7..0000000
--- a/src/gleam/binary_native.erl
+++ /dev/null
@@ -1,20 +0,0 @@
--module (binary_native).
--export ([int_to_u32/1, int_from_u32/1, append/2, part/3]).
-
-append(First, Second) ->
- <<First/binary, Second/binary>>.
-
-part(Bin, Pos, Len) ->
- try {ok, binary:part(Bin, Pos, Len)} catch
- error:badarg -> {error, nil}
- end.
-
-int_to_u32(I) when 0 =< I, I < 4294967296 ->
- {ok, <<I:32>>};
-int_to_u32(_) ->
- {error, nil}.
-
-int_from_u32(<<I:32>>) ->
- {ok, I};
-int_from_u32(_) ->
- {error, nil}.
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}.