[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Logical To Visual HTML Converter
Hi,
Attached is my naive logical Hebrew to visual Hebrew converter. I use this
to convert pages on-the-fly.
Regards,
- yba
EE 77 7F 30 4A 64 2E C5 83 5F E7 49 A6 82 29 BA ~. .~ TclTek Ltd.
=}-------------------------------------------------ooO--U--Ooo-----------{=
- benavrhm@tcltek.co.il - tel: +972.52.670.353, http://www.tcltek.co.il -
#!/usr/bin/perl
sub visual
{
my ($sam) = @_;
my ($buff) = "";
@f = split '', $sam;
$i = $first = $last = 0;
$state = "LETTER";
$number = "";
$linelength = 60;
foreach $c (@f)
{
if ($c eq " ")
{
$last = $i;
}
if (0 == ($i % $linelength) && ($i > 0))
{
if ($last == $first) { $last = $i; }
for ($j=$last; $j>=$first; $j--)
{
if (grep /[0-9]/, $f[$j])
{
$state = "NUMBER";
$number = $f[$j] . $number;
}
else
{
if ($state eq "NUMBER")
{
$buff .= $number;
$number = "";
$state = "LETTER";
}
$buff .= $f[$j];
}
}
$first = $last + 1;
$buff .= "<BR>\n";
}
$i++;
}
if ($first < $#f)
{
for ($j = $#f; $j >= $first; $j--)
{
$buff .= $f[$j];
}
}
# clip leading and trailing blanks
$buff =~ s/^\040*/$1/;
$buff =~ s/\040*$/$1/;
return $buff;
}
$text = "";
while (<>)
{
$text .= $_;
}
@strings = split /([\000-\073\220-\377]*[\220-\377][\000-\073]*)/, $text;
foreach $str (@strings)
{
if (grep /[\220-\377]/, $str)
{
print visual($str);
}
else
{
print $str;
}
}