-module(glentities@hex_encoder). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([encode/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/glentities/hex_encoder.gleam", 13). -spec do_encode(binary()) -> binary(). do_encode(Text) -> _pipe = Text, _pipe@1 = gleam@string:to_utf_codepoints(_pipe), _pipe@2 = gleam@list:map( _pipe@1, fun(Codepoint) -> case gleam_stdlib:identity(Codepoint) of C when ((((((C =:= 9) orelse (C =:= 10)) orelse (C =:= 13)) orelse (C =:= 32)) orelse ((C >= 48) andalso (C =< 57))) orelse ((C >= 65) andalso (C =< 90))) orelse ((C >= 97) andalso (C =< 122)) -> gleam_stdlib:utf_codepoint_list_to_string([Codepoint]); Encodable -> <<<<"&#x"/utf8, (gleam@int:to_base16(Encodable))/binary>>/binary, ";"/utf8>> end end ), gleam@string:join(_pipe@2, <<""/utf8>>). -file("src/glentities/hex_encoder.gleam", 7). ?DOC(" Encode text using HTML hex entities, except a-z, A-Z, 0-9, newline, tab, carriage return, and space.\n"). -spec encode(binary()) -> binary(). encode(Text) -> _pipe = Text, _pipe@1 = unicode:characters_to_nfc_binary(_pipe), do_encode(_pipe@1).