CGI-Utils

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  Aliases: url_encode()
 
urlUnicodeEncode($str)
  Returns the fully URL-encoded version of the given string as unicode
  characters. It does not convert space characters to '+' characters.
 
  Aliases: url_unicode_encode()
 
urlDecode($url_encoded_str)
  Returns the decoded version of the given URL-encoded string.
 
  Aliases: url_decode()
 
urlUnicodeDecode($url_encoded_str)
  Returns the decoded version of the given URL-encoded string, with
  unicode support.
 
  Aliases: url_unicode_decode()
 
urlEncodeVars($var_hash, $sep)
  Takes a hash of name/value pairs and returns a fully URL-encoded query
  string suitable for passing in a URL. By default, uses the newer
  separator, a semicolon, as recommended by the W3C. If you pass in a
  second argument, it is used as the separator between key/value pairs.

lib/CGI/Utils.pm  view on Meta::CPAN

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
        my ($self, $str) = @_;
        $str =~ s{([^A-Za-z0-9_])}{sprintf("%%u%04x", ord($1))}eg;
        return $str;
    }
    *url_unicode_encode = \&urlUnicodeEncode;
 
=pod
 
=head2 urlDecode($url_encoded_str)
 
Returns the decoded version of the given URL-encoded string.
 
Aliases: url_decode()
 
=cut
    sub urlDecode {
        my ($self, $str) = @_;
        $str =~ tr/+/ /;
        $str =~ s|%([A-Fa-f0-9]{2})|chr(hex($1))|eg;
        return $str;
    }
    *url_decode = \&urlDecode;
 
=pod
 
=head2 urlUnicodeDecode($url_encoded_str)
 
Returns the decoded version of the given URL-encoded string,
with unicode support.
 
Aliases: url_unicode_decode()
 
=cut
    sub urlUnicodeDecode {
        my ($self, $str) = @_;
        $str =~ tr/+/ /;
        $str =~ s|%([A-Fa-f0-9]{2})|chr(hex($1))|eg;
        $str =~ s|%u([A-Fa-f0-9]{2,4})|chr(hex($1))|eg;



( run in 0.238 second using v1.01-cache-2.11-cpan-1dc43b0fbd2 )