⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 escape.pm

📁 美国CMU大学开发的操作系统健壮性评测软件
💻 PM
字号:
## $Id: Escape.pm,v 1.1 1999/07/21 19:12:38 kraven Exp $#package URI::Escape;use strict;=head1 NAMEURI::Escape - Escape and unescape unsafe characters=head1 SYNOPSIS use URI::Escape; $safe = uri_escape("10% is enough\n"); $verysafe = uri_escape("foo", "\0-\377"); $str  = uri_unescape($safe);=head1 DESCRIPTIONThis module provide functions to escape and unescape URI strings.Some characters are regarded as "unsafe" and must be escaped inaccordance with RFC 1738.  Escaped characters are represented by atriplet consisting of the character "%" followed by two hexadecimaldigits.  The following functions are provided (and exported bydefault):=over 4=item uri_escape($string, [$unsafe])This function replaces all unsafe characters in the $string with theirescape sequence and return the result.The uri_escape() function takes an optional second argument thatoverrides the set of characters that are to be escaped.  The set isspecified as a string that can be used in a regular expressioncharacter class (between [ ]).  E.g.:  \x00-\x1f\x7f-\xff          # all control and hi-bit characters  a-z                         # all lower case characters  ^A-Za-z                     # everything not a letterThe default set of characters to be escaped is:  \x00-\x20"#%;<>?{}|\\^~`\[\]\x7F-\xFF=item uri_unescape($string)Returns a string with all %XX sequences replaced with the actualcharacter.=backThe module can also export the %escapes hash which contains themapping from all characters to the corresponding escape code.=head1 SEE ALSOL<URI::URL>=head1 COPYRIGHTCopyright 1995-1997 Gisle Aas.This program is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.=cutuse vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);use vars qw(%escapes);require Exporter;@ISA = qw(Exporter);@EXPORT = qw(uri_escape uri_unescape);@EXPORT_OK = qw(%escapes);$VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);use Carp ();# Build a char->hex mapfor (0..255) {    $escapes{chr($_)} = sprintf("%%%02X", $_);}my %subst;  # compiled patternessub uri_escape{    my($text, $patn) = @_;    return undef unless defined $text;    if (defined $patn){	unless (exists  $subst{$patn}) {	    # Because we can't compile regex we fake it with a cached sub	    $subst{$patn} =	      eval "sub {\$_[0] =~ s/([$patn])/\$escapes{\$1}/g; }";	    Carp::croak("uri_escape: $@") if $@;	}	&{$subst{$patn}}($text);    } else {	# Default unsafe characters. (RFC1738 section 2.2)	$text =~ s/([\x00-\x20\"#%;<>?{}|\\^~`\[\]\x7F-\xFF])/$escapes{$1}/g;    }    $text;}sub uri_unescape{    # Note from RFC1630:  "Sequences which start with a percent sign    # but are not followed by two hexadecimal characters are reserved    # for future extension"    my @copy = @_;    for (@copy) { s/%([\dA-Fa-f]{2})/chr(hex($1))/eg; }    wantarray ? @copy : $copy[0];}1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -