#!/usr/local/bin/perl
# These are the URL encode subroutines from the text. They must be called from another script.
# noexec

sub url_encode {
    my $text = shift;
    $text =~ s/([^a-z0-9_.!~*'() -])/sprintf "%%%02X", ord($1)/egi;
    $text =~ tr/ /+/;
    return $text;
}


sub url_decode {
    my $text = shift;
    $text =~ tr/+/ /;
    $text =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;
    return $text;
}

sub html_encode {
    my $line = shift;
    $line =~ s/&/&amp;/g;
    $line =~ s/</&lt;/g;
    $line =~ s/>/&gt;/g;
    return $line;
}

1;
