How to resolve the algorithm URL parser step by step in the Elixir programming language
How to resolve the algorithm URL parser step by step in the Elixir programming language
Table of Contents
Problem Statement
URLs are strings with a simple syntax:
Parse a well-formed URL to retrieve the relevant information: scheme, domain, path, ...
Note: this task has nothing to do with URL encoding or URL decoding.
According to the standards, the characters: only need to be percent-encoded (%) in case of possible confusion. Also note that the path, query and fragment are case sensitive, even if the scheme and domain are not. The way the returned information is provided (set of variables, array, structured, record, object,...) is language-dependent and left to the programmer, but the code should be clear enough to reuse. Extra credit is given for clear error diagnostics.
According to T. Berners-Lee foo://example.com:8042/over/there?name=ferret#nose should parse into:
urn:example:animal:ferret:nose should parse into:
other URLs that must be parsed include:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm URL parser step by step in the Elixir programming language
Source code in the elixir programming language
test_cases = [
"foo://example.com:8042/over/there?name=ferret#nose",
"urn:example:animal:ferret:nose",
"jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true",
"ftp://ftp.is.co.za/rfc/rfc1808.txt",
"http://www.ietf.org/rfc/rfc2396.txt#header1",
"ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two",
"mailto:John.Doe@example.com",
"news:comp.infosystems.www.servers.unix",
"tel:+1-816-555-1212",
"telnet://192.0.2.16:80/",
"urn:oasis:names:specification:docbook:dtd:xml:4.1.2",
"ssh://alice@example.com",
"https://bob:pass@example.com/place",
"http://example.com/?a=1&b=2+2&c=3&c=4&d=%65%6e%63%6F%64%65%64"
]
Enum.each(test_cases, fn str ->
IO.puts "\n#{str}"
IO.inspect URI.parse(str)
end)
You may also check:How to resolve the algorithm Reverse a string step by step in the OCaml programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the Ursala programming language
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Cubic step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Loops/Wrong ranges step by step in the XPL0 programming language