Current section
Files
Jump to
Current section
Files
gen/src/gleam@path.erl
-module(gleam@path).
-compile(no_auto_import).
-export([absolute/1, basename/1, extension/1, split/1, join/1, kind/1]).
absolute(A) ->
filename:absname(A).
basename(A) ->
filename:basename(A).
extension(A) ->
filename:extension(A).
split(A) ->
filename:split(A).
join(A) ->
filename:join(A).
kind(Path) ->
{K, _} = case gleam_file_bridge:os_family() of
win32 ->
win32_path_kind(Path);
unix ->
unix_path_kind(Path)
end,
K.
unix_path_kind(Path) ->
case Path of
<<"/"/utf8>> ->
{absolute, <<"."/utf8>>};
<<"/"/utf8, _/binary>> ->
{absolute, gleam@string:drop_left(Path, 1)};
_ ->
{relative, Path}
end.
win32_path_kind(Path) ->
case Path of
<<"\\\\"/utf8, _/binary>> ->
{absolute, gleam@string:drop_left(Path, 2)};
<<"//"/utf8, _/binary>> ->
{absolute, gleam@string:drop_left(Path, 2)};
<<"\\"/utf8, _/binary>> ->
{volumerelative, gleam@string:drop_left(Path, 1)};
<<"/"/utf8, _/binary>> ->
{volumerelative, gleam@string:drop_left(Path, 1)};
<<_/utf8, ":"/utf8, "\\"/utf8, _/binary>> ->
{absolute, gleam@string:drop_left(Path, 3)};
<<_/utf8, ":"/utf8, "/"/utf8, _/binary>> ->
{absolute, gleam@string:drop_left(Path, 3)};
<<_/utf8, ":"/utf8, _/binary>> ->
{volumerelative, gleam@string:drop_left(Path, 2)};
_ ->
{relative, Path}
end.