@@ -36,7 +36,7 @@ defmodule URI do
36
36
Any scheme may be registered via `default_port/2`.
37
37
38
38
## Examples
39
-
39
+
40
40
iex> URI.default_port("ftp")
41
41
21
42
42
@@ -61,11 +61,11 @@ defmodule URI do
61
61
Encodes an enumerable into a query string.
62
62
63
63
Takes an enumerable (containing a sequence of two-item tuples)
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
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
66
be any term that implements the `String.Chars` protocol (i.e. can be converted
67
67
to a binary).
68
-
68
+
69
69
## Examples
70
70
71
71
iex> hd = HashDict.new([{"foo", 1}, {"bar", "2"}])
@@ -85,15 +85,14 @@ defmodule URI do
85
85
Use `query_decoder/1` if you want to iterate over each value manually.
86
86
87
87
## Examples
88
-
88
+
89
89
iex> URI.decode_query("foo=1&bar=2") |> Dict.to_list
90
90
[{"bar", "2"}, {"foo", "1"}]
91
91
92
- > hd = HashDict.new()
93
- #HashDict<[]>
94
- > URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
92
+ iex> hd = HashDict.new()
93
+ iex> URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
95
94
["bar", "foo"]
96
- > URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
95
+ iex > URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
97
96
["2", "1"]
98
97
99
98
"""
@@ -104,12 +103,12 @@ defmodule URI do
104
103
@ doc """
105
104
Returns an iterator function over the query string that decodes
106
105
the query string in steps.
107
-
106
+
108
107
## Examples
109
-
108
+
110
109
iex> URI.query_decoder("foo=1&bar=2") |> Enum.map &(&1)
111
110
[{"foo", "1"}, {"bar", "2"}]
112
-
111
+
113
112
"""
114
113
def query_decoder ( q ) when is_binary ( q ) do
115
114
Stream . unfold ( q , & do_decoder / 1 )
@@ -141,12 +140,12 @@ defmodule URI do
141
140
142
141
@ doc """
143
142
Percent-escape a URI.
144
-
143
+
145
144
## Example
146
-
145
+
147
146
iex> URI.encode("http://elixir-lang.com/getting_started/2.html")
148
147
"http%3A%2F%2Felixir-lang.com%2Fgetting_started%2F2.html"
149
-
148
+
150
149
"""
151
150
def encode ( s ) , do: bc ( << c >> in bits s , do: << percent ( c ) :: binary >> )
152
151
@@ -169,12 +168,12 @@ defmodule URI do
169
168
170
169
@ doc """
171
170
Percent-unescape a URI.
172
-
171
+
173
172
## Examples
174
-
173
+
175
174
iex> URI.decode("http%3A%2F%2Felixir-lang.com")
176
175
"http://elixir-lang.com"
177
-
176
+
178
177
"""
179
178
def decode ( << ?% , hex1 , hex2 , tail :: binary >> ) do
180
179
<< bsl ( hex2dec ( hex1 ) , 4 ) + hex2dec ( hex2 ) >> <> decode ( tail )
@@ -196,26 +195,16 @@ defmodule URI do
196
195
@ doc """
197
196
Parses a URI into components.
198
197
199
- URIs have portions that are handled specially for the
200
- particular scheme of the URI. For example, http and https
201
- have different default ports. Sometimes the parsing
202
- of portions themselves are different. This parser
203
- is extensible via behavior modules. If you have a
204
- module named `URI.MYSCHEME` with a function called
205
- `parse` that takes a single argument, the generically
206
- parsed URI, that function will be called when this
207
- parse function is passed a URI of that scheme. This
208
- allows you to build on top of what the URI library
209
- currently offers. You also need to define `default_port`
210
- which takes no arguments and returns the default port
211
- for that particular scheme. Take a look at `URI.HTTPS` for an
212
- example of one of these extension modules.
213
-
198
+ URIs have portions that are handled specially for the particular
199
+ scheme of the URI. For example, http and https have different
200
+ default ports. Such values can be accessed and registered via
201
+ `URI.default_port/1` and `URI.default_port/2`.
202
+
214
203
## Examples
215
-
204
+
216
205
iex> URI.parse("http://elixir-lang.org/")
217
- URI.Info[scheme: "http", path: "/", query: nil, fragment: nil,
218
- authority: "elixir-lang.org", userinfo: nil,
206
+ URI.Info[scheme: "http", path: "/", query: nil, fragment: nil,
207
+ authority: "elixir-lang.org", userinfo: nil,
219
208
host: "elixir-lang.org", port: 80]
220
209
221
210
"""
0 commit comments