From a5581ccf55dbbfcf71260365aa773511b170a4d0 Mon Sep 17 00:00:00 2001 From: Michael Mark Date: Fri, 24 May 2024 18:42:25 -0700 Subject: Control characters 128-159 are now escaped Also added tests for this new case --- src/gleam_stdlib.erl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') 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 -> <> end, inspect_maybe_utf8_string(Rest, <>); _ -> {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)). -- cgit v1.2.3