}
sub Entity (@) {
- my $ref;
- my @copy;
- if (defined wantarray) {
- @copy = @_;
- $ref = \@copy;
- } else {
- $ref = \@_;
- }
+ my $ref = defined wantarray ? [@_] : \@_;
for (@$ref) {
eval {
s/&/&/g;
s/\t/ /g;
s/ / /g;
};
-# if ($@){ return defined wantarray ? @_ : undef }
}
return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
}
sub DecodeURI (@) {
- # Browsers do s/ /+/ - I don't care about RFC's, but I do care about real-life
- # situations.
- my @r;
- local $_;
- for (@_) {
- s/\+/%20/g;
- my $dec = $_;
- $dec =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
- if (defined wantarray) {
- push @r, $dec;
- } else {
- eval {$_ = $dec};
-# return undef if $@; # ;DecodeURI("foo");
- }
+ my $ref = defined wantarray ? [@_] : \@_;
+ for (@$ref) {
+ eval {
+ s/\+/%20/g; # Browsers do y/ /+/ - I don't care about RFC's, but
+ # I do care about real-life situations.
+ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
+ };
}
- return defined wantarray ? (wantarray ? @r : "@r") : undef;
+ return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
}
sub EncodeURI (@) {
- my @r;
- local $_;
- for (@_) {
- my $esc = $_;
- $esc =~
- s{
- ([^\/?:@\$,A-Za-z0-9\-_.!~*\'()])
- }{
- sprintf("%%%02x", ord($1))
- }xge;
- if (defined wantarray) {
- push @r, $esc;
- } else {
- eval {$_ = $esc};
-# return undef if $@; # ;EncodeURI("foo");
- }
+ my $ref = defined wantarray ? [@_] : \@_;
+ for (@$ref) {
+ eval {
+ s{([^A-Za-z0-9\-_.!~*'()/?:@\$,])}{sprintf("%%%02x", ord $1)}ge;
+ };
}
- return defined wantarray ? (wantarray ? @r : "@r") : undef;
+ return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
}
sub AddCookie ($) {
sub AutoURL ($) {
# This sub assumes your string does not match /(["<>])\cC\1/
- my $ref;
- if (defined wantarray){
- $ref = \(my $copy = $_[0]);
- }else{
- $ref = \$_[0];
- }
+ my $ref = defined wantarray ? \(my $copy = $_[0]) : \$_[0];
eval {
$$ref =~ s/"/"\cC"/g; # Single characters are easier to match :)
$$ref =~ s/>/>\cC>/g; # so we can just use a character class []