The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

BEGIN { $| = 1; print "1..11\n"; }
END {print "not ok 1\n" unless $loaded;}
use String::Multibyte;
$^W = 1;
$loaded = 1;
print "ok 1\n";

$mb = String::Multibyte->new('ShiftJIS',1);

#####

my $L82 = '(?:\x82[\x40-\xfc])';
my $L83 = '(?:\x83[\x40-\xfc])';

"‚`‚a‚bƒAƒCƒEƒGƒI" =~ /($L82+)($L83+)/;

print "‚`‚a‚b" eq $1 && "ƒAƒCƒEƒGƒI" eq $2
  ? "ok" : "not ok", " 2\n";

print $mb->length($1) == 3
   && $mb->length($2) == 5
  ? "ok" : "not ok", " 3\n";

print $mb->strrev($1) eq "‚b‚a‚`"
   && $mb->strrev($2) eq "ƒIƒGƒEƒCƒA"
  ? "ok" : "not ok", " 4\n";

print "‚a‚b" eq $mb->substr($1,1,2)
   && "ƒEƒGƒI" eq $mb->substr($2,-3)
  ? "ok" : "not ok", " 5\n";

print "ABC" eq $mb->strtr($1,'‚`-‚y','A-Z')
   && "ƒAƒCƒEƒGƒI" eq $mb->strtr($2,'‚`-‚y','A-Z')
  ? "ok" : "not ok", " 6\n";

print "‚`‚a‚b" eq $mb->strtr($1,'ƒA-ƒ“','‚ -‚ñ')
   && "‚ ‚¢‚¤‚¦‚¨" eq $mb->strtr($2,'ƒA-ƒ“','‚ -‚ñ')
  ? "ok" : "not ok", " 7\n";

print "‚`‚a‚b" eq $1 && "ƒAƒCƒEƒGƒI" eq $2
  ? "ok" : "not ok", " 8\n";

my $str = "‚`‚a‚bƒAƒCƒEƒGƒI“““‚w‚x‚yƒnƒqƒtƒwƒz";

$str =~ s/($L82+)($L83+)/
    $mb->strtr($1,'‚`-‚y','A-Z') . $mb->strtr($2,'ƒA-ƒ“','‚ -‚ñ')
/ge;

print $str eq "ABC‚ ‚¢‚¤‚¦‚¨“““XYZ‚͂ЂӂւÙ"
  ? "ok" : "not ok", " 9\n";

$str =~ s/($L82+)/$mb->strrev($mb->substr($1,1,3))/ge;

print $str eq "ABC‚¦‚¤‚¢“““XYZ‚Ö‚Ó‚Ð"
  ? "ok" : "not ok", " 10\n";

$str =~ s/($L82+)/$mb->length($1)/ge;

print $str eq "ABC3“““XYZ3"
  ? "ok" : "not ok", " 11\n";

1;
__END__