-module(gftp@command@feat). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/gftp/command/feat.gleam"). -export([is_last_line/1, parse_features/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(" This module exposes the FEAT command types\n"). -file("src/gftp/command/feat.gleam", 16). ?DOC(" Returns whether the given line is the last line of a FEAT response, which starts with \"211 \".\n"). -spec is_last_line(binary()) -> boolean(). is_last_line(Line) -> gleam_stdlib:string_starts_with(Line, <<"211 "/utf8>>). -file("src/gftp/command/feat.gleam", 49). ?DOC(" Checks if the given line starts with a space, and if so, trims it. Otherwise, returns an error.\n"). -spec trim_line(binary()) -> {ok, binary()} | {error, gftp@result:ftp_error()}. trim_line(Line) -> case gleam_stdlib:string_starts_with(Line, <<" "/utf8>>) of true -> {ok, gleam@string:trim(Line)}; false -> {error, bad_response} end. -file("src/gftp/command/feat.gleam", 37). ?DOC(" Parses a single line of a FEAT response into a key-value pair.\n"). -spec parse_feature(binary()) -> {ok, {binary(), gleam@option:option(binary())}} | {error, gftp@result:ftp_error()}. parse_feature(Line) -> gleam@result:'try'( trim_line(Line), fun(Trimmed_line) -> Tokens = gleam@string:split(Trimmed_line, <<" "/utf8>>), case Tokens of [] -> {error, bad_response}; [Key] -> {ok, {Key, none}}; [Key@1 | Rest] -> {ok, {Key@1, {some, gleam@string:join(Rest, <<" "/utf8>>)}}} end end ). -file("src/gftp/command/feat.gleam", 26). ?DOC(" Helper function to recursively parse the lines of a FEAT response into a `Features` dictionary.\n"). -spec parse_feature_loop( gleam@dict:dict(binary(), gleam@option:option(binary())), list(binary()) ) -> {ok, gleam@dict:dict(binary(), gleam@option:option(binary()))} | {error, gftp@result:ftp_error()}. parse_feature_loop(Acc, Lines) -> case Lines of [] -> {ok, Acc}; [Line | Rest] -> gleam@result:'try'( parse_feature(Line), fun(_use0) -> {Key, Value} = _use0, parse_feature_loop(gleam@dict:insert(Acc, Key, Value), Rest) end ) end. -file("src/gftp/command/feat.gleam", 21). ?DOC(" Parses the lines of a FEAT response into a `Features` dictionary.\n"). -spec parse_features(list(binary())) -> {ok, gleam@dict:dict(binary(), gleam@option:option(binary()))} | {error, gftp@result:ftp_error()}. parse_features(Lines) -> parse_feature_loop(maps:new(), Lines).