aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.erl
diff options
context:
space:
mode:
authorMichael Mark <michael.mark@oit.edu>2024-05-24 18:42:25 -0700
committerLouis Pilfold <louis@lpil.uk>2024-05-29 12:26:22 +0100
commita5581ccf55dbbfcf71260365aa773511b170a4d0 (patch)
tree0aca0784ab0b5e5a16b227b8906967488504eb0d /src/gleam_stdlib.erl
parentb152317a0bacbc7e17d22ffa30d3d1dc22c813df (diff)
downloadgleam_stdlib-a5581ccf55dbbfcf71260365aa773511b170a4d0.tar.gz
gleam_stdlib-a5581ccf55dbbfcf71260365aa773511b170a4d0.zip
Control characters 128-159 are now escaped
Also added tests for this new case
Diffstat (limited to 'src/gleam_stdlib.erl')
-rw-r--r--src/gleam_stdlib.erl16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 230ca4c..c1b6a1c 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -498,19 +498,21 @@ inspect_maybe_utf8_string(Binary, Acc) ->
$\n -> <<$\\, $n>>;
$\t -> <<$\\, $t>>;
$\f -> <<$\\, $f>>;
- 127 -> <<$\\, $u, ${, $0, $0, $7, $F, $}>>;
- X when X < 32 ->
- Hex = integer_to_list(X, 16),
- Leading = lists:duplicate(4 - length(Hex), "0"),
- Formatted = lists:append(Leading, Hex),
- Bin = list_to_binary(Formatted),
- <<$\\, $u, ${, Bin/binary, $}>>;
+ X when X > 126, X < 160 -> convert_to_u(X);
+ X when X < 32 -> convert_to_u(X);
Other -> <<Other/utf8>>
end,
inspect_maybe_utf8_string(Rest, <<Acc/binary, Escaped/binary>>);
_ -> {error, not_a_utf8_string}
end.
+convert_to_u(Code) ->
+ Hex = integer_to_list(Code, 16),
+ Leading = lists:duplicate(4 - length(Hex), "0"),
+ Formatted = lists:append(Leading, Hex),
+ Bin = list_to_binary(Formatted),
+ <<$\\, $u, ${, Bin/binary, $}>>.
+
float_to_string(Float) when is_float(Float) ->
erlang:iolist_to_binary(io_lib_format:fwrite_g(Float)).