Current section
Files
Jump to
Current section
Files
src/gftp@internal@utils.erl
-module(gftp@internal@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gftp/internal/utils.gleam").
-export([extract_str/2, re_matches/2, parse_int/1, parse_month/1, response_to_string/1, is_ipv6_address/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.
?MODULEDOC(false).
-file("src/gftp/internal/utils.gleam", 15).
?DOC(false).
-spec extract_str(binary(), binary()) -> {ok, binary()} | {error, nil}.
extract_str(Body, Token) ->
case gleam@string:split(Body, Token) of
[_] ->
{error, nil};
[_, Single] ->
{ok, Single};
[_ | Rest] ->
_pipe = Rest,
_pipe@1 = gleam@list:take(_pipe, erlang:length(Rest) - 1),
_pipe@2 = gleam@string:join(_pipe@1, Token),
{ok, _pipe@2};
_ ->
{error, nil}
end.
-file("src/gftp/internal/utils.gleam", 30).
?DOC(false).
-spec re_matches(gleam@regexp:regexp(), binary()) -> {ok,
list(gleam@option:option(binary()))} |
{error, nil}.
re_matches(Re, Line) ->
case gleam@regexp:scan(Re, Line) of
[] ->
{error, nil};
Matches ->
_pipe = Matches,
_pipe@1 = gleam@list:map(
_pipe,
fun(Match) -> erlang:element(3, Match) end
),
_pipe@2 = lists:append(_pipe@1),
{ok, _pipe@2}
end.
-file("src/gftp/internal/utils.gleam", 45).
?DOC(false).
-spec parse_int(binary()) -> {ok, integer()} | {error, gftp@result:ftp_error()}.
parse_int(S) ->
case gleam_stdlib:parse_int(S) of
{ok, I} ->
{ok, I};
{error, _} ->
{error, bad_response}
end.
-file("src/gftp/internal/utils.gleam", 53).
?DOC(false).
-spec parse_month(binary()) -> {ok, gleam@time@calendar:month()} |
{error, gftp@result:ftp_error()}.
parse_month(S) ->
gleam@result:'try'(
parse_int(S),
fun(Num) -> case gleam@time@calendar:month_from_int(Num) of
{ok, Month} ->
{ok, Month};
{error, _} ->
{error, bad_response}
end end
).
-file("src/gftp/internal/utils.gleam", 63).
?DOC(false).
-spec response_to_string(gftp@response:response()) -> {ok, binary()} |
{error, gftp@result:ftp_error()}.
response_to_string(Response) ->
_pipe = Response,
_pipe@1 = gftp@response:to_string(_pipe),
gleam@result:map_error(_pipe@1, fun(_) -> bad_response end).
-file("src/gftp/internal/utils.gleam", 70).
?DOC(false).
-spec is_ipv6_address(binary()) -> boolean().
is_ipv6_address(S) ->
gleam_stdlib:contains_string(S, <<":"/utf8>>).