aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam_stdlib.erl8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index edf3d6e..e8cc7e4 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -131,7 +131,11 @@ string_ends_with(String, Suffix) ->
Suffix == binary_part(String, byte_size(String) - SuffixSize, SuffixSize).
string_pad(String, Length, Dir, PadString) ->
- unicode:characters_to_binary(string:pad(String, Length, Dir, PadString)).
+ Chars = string:pad(String, Length, Dir, binary_to_list(PadString)),
+ case unicode:characters_to_binary(Chars) of
+ Bin when is_binary(Bin) -> Bin;
+ Error -> erlang:error({gleam_error, {string_invalid_utf8, Error}})
+ end.
string_pop_grapheme(String) ->
case string:next_grapheme(String) of
@@ -216,4 +220,4 @@ get_line(Prompt) ->
eof -> {error, eof};
{error, _} -> {error, no_data};
Data -> {ok, Data}
- end. \ No newline at end of file
+ end.