aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/int.gleam2
-rw-r--r--src/gleam_stdlib.erl9
2 files changed, 9 insertions, 2 deletions
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam
index 785e8c0..76bde60 100644
--- a/src/gleam/int.gleam
+++ b/src/gleam/int.gleam
@@ -192,7 +192,7 @@ pub fn from_base_string(string: String, base: Int) -> Result(Int, Nil) {
if erlang {
external fn do_from_base_string(String, Int) -> Result(Int, Nil) =
- "erlang" "binary_to_integer"
+ "gleam_stdlib" "int_from_base_string"
}
if javascript {
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 39721f1..b5d6ce6 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -10,7 +10,8 @@
percent_encode/1, percent_decode/1, regex_check/2, regex_split/2,
base_decode64/1, parse_query/1, bit_string_concat/1, size_of_tuple/1,
decode_tuple/1, tuple_get/2, classify_dynamic/1, print/1, println/1,
- print_error/1, println_error/1, inspect/1, float_to_string/1]).
+ print_error/1, println_error/1, inspect/1, float_to_string/1,
+ int_from_base_string/2]).
%% Taken from OTP's uri_string module
-define(DEC2HEX(X),
@@ -118,6 +119,12 @@ decode_result(Term) ->
_ -> decode_error_msg(<<"Result">>, Term)
end.
+int_from_base_string(String, Base) ->
+ case catch binary_to_integer(String, Base) of
+ Int when is_integer(Int) -> {ok, Int};
+ _ -> {error, nil}
+ end.
+
parse_int(String) ->
case catch binary_to_integer(String) of
Int when is_integer(Int) -> {ok, Int};