aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.erl
diff options
context:
space:
mode:
authorJoshua Reusch <jreusch4@gmail.com>2024-08-12 01:12:19 +0200
committerLouis Pilfold <louis@lpil.uk>2024-08-13 19:06:15 +0200
commitb01cf7a707338abb57e4ccf1383a4c11b195af4c (patch)
tree2084d1920d544de83b647e6e439140525b04e048 /src/gleam_stdlib.erl
parent01f05ae7c1e0de7248d592fbfc9073c6284e8ed7 (diff)
downloadgleam_stdlib-b01cf7a707338abb57e4ccf1383a4c11b195af4c.tar.gz
gleam_stdlib-b01cf7a707338abb57e4ccf1383a4c11b195af4c.zip
improve pop_grapheme performance
Diffstat (limited to 'src/gleam_stdlib.erl')
-rw-r--r--src/gleam_stdlib.erl6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 97b8831..0b4aae5 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -194,8 +194,12 @@ string_pad(String, Length, Dir, PadString) ->
string_pop_grapheme(String) ->
case string:next_grapheme(String) of
- [ Next | Rest ] ->
+ [ Next | Rest ] when is_binary(Rest) ->
+ {ok, {unicode:characters_to_binary([Next]), Rest}};
+
+ [ Next | Rest ] ->
{ok, {unicode:characters_to_binary([Next]), unicode:characters_to_binary(Rest)}};
+
_ -> {error, nil}
end.