#! /usr/local/bin/perl
use strict;
use warnings;
# $i: italic
# $s: shadowed
# $w: wide spacing
# $n: narrow spacing
# $m: normal setting
# $g: default color
# $t: changes the text to capitals
# $z: reset all
# $$: to write a "$"
my %classes = (
i => 'italics',
s => 'shadowed',
w => 'wide',
n => 'narrow',
m => 'normal',
);
my %testcases = (
'$iMy$z$w$f00Nickname' => 'MyNickname',
'$s$5aaD$ddfia$5aaD$ddfe$5cc§' => 'DiaDe§',
'$iT$sh$wi$ns is $m$444silly$z $tsmall stuff$z and BIG STUFF' => 'This is silly SMALL STUFF and BIG STUFF',
'$wWIDE$nNARROW$mnormal' => 'WIDENARROWnormal',
'$ta$$zas$zdf' => 'A$ZASdf',
'$tasdf' => 'ASDF',
);
foreach ( keys %testcases ) {
my $string = $_;
my @tags;
while ( $string =~ m/(\$[iswnmgtz\$]|\$[0-9a-f]{3,3})/ig ) {
my $pos = pos($string);
my $taglen = 2;
my $replacement = "";
my $c = lc(substr($1,1,1));
if(my $class = $classes{$c}) {
$replacement = "";
unshift(@tags, '');
} elsif($c eq 'g') {
$replacement = '';
unshift(@tags, '');
} elsif($c eq 't') {
my $length = length($string) - $pos;
while ( $string =~ m/(\$[iswnmgtz\$]|\$[0-9a-f]{3,3})/ig ) {
if(lc($1) eq '$z') {
$length = pos($string) - $pos - 2;
last;
}
}
substr($string, $pos, $length, uc( substr($string, $pos, $length) ) );
} elsif($c eq 'z') {
local $" = "";
$replacement = "@tags";
@tags = ();
} elsif($c eq '$') {
$replacement = '$';
} else {
$taglen = 4;
my ($x, $r, $g, $b) = split(//,$1);
$replacement = "";
unshift(@tags, '');
}
substr($string, $pos - $taglen, $taglen, $replacement);
pos($string) = $pos - $taglen + length($replacement);
}
{ local $" = ""; $string .= "@tags"; }
if($string eq $testcases{$_}) {
print "Ok '$_' =>\n '$string'\n";
} else {
print "Not Ok '$_' =>\n '$string' expecting:\n '$testcases{$_}'\n";
}
}
####
#! /usr/local/bin/perl
use strict;
use warnings;
# $i: italic
# $s: shadowed
# $w: wide spacing
# $n: narrow spacing
# $m: normal setting
# $g: default color
# $t: changes the text to capitals
# $z: reset all
# $$: to write a "$"
my %classes = (
i => 'italics',
s => 'shadowed',
w => 'wide',
n => 'narrow',
m => 'normal',
);
foreach (
'$iMy$z$w$f00Nickname',
'$s$5aaD$ddfia$5aaD$ddfe$5cc§',
'$iT$sh$wi$ns is $m$444silly$z $tsmall stuff$z and BIG STUFF',
'$wWIDE$nNARROW$mnormal',
) {
my $string = $_;
my @tags;
while ( $string =~ m/(\$[iswnmgtz\$]|\$[0-9a-f]{3,3})/ig ) {
my $c = lc(substr($1,1,1));
if(my $class = $classes{$c}) {
substr($string,pos($string) - 2, 2, "");
push(@tags, '');
} elsif($c eq 'g') {
substr($string,pos($string) - 2, 2, '');
push(@tags, '');
} elsif($c eq 't') {
my $end = index($string, '$z', pos($string));
$end = length($string) if($end == -1);
substr($string,pos($string)-2 ,$end - pos($string) +2, uc(substr($string,pos($string), $end - pos($string))));
} elsif($c eq 'z') {
{ local $" = ""; substr($string,pos($string) - 2, 2, "@tags"); }
@tags = ();
} elsif($c eq '$') {
substr($string,pos($string) - 2, 2, '$');
} else {
my ($x, $r, $g, $b) = split(//,$1);
substr($string,pos($string) - 4, 4, "");
push(@tags, '');
}
}
{ local $" = ""; $string .= "@tags"; }
print "$string\n";
}
####
####
MyNickname
DiaDe§
This is silly SMALL STUFF and BIG STUFF
WIDENARROWnormal