Current section
Files
Jump to
Current section
Files
src/roundabout@constant.erl
-module(roundabout@constant).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/roundabout/constant.gleam").
-export([new/1, unsafe/1, value/1]).
-export_type([constant/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.
-opaque constant() :: {constant, binary()}.
-file("src/roundabout/constant.gleam", 10).
?DOC(false).
-spec new(binary()) -> {ok, constant()} | {error, binary()}.
new(Value) ->
Re@1 = case gleam@regexp:from_string(<<"^[a-zA-Z0-9._~%-]+$"/utf8>>) of
{ok, Re} -> Re;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"roundabout/constant"/utf8>>,
function => <<"new"/utf8>>,
line => 11,
value => _assert_fail,
start => 175,
'end' => 236,
pattern_start => 186,
pattern_end => 192})
end,
Candidate = string:lowercase(Value),
case gleam@regexp:check(Re@1, Candidate) of
true ->
{ok, {constant, Candidate}};
false ->
{error, <<"Invalid constant value "/utf8, Value/binary>>}
end.
-file("src/roundabout/constant.gleam", 22).
?DOC(false).
-spec unsafe(binary()) -> constant().
unsafe(Value) ->
{constant, Value}.
-file("src/roundabout/constant.gleam", 27).
?DOC(false).
-spec value(constant()) -> binary().
value(Input) ->
erlang:element(2, Input).