/[suikacvs]/messaging/manakai/lib/Message/CGI/Util.pm
Suika

Contents of /messaging/manakai/lib/Message/CGI/Util.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Mon Nov 24 07:45:31 2008 UTC (16 years ago) by wakaba
Branch: MAIN
++ manakai/lib/Message/CGI/ChangeLog	24 Nov 2008 07:43:56 -0000
2008-11-24  Wakaba  <wakaba@suika.fam.cx>

	* Util.pm: New module (Functions originally developed for
	SuikaWiki4).

1 wakaba 1.1 package Message::CGI::Util;
2     use strict;
3    
4     use Exporter;
5     push our @ISA, 'Exporter';
6    
7     our @EXPORT_OK = qw/
8     htescape
9     percent_encode percent_encode_na
10     percent_decode
11     get_absolute_url
12     /;
13    
14     require Encode;
15    
16     sub htescape ($) {
17     my $s = shift;
18     $s =~ s/&/&amp;/g;
19     $s =~ s/</&lt;/g;
20     $s =~ s/"/&quot;/g;
21     return $s;
22     } # htescape
23    
24     sub percent_encode ($) {
25     my $s = Encode::encode ('utf8', $_[0]);
26     $s =~ s/([^A-Za-z0-9_~-])/sprintf '%%%02X', ord $1/ges;
27     return $s;
28     } # percent_encode
29    
30     sub percent_encode_na ($) {
31     my $s = Encode::encode ('utf8', $_[0]);
32     $s =~ s/([^\x00-\x7F])/sprintf '%%%02X', ord $1/ges;
33     return $s;
34     } # percent_encode_na
35    
36     sub percent_decode ($) { # input should be a byte string.
37     my $s = shift;
38     $s =~ s/%([0-9A-Fa-f]{2})/pack 'C', hex $1/ge;
39     return Encode::decode ('utf-8', $s); # non-UTF-8 octet converted to \xHH
40     } # percent_decode
41    
42     sub get_absolute_url ($$) {
43     require Message::DOM::DOMImplementation;
44     return Message::DOM::DOMImplementation->create_uri_reference ($_[0])
45     ->get_absolute_reference ($_[1])
46     ->get_uri_reference
47     ->uri_reference;
48     } # get_absolute_url
49    
50     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24