Packages
base_emoji
1.0.0
Encoding to emoji designed to produce visually easily distinguished strings
Current section
Files
Jump to
Current section
Files
src/base_emoji.erl
-module(base_emoji).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/base_emoji.gleam").
-export([u8_from_bits/1, encode_with_version/2, encode/1]).
-export_type([map_version/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type map_version() :: v1.
-file("src/base_emoji.gleam", 11).
-spec version_to_map(map_version()) -> list({integer(), binary()}).
version_to_map(V) ->
case V of
v1 ->
[{0, <<"🍔"/utf8>>},
{1, <<"🦰"/utf8>>},
{2, <<"🌫"/utf8>>},
{3, <<"🈺"/utf8>>},
{4, <<"🧱"/utf8>>},
{5, <<"🛗"/utf8>>},
{6, <<"🎆"/utf8>>},
{7, <<"🚟"/utf8>>},
{8, <<"🏤"/utf8>>},
{9, <<"🗓"/utf8>>},
{10, <<"🖼"/utf8>>},
{11, <<"🌅"/utf8>>},
{12, <<"🖥"/utf8>>},
{13, <<"👹"/utf8>>},
{14, <<"🤡"/utf8>>},
{15, <<"🧖"/utf8>>},
{16, <<"🧮"/utf8>>},
{17, <<"💽"/utf8>>},
{18, <<"💏"/utf8>>},
{19, <<"🏟"/utf8>>},
{20, <<"🚞"/utf8>>},
{21, <<"📝"/utf8>>},
{22, <<"🎉"/utf8>>},
{23, <<"🏞"/utf8>>},
{24, <<"🤠"/utf8>>},
{25, <<"💓"/utf8>>},
{26, <<"🪯"/utf8>>},
{27, <<"📳"/utf8>>},
{28, <<"📠"/utf8>>},
{29, <<"🌞"/utf8>>},
{30, <<"🤗"/utf8>>},
{31, <<"🎬"/utf8>>},
{32, <<"💇"/utf8>>},
{33, <<"🚋"/utf8>>},
{34, <<"🚂"/utf8>>},
{35, <<"🎊"/utf8>>},
{36, <<"🥘"/utf8>>},
{37, <<"🥞"/utf8>>},
{38, <<"🎑"/utf8>>},
{39, <<"📉"/utf8>>},
{40, <<"🌉"/utf8>>},
{41, <<"🎒"/utf8>>},
{42, <<"🛟"/utf8>>},
{43, <<"🧾"/utf8>>},
{44, <<"🌇"/utf8>>},
{45, <<"🧏"/utf8>>},
{46, <<"🏭"/utf8>>},
{47, <<"🩻"/utf8>>},
{48, <<"🎞"/utf8>>},
{49, <<"🥦"/utf8>>},
{50, <<"🥙"/utf8>>},
{51, <<""/utf8>>},
{52, <<"🕌"/utf8>>},
{53, <<"🙀"/utf8>>},
{54, <<"🪩"/utf8>>},
{55, <<"🎰"/utf8>>},
{56, <<"🚉"/utf8>>},
{57, <<"🩳"/utf8>>},
{58, <<"🚝"/utf8>>},
{59, <<"🪔"/utf8>>},
{60, <<"💯"/utf8>>},
{61, <<"🧊"/utf8>>},
{62, <<"📆"/utf8>>},
{63, <<"🏪"/utf8>>},
{64, <<"🎇"/utf8>>},
{65, <<"🥮"/utf8>>},
{66, <<"👺"/utf8>>},
{67, <<"🚍"/utf8>>},
{68, <<"🎥"/utf8>>},
{69, <<"🚧"/utf8>>},
{70, <<"🌐"/utf8>>},
{71, <<"🧲"/utf8>>},
{72, <<"🏜"/utf8>>},
{73, <<"🚵"/utf8>>},
{74, <<"📜"/utf8>>},
{75, <<"🏾"/utf8>>},
{76, <<"🌠"/utf8>>},
{77, <<"🏥"/utf8>>},
{78, <<"🐯"/utf8>>},
{79, <<"🌆"/utf8>>},
{80, <<"🥝"/utf8>>},
{81, <<"🎎"/utf8>>},
{82, <<"🍱"/utf8>>},
{83, <<"🏢"/utf8>>},
{84, <<"🏬"/utf8>>},
{85, <<"🈲"/utf8>>},
{86, <<"🏦"/utf8>>},
{87, <<"🪣"/utf8>>},
{88, <<"👧"/utf8>>},
{89, <<"💥"/utf8>>},
{90, <<"🪅"/utf8>>},
{91, <<"🎼"/utf8>>},
{92, <<"🙆"/utf8>>},
{93, <<"🍊"/utf8>>},
{94, <<"🥶"/utf8>>},
{95, <<"🎛"/utf8>>},
{96, <<"🏂"/utf8>>},
{97, <<"🏗"/utf8>>},
{98, <<"📘"/utf8>>},
{99, <<"🕵"/utf8>>},
{100, <<"🧭"/utf8>>},
{101, <<"🏩"/utf8>>},
{102, <<"🗾"/utf8>>},
{103, <<"🚅"/utf8>>},
{104, <<"🌼"/utf8>>},
{105, <<"🫚"/utf8>>},
{106, <<"🚠"/utf8>>},
{107, <<"📚"/utf8>>},
{108, <<"🎹"/utf8>>},
{109, <<"📸"/utf8>>},
{110, <<"🥭"/utf8>>},
{111, <<"🌺"/utf8>>},
{112, <<"🎡"/utf8>>},
{113, <<"🧺"/utf8>>},
{114, <<"🎏"/utf8>>},
{115, <<"🚘"/utf8>>},
{116, <<"🛣"/utf8>>},
{117, <<"🫂"/utf8>>},
{118, <<"📢"/utf8>>},
{119, <<"👘"/utf8>>},
{120, <<"🍑"/utf8>>},
{121, <<"👻"/utf8>>},
{122, <<"🧗"/utf8>>},
{123, <<"🥵"/utf8>>},
{124, <<"🎢"/utf8>>},
{125, <<"🔐"/utf8>>},
{126, <<"🌀"/utf8>>},
{127, <<"🗄"/utf8>>},
{128, <<"🌏"/utf8>>},
{129, <<"🗑"/utf8>>},
{130, <<"🛺"/utf8>>},
{131, <<"🎁"/utf8>>},
{132, <<"🪟"/utf8>>},
{133, <<"🫨"/utf8>>},
{134, <<"👭"/utf8>>},
{135, <<"🌌"/utf8>>},
{136, <<"🏯"/utf8>>},
{137, <<"🏡"/utf8>>},
{138, <<"🚇"/utf8>>},
{139, <<"📽"/utf8>>},
{140, <<"🪙"/utf8>>},
{141, <<"🐲"/utf8>>},
{142, <<"🧶"/utf8>>},
{143, <<"🔲"/utf8>>},
{144, <<"🥨"/utf8>>},
{145, <<"🖇"/utf8>>},
{146, <<"🏕"/utf8>>},
{147, <<"👑"/utf8>>},
{148, <<"🥋"/utf8>>},
{149, <<"😈"/utf8>>},
{150, <<"💱"/utf8>>},
{151, <<"🥁"/utf8>>},
{152, <<"🍢"/utf8>>},
{153, <<"🏰"/utf8>>},
{154, <<"🛠"/utf8>>},
{155, <<"💻"/utf8>>},
{156, <<"🌿"/utf8>>},
{157, <<"🤶"/utf8>>},
{158, <<"🪴"/utf8>>},
{159, <<""/utf8>>},
{160, <<"💸"/utf8>>},
{161, <<"🤯"/utf8>>},
{162, <<"🛍"/utf8>>},
{163, <<"🫓"/utf8>>},
{164, <<"🥐"/utf8>>},
{165, <<"🐼"/utf8>>},
{166, <<"🧰"/utf8>>},
{167, <<"🚴"/utf8>>},
{168, <<"🗳"/utf8>>},
{169, <<"🥸"/utf8>>},
{170, <<"🏵"/utf8>>},
{171, <<"📖"/utf8>>},
{172, <<"📇"/utf8>>},
{173, <<"💐"/utf8>>},
{174, <<"🥳"/utf8>>},
{175, <<"💞"/utf8>>},
{176, <<"🗒"/utf8>>},
{177, <<"🛀"/utf8>>},
{178, <<"🚚"/utf8>>},
{179, <<"💹"/utf8>>},
{180, <<"🌄"/utf8>>},
{181, <<"📻"/utf8>>},
{182, <<"🧟"/utf8>>},
{183, <<"🖨"/utf8>>},
{184, <<"🍣"/utf8>>},
{185, <<"🦲"/utf8>>},
{186, <<"🌊"/utf8>>},
{187, <<"🚭"/utf8>>},
{188, <<"🌽"/utf8>>},
{189, <<"🫠"/utf8>>},
{190, <<"📲"/utf8>>},
{191, <<"🏈"/utf8>>},
{192, <<"🩰"/utf8>>},
{193, <<"💒"/utf8>>},
{194, <<"🌰"/utf8>>},
{195, <<"🎂"/utf8>>},
{196, <<"💖"/utf8>>},
{197, <<"🏣"/utf8>>},
{198, <<"🧩"/utf8>>},
{199, <<"🏐"/utf8>>},
{200, <<"🍘"/utf8>>},
{201, <<"🥠"/utf8>>},
{202, <<"🤣"/utf8>>},
{203, <<"🏻"/utf8>>},
{204, <<"🐒"/utf8>>},
{205, <<"🔱"/utf8>>},
{206, <<"🪤"/utf8>>},
{207, <<"🥩"/utf8>>},
{208, <<"🎾"/utf8>>},
{209, <<"🍈"/utf8>>},
{210, <<"📰"/utf8>>},
{211, <<"🛸"/utf8>>},
{212, <<"🏠"/utf8>>},
{213, <<"🏄"/utf8>>},
{214, <<"🦥"/utf8>>},
{215, <<"🏆"/utf8>>},
{216, <<"🤢"/utf8>>},
{217, <<"🚈"/utf8>>},
{218, <<"🦺"/utf8>>},
{219, <<"🎳"/utf8>>},
{220, <<"🛳"/utf8>>},
{221, <<"🌋"/utf8>>},
{222, <<"👔"/utf8>>},
{223, <<"🥯"/utf8>>},
{224, <<"🙇"/utf8>>},
{225, <<"🎧"/utf8>>},
{226, <<"🎀"/utf8>>},
{227, <<"👯"/utf8>>},
{228, <<"👪"/utf8>>},
{229, <<"🧙"/utf8>>},
{230, <<"🥏"/utf8>>},
{231, <<"🥷"/utf8>>},
{232, <<"🔊"/utf8>>},
{233, <<"🧽"/utf8>>},
{234, <<"👛"/utf8>>},
{235, <<"🤽"/utf8>>},
{236, <<"🦮"/utf8>>},
{237, <<"🍪"/utf8>>},
{238, <<"🫣"/utf8>>},
{239, <<"🕰"/utf8>>},
{240, <<"💭"/utf8>>},
{241, <<"🫁"/utf8>>},
{242, <<"💦"/utf8>>},
{243, <<"🏹"/utf8>>},
{244, <<"🌬"/utf8>>},
{245, <<"🧧"/utf8>>},
{246, <<"💢"/utf8>>},
{247, <<"🛼"/utf8>>},
{248, <<"🎯"/utf8>>},
{249, <<"🫒"/utf8>>},
{250, <<"🚿"/utf8>>},
{251, <<"🍂"/utf8>>},
{252, <<"🚔"/utf8>>},
{253, <<"🐝"/utf8>>},
{254, <<"🪀"/utf8>>},
{255, <<"🍝"/utf8>>}]
end.
-file("src/base_emoji.gleam", 64).
?DOC(
" Takes a byte from the front of the given array. If the bit array is not empty\n"
" returns Ok tuple with the first item being a bit array filled with the taken bits\n"
" and padded to length 8. The second item is the remaining bits. If the input is empty,\n"
" Error(Nil) is returned.\n"
).
-spec take_byte(bitstring()) -> {ok, {bitstring(), bitstring()}} | {error, nil}.
take_byte(B) ->
case begin
_pipe = B,
erlang:bit_size(_pipe)
end of
0 ->
{error, nil};
C when C =< 8 ->
Taken@1 = case begin
_pipe@1 = B,
_pipe@2 = gleam_stdlib:bit_array_pad_to_bytes(_pipe@1),
gleam_stdlib:bit_array_slice(_pipe@2, 0, 1)
end of
{ok, Taken} -> Taken;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"base_emoji"/utf8>>,
function => <<"take_byte"/utf8>>,
line => 69,
value => _assert_fail,
start => 2088,
'end' => 2171,
pattern_start => 2099,
pattern_end => 2108})
end,
{ok,
{begin
_pipe@3 = Taken@1,
gleam_stdlib:bit_array_pad_to_bytes(_pipe@3)
end,
<<>>}};
C@1 ->
Taken@3 = case begin
_pipe@4 = B,
gleam_stdlib:bit_array_slice(_pipe@4, 0, 1)
end of
{ok, Taken@2} -> Taken@2;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"base_emoji"/utf8>>,
function => <<"take_byte"/utf8>>,
line => 75,
value => _assert_fail@1,
start => 2275,
'end' => 2324,
pattern_start => 2286,
pattern_end => 2295})
end,
Remaining@1 = case begin
_pipe@5 = B,
gleam_stdlib:bit_array_slice(_pipe@5, 1, (C@1 div 8) - 1)
end of
{ok, Remaining} -> Remaining;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"base_emoji"/utf8>>,
function => <<"take_byte"/utf8>>,
line => 76,
value => _assert_fail@2,
start => 2331,
'end' => 2392,
pattern_start => 2342,
pattern_end => 2355})
end,
{ok, {Taken@3, Remaining@1}}
end.
-file("src/base_emoji.gleam", 85).
?DOC(false).
-spec u8_from_bits(bitstring()) -> {ok, integer()} | {error, nil}.
u8_from_bits(B) ->
case begin
_pipe = B,
erlang:bit_size(_pipe)
end of
C when C =:= 8 ->
{ok,
begin
_pipe@1 = B,
'Elixir.BaseEmoji':u8_from_bits(_pipe@1)
end};
_ ->
{error, nil}
end.
-file("src/base_emoji.gleam", 48).
?DOC(
" Takes a byte int from the front of the given BitArray, converts it to\n"
" an Int guaranteed to be 0-255. The remaining bits after this operation are also returned.\n"
" If the BitArray is empty, Error(nil) is returned.\n"
).
-spec take_int(bitstring()) -> {ok, {integer(), bitstring()}} | {error, nil}.
take_int(B) ->
case begin
_pipe = B,
take_byte(_pipe)
end of
{ok, {First, Rest}} ->
case begin
_pipe@1 = First,
u8_from_bits(_pipe@1)
end of
{ok, Int} ->
{ok, {Int, Rest}};
{error, _} ->
{error, nil}
end;
{error, _} ->
{error, nil}
end.
-file("src/base_emoji.gleam", 34).
-spec encode_inner(bitstring(), list({integer(), binary()}), binary()) -> binary().
encode_inner(B, Map, State) ->
case begin
_pipe = B,
erlang:bit_size(_pipe)
end of
0 ->
State;
_ ->
{Int@1, Rest@1} = case begin
_pipe@1 = B,
take_int(_pipe@1)
end of
{ok, {Int, Rest}} -> {Int, Rest};
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"base_emoji"/utf8>>,
function => <<"encode_inner"/utf8>>,
line => 38,
value => _assert_fail,
start => 987,
'end' => 1030,
pattern_start => 998,
pattern_end => 1014})
end,
Next@1 = case begin
_pipe@2 = Map,
gleam@list:key_find(_pipe@2, Int@1)
end of
{ok, Next} -> Next;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"base_emoji"/utf8>>,
function => <<"encode_inner"/utf8>>,
line => 39,
value => _assert_fail@1,
start => 1037,
'end' => 1084,
pattern_start => 1048,
pattern_end => 1056})
end,
encode_inner(Rest@1, Map, <<State/binary, Next@1/binary>>)
end.
-file("src/base_emoji.gleam", 28).
?DOC(
" Econdes the given bit array with the requested emoji map\n"
" Unless you have need of a constant display, [encode](#encode) should\n"
" be preferred to get the latest map, which attempts to maximize the\n"
" visual difference between two arrays\n"
).
-spec encode_with_version(bitstring(), map_version()) -> binary().
encode_with_version(B, V) ->
Map = begin
_pipe = V,
version_to_map(_pipe)
end,
Byte_size = begin
_pipe@1 = B,
erlang:byte_size(_pipe@1)
end,
_pipe@2 = B,
_pipe@3 = 'Elixir.Gblake3':hash_len(_pipe@2, Byte_size),
encode_inner(_pipe@3, Map, <<""/utf8>>).
-file("src/base_emoji.gleam", 20).
?DOC(" Encodes the given bit array with the latest emoji map\n").
-spec encode(bitstring()) -> binary().
encode(B) ->
_pipe = B,
encode_with_version(_pipe, v1).