Skip to content

Commit 522129f

Browse files
committed
added functions of the interfaces
1 parent b8c8b81 commit 522129f

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

src/stdlib_system_path.f90

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
submodule(stdlib_system) stdlib_system_path
22
use stdlib_ascii, only: reverse
3-
use stdlib_strings, only: chomp, join
3+
use stdlib_strings, only: chomp, join, starts_with
44
use stdlib_string_type, only: string_type, char, move
55
contains
66
module function join2_char_char(p1, p2) result(path)
@@ -167,4 +167,58 @@ module function dir_name_string(p) result(dir)
167167

168168
call split_path(p, dir, temp)
169169
end function dir_name_string
170+
171+
module logical function is_abs_char(p)
172+
character(len=*), intent(in) :: p
173+
character(len=1) :: sep
174+
175+
sep = path_sep()
176+
177+
if (sep == '/') then
178+
! should start with '/'
179+
is_abs_char = starts_with(p, sep)
180+
else
181+
! should be either an UNC path like '\\server\host...'
182+
! or should be starting with a drive letter like 'C:\Users\...'
183+
is_abs_char = starts_with(p(2:), ':\') .or. starts_with(p, '\\')
184+
end if
185+
end function is_abs_char
186+
187+
module logical function is_abs_string(p)
188+
type(string_type), intent(in) :: p
189+
190+
is_abs_string = is_abs(char(p))
191+
end function is_abs_string
192+
193+
module function abs_path_char(p, err) result(abs_p)
194+
character(len=*), intent(in) :: p
195+
type(state_type), optional, intent(out) :: err
196+
character(len=:), allocatable :: abs_p
197+
198+
type(state_type) :: err0
199+
character(:), allocatable :: cwd
200+
201+
! get the current working directory
202+
call get_cwd(cwd, err0)
203+
204+
if (err0%error()) then
205+
abs_p = ''
206+
call err0%handle(err)
207+
end if
208+
209+
! join the cwd and path
210+
abs_p = cwd / p
211+
end function abs_path_char
212+
213+
module function abs_path_string(p, err) result(abs_p)
214+
type(string_type), intent(in) :: p
215+
type(state_type), optional, intent(out) :: err
216+
type(string_type) :: abs_p
217+
218+
character(len=:), allocatable :: res
219+
220+
res = abs_path(char(p), err)
221+
222+
call move(res, abs_p)
223+
end function abs_path_string
170224
end submodule stdlib_system_path

0 commit comments

Comments
 (0)