aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.erl
diff options
context:
space:
mode:
authorErik Terpstra <erterpstra@gmail.com>2020-05-20 09:34:52 +0200
committerLouis Pilfold <louis@lpil.uk>2020-05-22 12:47:08 +0100
commit088ed8c9fcaaab0a434a29eb26175d4452f4b179 (patch)
tree9523b08edbb5f818c2eb1e416becd92ef554fec0 /src/gleam_stdlib.erl
parent2109886ed8a7fc9aae1a2f5f9fb4e85cc29f49e5 (diff)
downloadgleam_stdlib-088ed8c9fcaaab0a434a29eb26175d4452f4b179.tar.gz
gleam_stdlib-088ed8c9fcaaab0a434a29eb26175d4452f4b179.zip
string.next_grapheme
Diffstat (limited to 'src/gleam_stdlib.erl')
-rw-r--r--src/gleam_stdlib.erl11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 0efedec..fc5499c 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -8,8 +8,8 @@
decode_int/1, decode_string/1, decode_bool/1, decode_float/1,
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_starts_with/2, string_ends_with/2, string_pad/4,
- decode_tuple2/1, decode_map/1]).
+ string_pop_grapheme/1, string_starts_with/2, string_ends_with/2,
+ string_pad/4, decode_tuple2/1, decode_map/1]).
should_equal(Actual, Expected) -> ?assertEqual(Expected, Actual).
should_not_equal(Actual, Expected) -> ?assertNotEqual(Expected, Actual).
@@ -135,3 +135,10 @@ string_ends_with(String, Suffix) ->
string_pad(String, Length, Dir, PadString) ->
unicode:characters_to_binary(string:pad(String, Length, Dir, PadString)).
+
+string_pop_grapheme(String) ->
+ case string:next_grapheme(String) of
+ [ Next | Rest ] ->
+ {ok, {unicode:characters_to_binary([Next]), unicode:characters_to_binary(Rest)}};
+ _ -> {error, nil}
+ end.