aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gleam_stdlib.erl16
-rw-r--r--test/gleam/string_test.gleam6
2 files changed, 15 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)).
diff --git a/test/gleam/string_test.gleam b/test/gleam/string_test.gleam
index 9a1a315..f3c56a8 100644
--- a/test/gleam/string_test.gleam
+++ b/test/gleam/string_test.gleam
@@ -709,6 +709,12 @@ pub fn inspect_test() {
string.inspect("\u{007F}")
|> should.equal("\"\\u{007F}\"")
+ string.inspect("\u{009F}")
+ |> should.equal("\"\\u{009F}\"")
+
+ string.inspect("\u{00A0}")
+ |> should.equal("\"\u{00A0}\"")
+
string.inspect("\r\r")
|> should.equal("\"\\r\\r\"")