@@ -31,8 +31,18 @@ defmodule URI do
3131
3232 @ doc """
3333 Returns the default port for a given scheme.
34+
3435 If the scheme is unknown to URI, returns `nil`.
3536 Any scheme may be registered via `default_port/2`.
37+
38+ ## Examples
39+
40+ iex> URI.default_port("ftp")
41+ 21
42+
43+ iex> URI.default_port("ponzi")
44+ nil
45+
3646 """
3747 def default_port ( scheme ) when is_binary ( scheme ) do
3848 { :ok , dict } = :application . get_env ( :elixir , :uri )
@@ -48,39 +58,42 @@ defmodule URI do
4858 end
4959
5060 @ doc """
61+ Encodes an enumerable into a query string.
62+
5163 Takes an enumerable (containing a sequence of two-item tuples)
52- and returns a string of the form "k=v&k2=v2 ..." where keys and values are
53- URL encoded as per `encode/1`. Keys and values can be any term
54- that implements the `String.Chars` protocol (i.e. can be converted
64+ and returns a string of the form "key1=value1&key2=value2 ..." where
65+ keys and values are URL encoded as per `encode/1`. Keys and values can
66+ be any term that implements the `String.Chars` protocol (i.e. can be converted
5567 to a binary).
5668
5769 ## Examples
5870
5971 iex> hd = HashDict.new([{"foo", 1}, {"bar", "2"}])
60- #HashDict<[{"bar", "2"}, {"foo", 1}]>
6172 iex> URI.encode_query(hd)
6273 "bar=2&foo=1"
6374
6475 """
6576 def encode_query ( l ) , do: Enum . map_join ( l , "&" , & pair / 1 )
6677
6778 @ doc """
68- Given a query string of the form "key1=value1&key=value2...", produces an
79+ Decodes a query string into an orddict.
80+
81+ Given a query string of the form "key1=value1&key2=value2...", produces an
6982 orddict with one entry for each key-value pair. Each key and value will be a
70- binary. It also does percent-unescaping of both keys and values .
83+ binary. Keys and values will be percent-unescaped .
7184
7285 Use `query_decoder/1` if you want to iterate over each value manually.
7386
7487 ## Examples
7588
76- iex> URI.decode_query("foo=1&bar=2")
77- #HashDict< [{"bar", "2"}, {"foo", "1"}]>
89+ iex> URI.decode_query("foo=1&bar=2") |> Dict.to_list
90+ [{"bar", "2"}, {"foo", "1"}]
7891
79- iex > hd = HashDict.new()
92+ > hd = HashDict.new()
8093 #HashDict<[]>
81- iex > URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
94+ > URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
8295 ["bar", "foo"]
83- iex > URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
96+ > URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
8497 ["2", "1"]
8598
8699 """
@@ -201,7 +214,9 @@ defmodule URI do
201214 ## Examples
202215
203216 iex> URI.parse("http://elixir-lang.org/")
204- URI.Info[scheme: "http", path: "/", query: nil, fragment: nil, authority: "elixir-lang.org", userinfo: nil, host: "elixir-lang.org", port: 80]
217+ URI.Info[scheme: "http", path: "/", query: nil, fragment: nil,
218+ authority: "elixir-lang.org", userinfo: nil,
219+ host: "elixir-lang.org", port: 80]
205220
206221 """
207222 def parse ( s ) when is_binary ( s ) do
0 commit comments