1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 18:45:42 -04:00
perlbuut/lib/Bot/BB3/MacroQuote.pm
2009-12-05 00:02:04 -05:00

20 lines
695 B
Perl

# This package defines the quoting methods common between the
# quote and arg plugins.
package Bot::BB3::MacroQuote;
sub quote {
my($m,$s) = @_;
if ("z" eq $m) { # no-op
return $s;
} elsif ("c" eq $m || "d" eq $m) { # c-like quoting (without or with double-quote delimiter)
$s =~ s/([\x00\x01\n\r\x10\"\#\$\'\@\\])/sprintf"\\x%02x",ord$1/ge;
return "d" eq $m ? qq["$s"] : $s;
} elsif ("e" eq $m || "f" eq $m) { # quote almost everything
$s =~ s/(\W)/sprintf"\\x%02x",ord$1/ge;
return "f" eq $m ? qq["$s"] : $s;
} elsif ("h" eq $m) { # pack byte to two hex digits each, if nothing else this must work
return unpack "H*", $s;
} else { # unknown quoting mode
return $s;
}
}
1;