aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.erl
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-08-19 17:16:25 +0100
committerLouis Pilfold <louis@lpil.uk>2024-08-19 17:16:25 +0100
commit9789d26a5faa2ff284448387f5c6ff5131fef275 (patch)
tree56af9c6e40207581addf2810c46a774c6647e807 /src/gleam_stdlib.erl
parent1962beacc59f37c1db782e79e90358cb14315c18 (diff)
downloadgleam_stdlib-9789d26a5faa2ff284448387f5c6ff5131fef275.tar.gz
gleam_stdlib-9789d26a5faa2ff284448387f5c6ff5131fef275.zip
Fix slice
Closes https://github.com/gleam-lang/gleam/issues/3499
Diffstat (limited to 'src/gleam_stdlib.erl')
-rw-r--r--src/gleam_stdlib.erl8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 0b4aae5..0941a33 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -14,7 +14,7 @@
decode_tuple5/1, decode_tuple6/1, tuple_get/2, classify_dynamic/1, print/1,
println/1, print_error/1, println_error/1, inspect/1, float_to_string/1,
int_from_base_string/2, utf_codepoint_list_to_string/1, contains_string/2,
- crop_string/2, base16_decode/1, string_replace/3, regex_replace/3
+ crop_string/2, base16_decode/1, string_replace/3, regex_replace/3, slice/3
]).
%% Taken from OTP's uri_string module
@@ -547,3 +547,9 @@ base16_decode(String) ->
string_replace(String, Pattern, Replacement) ->
string:replace(String, Pattern, Replacement, all).
+
+slice(String, Index, Length) ->
+ case string:slice(String, Index, Length) of
+ X when is_binary(X) -> X;
+ X when is_list(X) -> unicode:characters_to_binary(X)
+ end.