36 lines
646 B
Perl
36 lines
646 B
Perl
#!/usr/bin/perl
|
|
package Simba::Util;
|
|
|
|
use warnings;
|
|
use strict;
|
|
use Exporter qw( import );
|
|
use Encode qw(decode encode );
|
|
|
|
our @EXPORT_OK = qw(quote unquote typestr);
|
|
|
|
sub quote {
|
|
my ($s) = @_;
|
|
$s =~ s{[\000-\040&=]}{sprintf("&#%d;", ord($&))}eg;
|
|
return encode('utf-8', $s);
|
|
}
|
|
|
|
sub unquote {
|
|
my ($s) = @_;
|
|
$s = decode('utf-8', $s);
|
|
$s =~ s{&#(\d+);}{chr($1)}eg;
|
|
return $s;
|
|
}
|
|
|
|
my @typestr = (
|
|
#0 1 2 3 4 5 6 7
|
|
'?', 'p', 'c', '?', 'd', '?', 'b', '?',
|
|
'f', '?', 'l', '?', 's', '?', '?', '?',
|
|
);
|
|
sub typestr {
|
|
my ($mode) = @_;
|
|
$mode >>= 12;
|
|
return $typestr[$mode] || '?';
|
|
}
|
|
|
|
1;
|