mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 10:35:41 -04:00
20 lines
695 B
Text
20 lines
695 B
Text
# 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;
|