# #
# File: shared/CheckRFC.pm #
# #
-# Authors: Andre Malo <nd@o3media.de>, 2001-04-14 #
+# Authors: André Malo <nd@o3media.de> #
# #
# Description: implement several string checks on RFC correctness #
# #
use Carp qw(croak);
+################################################################################
+#
+# Version check
+#
+# last modified:
+# $Date$ (GMT)
+# by $Author$
+#
+sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
+
################################################################################
#
# Export
#
# Return: Status code (Bool)
#
-sub is_URL ($@) {
+sub is_URL (;$@) {
my ($string, @schemes) = @_;
+ $string = $_ unless defined $string;
+ my $scheme;
return unless (defined ($string) and length ($string));
@schemes = qw(http) unless (@schemes);
@schemes = keys %url if (@schemes == 1 and $schemes[0] eq ':ALL');
- for (@schemes) {
- croak "unknown url scheme '$_'" unless exists $url{$_};
- unless (/mailto/) {
- return 1 if ($string =~ /$url{$_}/);
+ for $scheme (@schemes) {
+ croak "unknown url scheme '$scheme'" unless exists $url{$scheme};
+ unless ($scheme =~ /mailto/) {
+ return 1 if ($string =~ /$url{$scheme}/);
}
else {
- return unless ($string =~ /^mailto:(.+)/);
-
- if ($_ eq 'mailto') {
- return 1 if (is_email ($1));
- }
- elsif ($_ eq 'strict_mailto') {
- return 1 if (is_email ($1,1));
+ if ($string =~ /^mailto:(.+)/) {
+
+ if ($scheme eq 'mailto') {
+ return 1 if (is_email ($1));
+ }
+ elsif ($scheme eq 'strict_mailto') {
+ return 1 if (is_email ($1,1));
+ }
}
}
}
#
# Return: Status code (Bool)
#
-sub is_email ($;$) {
+sub is_email (;$$) {
my $string = shift;
+ $string = $_ unless defined $string;
+ return unless defined $string;
+
my $strict = shift;
# false if any non-ascii chars
# remove nested comments
1 while ($string =~ s/\([^()]*\)//g);
- #$string =~ s/^\s+//;
- #$string =~ s/\s+$//;
return ($string =~ /^$email[0]$/) unless $strict;
# credits to an unknown(?) programmer ;)
# modified by n.d.p.
- my $lowalpha = '(?:[a-z])';
- my $hialpha = '(?:[A-Z])';
- my $alpha = "(?:$lowalpha|$hialpha)";
- my $digit = '(?:\d)';
- my $safe = '(?:[$_.+-])';
- my $extra = '(?:[!*\'(),])';
- my $national = '(?:[{}|\\\\^~\[\]`])';
- my $punctuation = '(?:[<>#%"])';
- my $reserved = '(?:[;/?:@&=])';
- my $hex = '(?:[\dA-Fa-f])';
+ my $lowalpha = '[a-z]';
+ my $hialpha = '[A-Z]';
+ my $alpha = '[a-zA-Z]';
+ my $digit = '\d';
+ my $safe = '[$_.+-]';
+ my $extra = '[!*\'(),]';
+ my $national = '[{}|\\\\^~\[\]`]';
+ my $punctuation = '[<>#%"]';
+ my $reserved = '[;/?:@&=]';
+ my $hex = '[\dA-Fa-f]';
my $escape = "(?:%$hex$hex)";
- my $unreserved = "(?:$alpha|$digit|$safe|$extra)";
+ my $unreserved = '[{}|\\\\^~\[\]`a-zA-Z\d$_.+-]'; #"(?:$alpha|$digit|$safe|$extra)";
my $uchar = "(?:$unreserved|$escape)";
my $xchar = "(?:$unreserved|$escape|$reserved)";
my $digits = '(?:\d+)';
- my $alphadigit = "(?:$alpha|\\d)";
+ my $alphadigit = '[a-zA-Z\d]'; #"(?:$alpha|$digit)";
# URL schemeparts for ip based protocols:
my $urlpath = "(?:$xchar*)";
}
}
-# keeping require happy
+# keep 'require' happy
1;
#