Skip to content

Commit

Permalink
Refactor with simpler logicals and ternaries
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedmcse committed Apr 28, 2024
1 parent 6385f92 commit 08bd30e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
20 changes: 4 additions & 16 deletions waifuAPIModule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ function fileInfo(token, formatted) result (res)
url = ''
url = trim(BASEURL) // '/' // trim(token) // '?formatted='
if (formatted .eqv. .true.) then
url = trim(url) // 'true'
else
url = trim(url) // 'false'
end if
url = merge(trim(url) // 'true', trim(url) // 'false', formatted)
call dispatch_curl(rc, 'GET', trim(url), c_null_ptr, body, '')
call checkError(rc, body%content)
Expand Down Expand Up @@ -181,14 +177,10 @@ function fileUpdate(token, password, previous_password, custom_expiry, hide_file
fields = trim(fields) // custom_expiry
end if
fields = trim(fields) // '","hideFilename":'
if (hide_filename .eqv. .true.) then
fields = trim(fields) // 'true'
else
fields = trim(fields) // 'false'
end if
fields = merge(trim(fields) // 'true ', trim(fields) // 'false', hide_filename)
fields = trim(fields) // '}'
call dispatch_curl(rc, 'PATCH', trim(url), headers, body, fields)
call dispatch_curl(rc, 'PATCH', trim(url), headers, body, trim(fields))
call checkError(rc, body%content)
res = deserializeResponse(body%content)
deallocate(body%content)
Expand All @@ -207,11 +199,7 @@ function deleteFile(token) result (res)
call dispatch_curl(rc, 'DELETE', trim(url), c_null_ptr, body, '')
call checkError(rc, body%content)
if (body%content(1:4) == 'true') then
res = .true.
else
res = .false.
end if
res = body%content(1:4) == 'true'
deallocate(body%content)
end function deleteFile
Expand Down
12 changes: 2 additions & 10 deletions waifuUtilsModule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ module waifuvault_utils
function stringToLogical(input) result (res)
character(len=*) :: input
logical :: res
if(input == 'true') then
res = .true.
else
res = .false.
end if
res = input == 'true'
end function stringToLogical

function basename(path)
Expand All @@ -41,11 +37,7 @@ subroutine expandHomedir(path, result)

call getHomeDirectory(home, status)

if (path(1:1) == '~' .and. status == 0) then
result = trim(home) // path(2:)
else
result = path
end if
result = merge(trim(home) // path(2:), path, (path(1:1) == '~' .and. status == 0))
end subroutine expandHomedir

subroutine getHomeDirectory(home, status)
Expand Down

0 comments on commit 08bd30e

Please sign in to comment.