-module(gftp@utils). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/gftp/utils.gleam"). -export([extract_str/2, re_matches/2, parse_int/1, parse_month/1, response_to_string/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. -file("src/gftp/utils.gleam", 12). ?DOC(" Get the substring enclosed in the provided token.\n"). -spec extract_str(binary(), binary()) -> {ok, binary()} | {error, nil}. extract_str(Body, Token) -> case gleam@string:split(Body, Token) of [_ | 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/utils.gleam", 25). ?DOC(" A helper function to match a regular expression against a string and extract the submatches as a list of strings.\n"). -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/utils.gleam", 40). ?DOC(" A helper function to parse a string into an integer, returning an ftp error if the parsing fails.\n"). -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/utils.gleam", 48). ?DOC(" A helper function to parse a string into a Month\n"). -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/utils.gleam", 58). ?DOC(" A helper function to convert a Response to a String, returning an ftp error if the conversion fails.\n"). -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).