Debian Codegraph @

README

raw
1 NAME
2 URI::Escape::XS - Drop-In replacement for URI::Escape
3
4 VERSION
5 $Id: README,v 0.5 2013/02/25 17:24:25 dankogai Exp $
6
7 SYNOPSIS
8 # use it instead of URI::Escape
9 use URI::Escape::XS qw/uri_escape uri_unescape/;
10 $safe = uri_escape("10% is enough\n");
11 $verysafe = uri_escape("foo", "\0-\377");
12 $str = uri_unescape($safe);
13
14 # or use encodeURIComponent and decodeURIComponent
15 use URI::Escape::XS;
16 $safe = encodeURIComponent("10% is enough\n");
17 $str = decodeURIComponent("10%25%20is%20enough%0A");
18
19 # if you have CNet::IDN::Encode installed
20 $safe = encodeURIComponentIDN("http://ドメイン名例.jp/dan/");
21 $str = decodeURIComponentIDN("http:%2F%2Fxn--eckwd4c7cu47r2wf.jp%2Fdan%2F");
22
23 EXPORT
24 by default
25 "encodeURIComponent" and "decodeURIComponent"
26
27 "encodeURIComponentIDN" and "decodeURIComponentIDN" if either
28 Net::LibIDN or Net::IDN::Encode is available
29
30 on demand
31 "uri_escape" and "uri_unescape"
32
33 FUNCTIONS
34 encodeURIComponent
35 Does what JavaScript's encodeURIComponent does.
36
37 $uri = encodeURIComponent("http://www.example.com/");
38 # http%3A%2F%2Fwww.example.com%2F
39
40 Note you cannot customize characters to escape. If you need to do so,
41 use "uri_escape".
42
43 decodeURIComponent
44 Does what JavaScript's decodeURIComponent does.
45
46 $str = decodeURIComponent("http%3A%2F%2Fwww.example.com%2F");
47 # http://www.example.com/
48
49 It decode not only %HH sequences but also %uHHHH sequences, with
50 surrogate pairs correctly decoded.
51
52 $str = decodeURIComponent("%uD869%uDEB2%u5F3E%u0061");
53 # \x{2A6B2}\x{5F3E}a
54
55 This function UNCONDITIONALLY returns the decoded string with utf8 flag
56 off. To get utf8-decoded string, use Encode and
57
58 decode_utf8(decodeURIComponent($uri));
59
60 This is the correct behavior because you cannot tell if the decoded
61 string actually contains UTF-8 decoded string, like ISO-8859-1 and
62 Shift_JIS.
63
64 encodeURIComponentIDN
65 Same as "encodeURIComponent" except that the host part is encoded in
66 punycode. Either Net::LibIDN or Net::IDN::Encode is required to use this
67 function.
68
69 URIs with Internationalizing Domain Names require two encodings:
70 Punycode for host part and URI escape for the rest.
71
72 Currently only FULL URIs with "http:" or "https:" are supported.
73
74 decodeURIComponentIDN
75 Same as "decodeURIComponent" except that the host part is encoded in
76 punycode. Either Net::LibIDN or Net::IDN::Encode is required to use this
77 function.
78
79 uri_escape
80 Does exactly the same as URI::Escape::uri_escape() except when
81 utf8-flagged string is fed.
82
83 URI::Escape::uri_escape() croak and urge you to "uri_escape_utf8()" but
84 it is pointless because URI itself has no such things as utf8 flag. The
85 function in this module ALWAYS TREATS the string as byte sequence. That
86 way you can safely use this function without worring about utf8 flags.
87
88 Note this function is NOT EXPORTED by default. That way you can use
89 URI::Escape and URI::Escape::XS simultaneously.
90
91 uri_unescape
92 Does exactly the same as URI::Escape::uri_escape() except when %uHHHH is
93 fed.
94
95 URI::Escape::uri_unescape() simply ignores %uHHHH sequences while the
96 function in this module does decode it into the corresponding UTF-8 byte
97 sequence.
98
99 Like uri_escape, this funciton is NOT EXPORTED by default.
100
101 Note on the %uHHHH sequence
102 With this module the resulting strings never have the utf8 flag on. So
103 if you want to decode it to perl utf8, You have to explicitly decode via
104 Encode. Remember. URIs have always been a byte sequence, not UTF-8
105 characters.
106
107 If the %uHHHH sequence became standard, you could have safely told if a
108 given URI is in Unicode. But more fortunately than unfortunately, the
109 RFC proposal was rejected so you cannot tell which encoding is used just
110 by looking at the URI.
111
112 <http://en.wikipedia.org/wiki/Percent-encoding#Non-standard_implementati
113 ons>
114
115 I said fortunately because %uHHHH can be nasty for non-BMP characters.
116 Since each %uHHHH can hold one 16-bit value, you need a *surrogate pair*
117 to represent it if it is U+10000 and above.
118
119 In spite of that, there are a significant number of URIs with %uHHHH
120 escapes. Therefore this module supports decoding only.
121
122 SPEED
123 Since this module uses XS, it is really fast except for
124 uri_escape("noop").
125
126 Regexp which is used in URI::Escape is really fast for non-matching but
127 slows down significantly when it has to replace string.
128
129 BENCHMARK
130 On Macbook Pro 2GHz, Perl 5.8.8.
131
132 http://www.google.co.jp/search?q=%E5%B0%8F%E9%A3%BC%E5%BC%BE
133 ============================================================
134 Unescape it
135 -----------
136 U::E 58526/s -- -88%
137 U::E::XS 486968/s 732% --
138 --------------
139 Escape it back
140 --------------
141 U::E 30046/s -- -78%
142 U::E::XS 136992/s 356% --
143
144 www.example.com
145 ===============
146 Unescape it
147 -----------
148 Rate U::E U::E::XS
149 U::E 821972/s -- -4%
150 U::E::XS 854732/s 4% --
151 --------------
152 Escape it back
153 -------------
154 U::E::XS 522969/s -- -7%
155 U::E 565112/s 8% --
156
157 AUTHOR
158 Dan Kogai, "<dankogai+cpan at gmail.com>"
159
160 BUGS
161 Please report any bugs or feature requests to "bug-uri-escape-xs at
162 rt.cpan.org", or through the web interface at
163 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=URI-Escape-XS>. I will
164 be notified, and then you'll automatically be notified of progress on
165 your bug as I make changes.
166
167 SUPPORT
168 You can find documentation for this module with the perldoc command.
169
170 perldoc URI::Escape::XS
171
172 You can also look for information at:
173
174 * AnnoCPAN: Annotated CPAN documentation
175
176 <http://annocpan.org/dist/URI-Escape-XS>
177
178 * CPAN Ratings
179
180 <http://cpanratings.perl.org/d/URI-Escape-XS>
181
182 * RT: CPAN's request tracker
183
184 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=URI-Escape-XS>
185
186 * Search CPAN
187
188 <http://search.cpan.org/dist/URI-Escape-XS>
189
190 ACKNOWLEDGEMENTS
191 Gisle Aas for URI::Escape
192
193 Koichi Taniguchi for URI::Escape::JavaScript
194
195 Thomas Jacob for Net::LibIDN
196
197 Claus Färber for Net::IDN::Encode
198
199 COPYRIGHT & LICENSE
200 Copyright 2007-2012 Dan Kogai, all rights reserved.
201
202 This program is free software; you can redistribute it and/or modify it
203 under the same terms as Perl itself.
204