aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/binary.gleam53
-rw-r--r--src/gleam/bit_string.gleam54
-rw-r--r--src/gleam_stdlib.erl18
3 files changed, 63 insertions, 62 deletions
diff --git a/src/gleam/binary.gleam b/src/gleam/binary.gleam
deleted file mode 100644
index a469403..0000000
--- a/src/gleam/binary.gleam
+++ /dev/null
@@ -1,53 +0,0 @@
-//// Working with raw binary data.
-//// The Binary type should be used instead of a String type when not utf8
-//// encoded.
-
-pub external type Binary
-
-/// Convert a utf8 String type into a raw Binary type.
-///
-pub external fn from_string(String) -> Binary =
- "gleam_stdlib" "identity"
-
-/// Returns an integer which is the number of bytes in the binary.
-///
-pub external fn byte_size(Binary) -> Int =
- "erlang" "byte_size"
-
-/// Create a new binary by joining two binaries.
-///
-/// ## Examples
-///
-/// > append(to: from_string("butter"), suffix: from_string("fly"))
-/// from_string("butterfly")
-///
-pub external fn append(first: Binary, second: Binary) -> Binary =
- "gleam_stdlib" "binary_append"
-
-/// Extracts part of a binary.
-///
-/// Binary part will start at given position and continue up to specified
-/// length.
-/// A negative length can be used to extract bytes at the end of a binary.
-///
-pub external fn part(
- string: Binary,
- position: Int,
- length: Int,
-) -> Result(Binary, Nil) =
- "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) =
- "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) =
- "gleam_stdlib" "binary_int_from_u32"
diff --git a/src/gleam/bit_string.gleam b/src/gleam/bit_string.gleam
new file mode 100644
index 0000000..d6fe14d
--- /dev/null
+++ b/src/gleam/bit_string.gleam
@@ -0,0 +1,54 @@
+//// Working with raw bit string data.
+//// The BitString type should be used instead of a String type when not utf8
+//// encoded.
+
+// TODO: determine which of these functions once we have bit string syntax
+pub external type BitString
+
+/// Convert a utf8 String type into a raw Bitstring type.
+///
+pub external fn from_string(String) -> Bitstring =
+ "gleam_stdlib" "identity"
+
+/// Returns an integer which is the number of bytes in the bit string.
+///
+pub external fn byte_size(Bitstring) -> Int =
+ "erlang" "byte_size"
+
+/// Create a new bit string by joining two binaries.
+///
+/// ## Examples
+///
+/// > append(to: from_string("butter"), suffix: from_string("fly"))
+/// from_string("butterfly")
+///
+pub external fn append(first: Bitstring, second: Bitstring) -> Bitstring =
+ "gleam_stdlib" "bit_string_append"
+
+/// Extracts part of a bit string.
+///
+/// Bitstring part will start at given position and continue up to specified
+/// length.
+/// A negative length can be used to extract bytes at the end of a bit string.
+///
+pub external fn part(
+ string: Bitstring,
+ position: Int,
+ length: Int,
+) -> Result(Bitstring, Nil) =
+ "gleam_stdlib" "bit_string_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(Bitstring, Nil) =
+ "gleam_stdlib" "bit_string_int_to_u32"
+
+/// Convert unsigned 32 bits to an integer.
+///
+/// Returns an error if the bit string is not 32 bits in length.
+///
+pub external fn int_from_u32(Bitstring) -> Result(Int, Nil) =
+ "gleam_stdlib" "bit_string_int_from_u32"
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 376692b..a5dd804 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -8,8 +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, binary_int_to_u32/1,
- binary_int_from_u32/1, binary_append/2, binary_part_/3]).
+ string_pad/4, decode_tuple2/1, decode_map/1, bit_string_int_to_u32/1,
+ bit_string_int_from_u32/1, bit_string_append/2, bit_string_part_/3]).
should_equal(Actual, Expected) -> ?assertEqual(Expected, Actual).
should_not_equal(Actual, Expected) -> ?assertNotEqual(Expected, Actual).
@@ -141,20 +141,20 @@ string_pop_grapheme(String) ->
_ -> {error, nil}
end.
-binary_append(First, Second) ->
- <<First/binary, Second/binary>>.
+bit_string_append(First, Second) ->
+ <<First/bitstring, Second/bitstring>>.
-binary_part_(Bin, Pos, Len) ->
+bit_string_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 ->
+bit_string_int_to_u32(I) when 0 =< I, I < 4294967296 ->
{ok, <<I:32>>};
-binary_int_to_u32(_) ->
+bit_string_int_to_u32(_) ->
{error, nil}.
-binary_int_from_u32(<<I:32>>) ->
+bit_string_int_from_u32(<<I:32>>) ->
{ok, I};
-binary_int_from_u32(_) ->
+bit_string_int_from_u32(_) ->
{error, nil}.