Your task is to automatically complete URLs like the address bar in most browsers is doing. We will use the following (simplified) rules:
- If the input string starts with
http://
,ftp://
orhttps://
, return the string unchanged. - Otherwise, if the input string contains a dot
.
, e.g.in.put
then the HTTP is assumed andhttp://
is prepended:http://in.put
. - Otherwise
ftp://
is prepended, e.g.ftp://input
when the input string wasinput
.
Input
Any string which must not necessarily be a valid URL.
Output
The string modified according to the above rules.
Test Cases
dan-pc -> ftp://dan-pc
https://localhost/ -> https://localhost/
ftp://foo -> ftp://foo
http://foo -> http://foo
f.oo -> http://f.oo
derp.me -> http://derp.me
another.one/ ->http://another.one/
// -> ftp:////
a://b -> ftp://a://b
This is code golf, shortest code wins. Good Luck!
abcd://site
? (generally if there is something before://
can we assume it's http, https or ftp? \$\endgroup\$http://foo
\$\endgroup\$