Current section

Files

Jump to
roundabout src roundabout@internal@fixed.erl
Raw

src/roundabout@internal@fixed.erl

-module(roundabout@internal@fixed).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/roundabout/internal/fixed.gleam").
-export([new/1, unsafe/1, value/1]).
-export_type([fixed/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.
?MODULEDOC(false).
-opaque fixed() :: {fixed, binary()}.
-file("src/roundabout/internal/fixed.gleam", 8).
?DOC(false).
-spec new(binary()) -> {ok, fixed()} | {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/internal/fixed"/utf8>>,
function => <<"new"/utf8>>,
line => 9,
value => _assert_fail,
start => 146,
'end' => 207,
pattern_start => 157,
pattern_end => 163})
end,
Candidate = string:lowercase(Value),
case gleam@regexp:check(Re@1, Candidate) of
true ->
{ok, {fixed, Candidate}};
false ->
{error, <<"Invalid fixed value "/utf8, Value/binary>>}
end.
-file("src/roundabout/internal/fixed.gleam", 19).
?DOC(false).
-spec unsafe(binary()) -> fixed().
unsafe(Value) ->
{fixed, Value}.
-file("src/roundabout/internal/fixed.gleam", 23).
?DOC(false).
-spec value(fixed()) -> binary().
value(Input) ->
erlang:element(2, Input).