Current section
Files
Jump to
Current section
Files
src/url_join@query.erl
-module(url_join@query).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/url_join/query.gleam").
-export([normalize/1]).
-file("src/url_join/query.gleam", 40).
-spec split_query_parts(binary()) -> list(binary()).
split_query_parts(S) ->
_pipe = gleam@string:replace(S, <<"?"/utf8>>, <<"&"/utf8>>),
_pipe@1 = gleam@string:split(_pipe, <<"&"/utf8>>),
gleam@list:filter(_pipe@1, fun(X) -> not gleam@string:is_empty(X) end).
-file("src/url_join/query.gleam", 13).
-spec normalize_params(binary()) -> binary().
normalize_params(S) ->
case gleam@string:split_once(S, <<"#"/utf8>>) of
{ok, {Before_hash, After_hash}} ->
Hash_suffix = case gleam@string:is_empty(After_hash) of
true ->
<<""/utf8>>;
false ->
<<"#"/utf8, After_hash/binary>>
end,
Parts = split_query_parts(Before_hash),
case Parts of
[] ->
S;
[Path] ->
<<Path/binary, Hash_suffix/binary>>;
[Path@1 | Params] ->
<<<<<<Path@1/binary, "?"/utf8>>/binary,
(gleam@string:join(Params, <<"&"/utf8>>))/binary>>/binary,
Hash_suffix/binary>>
end;
{error, _} ->
Parts@1 = split_query_parts(S),
case Parts@1 of
[] ->
S;
[Path@2] ->
Path@2;
[Path@3 | Params@1] ->
<<<<Path@3/binary, "?"/utf8>>/binary,
(gleam@string:join(Params@1, <<"&"/utf8>>))/binary>>
end
end.
-file("src/url_join/query.gleam", 4).
-spec normalize(binary()) -> binary().
normalize(S) ->
No_slash_before_special = gleam@string:replace(
S,
<<"/?"/utf8>>,
<<"?"/utf8>>
),
No_slash_before_hash = gleam@string:replace(
No_slash_before_special,
<<"/#"/utf8>>,
<<"#"/utf8>>
),
No_slash_before_amp = gleam@string:replace(
No_slash_before_hash,
<<"/&"/utf8>>,
<<"&"/utf8>>
),
normalize_params(No_slash_before_amp).