Debian Codegraph @

README.markdown

raw symbols SCIP
1 # QURI
2
3 [![Build Status](https://travis-ci.org/fukamachi/quri.svg?branch=master)](https://travis-ci.org/fukamachi/quri)
4 [![Coverage Status](https://coveralls.io/repos/fukamachi/quri/badge.svg?branch=master)](https://coveralls.io/r/fukamachi/quri)
5
6 <p align=center><a href="https://www.flickr.com/photos/m-louis/8209540334/"><img src="http://c1.staticflickr.com/9/8202/8209540334_261582582c_h.jpg" alt="冷やしきゅうり"></a></p>
7 <p align=right><i>Photo by <a href="https://www.flickr.com/photos/m-louis/">m-louis</a>, licensed under the <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA 2.0</a> license.</i></p>
8
9 **QURI** (pronounced "Q-ree") is yet another URI library for Common Lisp. It is intended to be a replacement of [PURI](http://puri.b9.com).
10
11 ## Differences from PURI
12
13 - Fast. (See [Benchmark](#benchmark))
14 - Doesn't encode/decode URL implicitly.
15 - Supports userinfo. (ex. `git` in `[email protected]`)
16 - Supports IPv6 hostname. (ex. `ldap://[2001:db8::7]/`)
17 - Allows byte vectors as input.
18 - Takes optional `:start` and `:end` keyword arguments.
19 - Low-level parser functions.
20 - URL encoding/decoding utilities.
21 - `url-decode`, `url-decode-params`, `url-encode`, `url-encode-params`
22
23 ## Usage
24
25 ```common-lisp
26 (use-package :quri)
27
28 (defvar *uri* (uri "http://www.ics.uci.edu/pub/ietf/uri/#Related"))
29
30 *uri*
31 ;=> #<QURI.URI.HTTP:URI-HTTP http://www.ics.uci.edu/pub/ietf/uri/#Related>
32
33 (uri-scheme *uri*)
34 ;=> "http"
35
36 (uri-host *uri*)
37 ;=> "www.ics.uci.edu"
38
39 (uri-domain *uri*)
40 ;=> "uci.edu"
41
42 (uri-path *uri*)
43 ;=> "/pub/ietf/uri/"
44
45 (uri-fragment *uri*)
46 ;=> "Related"
47 ```
48
49 ## Functions
50
51 ### \[Function] uri
52
53 Parse a string or a byte vector and return a `uri` object.
54
55 ### \[Function] make-uri
56
57 Create a `uri` object.
58
59 ### \[Function] copy-uri
60
61 Return a copy of the given `uri` object.
62
63 ### \[Function] merge-uris
64
65 Merge a reference URI into the base URI as described in RFC 2396 Section 5.2. The returned URI may or may not be a new instance. Neither REFERENCE nor BASE is mutated.
66
67 ### \[Structure] uri
68
69 Structure class as a representation of URIs. The following methods are available for all classes extends this class.
70
71 #### Methods
72
73 - `uri-scheme`
74 - `uri-userinfo`
75 - `uri-host`
76 - `uri-domain`
77 - `uri-tld`
78 - `uri-port`
79 - `uri-path`
80 - `uri-authority`
81 - `render-uri`
82
83 ### \[Structure] urn (extends uri)
84
85 Structure class as a representation of URNs. All methods of `uri` are also available for this class.
86
87 #### Methods
88
89 - `urn-nid`
90 - `urn-nss`
91
92 ### \[Structure] uri-http (extends uri)
93
94 Structure class for HTTP/HTTPS URIs.
95
96 #### Methods
97
98 - `uri-query-params`
99
100 ```common-lisp
101 (defvar *uri* (quri:uri "http://quickdocs.org/search?q=web"))
102
103 (uri-query-params *uri*)
104 ;=> (("q" . "web"))
105
106 (setf (uri-query-params *uri*) '(("q" . "system programming")))
107
108 *uri*
109 ;=> #<QURI.URI.HTTP:URI-HTTP http://quickdocs.org/search?q=system%20programming>
110 ```
111
112 ### \[Structure] uri-ftp (extends uri)
113
114 Structure class for FTP URIs.
115
116 #### Methods
117
118 - `uri-ftp-typecode`
119
120 ### \[Structure] uri-ldap (extends uri)
121
122 Structure class for LDAP/LDAPS URIs.
123
124 #### Methods
125
126 - `uri-ldap-dn`
127 - `uri-ldap-attributes`
128 - `uri-ldap-scope`
129 - `uri-ldap-filter`
130 - `uri-ldap-extensions`
131
132 ### \[Function] url-decode
133
134 Decode a Percent-Encoded string or byte vector.
135
136 ```common-lisp
137 (url-decode "%2Ffoo%E3%81%82")
138 ;=> "/fooあ"
139 ```
140
141 ### \[Function] url-decode-params
142
143 Decode a [form-urlencoded](http://tools.ietf.org/html/rfc1866#section-8.2.1) string or byte vector and return an association list.
144
145 ### \[Function] url-encode
146
147 Encode a string or a byte vector into a Percent-Encoded string.
148
149 ```common-lisp
150 (url-encode "/fooあ")
151 ;=> "%2Ffoo%E3%81%82"
152 ```
153
154 ### \[Function] url-encode-params
155
156 Encode an association list into a [form-urlencoded](http://tools.ietf.org/html/rfc1866#section-8.2.1) string.
157
158 ## Low-level functions
159
160 ### \[Function] parse-uri
161
162 Parse a URI string or a URI byte vector and return 7 URI components -- scheme, userinfo, host name, port, path, query and fragment.
163
164 ```common-lisp
165 (parse-uri "http://www.ics.uci.edu/pub/ietf/uri/#Related")
166 ;=> "http"
167 ; NIL
168 ; "www.ics.uci.edu"
169 ; NIL
170 ; "/pub/ietf/uri/"
171 ; NIL
172 ; "Related"
173 ```
174
175 ## Installation
176
177 ```
178 $ git clone https://github.com/fukamachi/quri
179 ```
180
181 ```common-lisp
182 (ql:quickload :quri)
183 ```
184
185 ## Benchmark
186
187 ### Parsing URI
188
189 - Parsing a URI string 100,000 times.
190
191 | QURI | PURI |
192 |--------|--------|
193 | 0.064s | 0.423s |
194
195 QURI is **6.6 times faster** than PURI for URI parsing.
196
197 #### QURI
198
199 ```common-lisp
200 (time
201 (dotimes (i 100000)
202 (quri:uri "http://www.ics.uci.edu/pub/ietf/uri/#Related")))
203 ```
204
205 ```
206 Evaluation took:
207 0.064 seconds of real time
208 0.063984 seconds of total run time (0.063745 user, 0.000239 system)
209 100.00% CPU
210 191,340,531 processor cycles
211 28,807,728 bytes consed
212 ```
213
214 #### PURI
215
216 ```common-lisp
217 (time
218 (dotimes (i 100000)
219 (puri:uri "http://www.ics.uci.edu/pub/ietf/uri/#Related")))
220 ```
221
222 ```
223 Evaluation took:
224 0.423 seconds of real time
225 0.425327 seconds of total run time (0.422234 user, 0.003093 system)
226 [ Run times consist of 0.004 seconds GC time, and 0.422 seconds non-GC time. ]
227 100.47% CPU
228 1,266,663,894 processor cycles
229 64,001,408 bytes consed
230 ```
231
232 ### URL decoding
233
234 - Decoding a URL-encoded string 100,000 times.
235
236 | QURI | Hunchentoot | do-urlencode |
237 |--------|-------------|--------------|
238 | 0.029s | 0.089s | 0.634s |
239
240 QURI is **3 times faster** than Hunchentoot, and **21.8 times faster** than do-urlencode.
241
242 #### QURI
243
244 ```common-lisp
245 (time
246 (dotimes (i 100000)
247 (quri:url-decode "foo%E3%81%82")))
248 ```
249
250 ```
251 Evaluation took:
252 0.029 seconds of real time
253 0.028683 seconds of total run time (0.027934 user, 0.000749 system)
254 100.00% CPU
255 85,421,676 processor cycles
256 7,993,456 bytes consed
257 ```
258
259 #### Hunchentoot
260
261 ```common-lisp
262 (time
263 (dotimes (i 100000)
264 (hunchentoot:url-decode "foo%E3%81%82")))
265 ```
266
267 ```
268 Evaluation took:
269 0.089 seconds of real time
270 0.088946 seconds of total run time (0.087632 user, 0.001314 system)
271 100.00% CPU
272 265,341,714 processor cycles
273 17,611,968 bytes consed
274 ```
275
276 #### do-urlencode
277
278 ```common-lisp
279 (time
280 (dotimes (i 100000)
281 (do-urlencode:urldecode "foo%E3%81%82")))
282 ```
283
284 ```
285 Evaluation took:
286 0.634 seconds of real time
287 0.637236 seconds of total run time (0.632224 user, 0.005012 system)
288 [ Run times consist of 0.023 seconds GC time, and 0.615 seconds non-GC time. ]
289 100.47% CPU
290 1,897,304,959 processor cycles
291 153,606,064 bytes consed
292 ```
293
294 ### URL encoding
295
296 - URL-encoding a string 100,000 times.
297
298 | QURI | Hunchentoot | do-urlencode |
299 |--------|-------------|--------------|
300 | 0.074s | 0.282s | 0.317s |
301
302 QURI is **3.8 times faster** than Hunchentoot, and **4.2 times faster** than do-urlencode.
303
304 #### QURI
305
306 ```common-lisp
307 (time
308 (dotimes (i 100000)
309 (quri:url-encode "fooあ")))
310 ```
311
312 ```
313 Evaluation took:
314 0.074 seconds of real time
315 0.074284 seconds of total run time (0.072908 user, 0.001376 system)
316 100.00% CPU
317 221,267,517 processor cycles
318 31,993,520 bytes consed
319 ```
320
321 #### Hunchentoot
322
323 ```common-lisp
324 (time
325 (dotimes (i 100000)
326 (hunchentoot:url-encode "fooあ")))
327 ```
328
329 ```
330 Evaluation took:
331 0.282 seconds of real time
332 0.284922 seconds of total run time (0.280063 user, 0.004859 system)
333 [ Run times consist of 0.034 seconds GC time, and 0.251 seconds non-GC time. ]
334 101.06% CPU
335 845,204,850 processor cycles
336 214,382,672 bytes consed
337 ```
338
339 #### do-urlencode
340
341 ```common-lisp
342 (time
343 (dotimes (i 100000)
344 (do-urlencode:urlencode "fooあ")))
345 ```
346
347 ```
348 Evaluation took:
349 0.317 seconds of real time
350 0.319419 seconds of total run time (0.314339 user, 0.005080 system)
351 [ Run times consist of 0.026 seconds GC time, and 0.294 seconds non-GC time. ]
352 100.63% CPU
353 946,704,912 processor cycles
354 219,186,768 bytes consed
355 ```
356
357 ## Author
358
359 * Eitaro Fukamachi ([email protected])
360
361 ## Copyright
362
363 Copyright (c) 2014 Eitaro Fukamachi ([email protected])
364
365 ## License
366
367 Licensed under the BSD 3-Clause License.