Skip to content

Commit

Permalink
Use replace and startswith
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffFessler committed Oct 2, 2023
1 parent 83c51a3 commit 049f384
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/GoogleDrive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@ to the form needed for raw data download:
`https://docs.google.com/uc?export=download&id=XYZ`
"
function google_download_url(url::AbstractString)
head = "https://drive.google.com/file/d/"
nhead = length(head)
prefix = "https://docs.google.com/uc?export=download&id="
nprefix = length(prefix)

if (length(url) nhead) && (url[1:nhead] == head)
url = prefix * url[(length(head)+1):end]
elseif (length(url) < nprefix) || (url[1:nprefix] != prefix)
old = "https://drive.google.com/file/d/"
new = "https://docs.google.com/uc?export=download&id="
startswith(url, old) || startswith(url, new) ||
throw(ArgumentError("Unknown URL form $url"))
end

return url
return replace(url, old => new)
end


Expand Down

0 comments on commit 049f384

Please sign in to comment.