[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hebrew Under gbiff



Ignoring silly things like startup latency, I thing Perl is better 
for this job:

#!/usr/bin/perl -w

print &tostring($ARGV[0]), "\n";

sub tostring {
  my $s = shift;
  my @spl = split('\?', $s);

  return $s if ($#spl != 3 || $spl[0] ne '=');

  ($_, $charset, $enc, $str) =  @spl;

  #TODO: handle other encodings and charsets
  return $s if $charset ne 'WINDOWS-1255' or $enc ne 'Q';

  $accum = "";
  while ($str =~ s/\=(..)//) {$accum = $accum.chr(hex($1))}
  return $s if length $str != 0;
  return $accum;
}

P.S. Thanks to whomever taught me Perl. Any comment is welcome.

> 
> On Tue, Dec 18, 2001, Tzafrir Cohen wrote about "Re: Hebrew Under gbiff":
> > On Wed, 12 Dec 2001, Herouth Maoz wrote:
> > 
> > > On 2001 December? 12 ,Wednesday 12:18, Eli Marmor wrote:
> > > > Aharon Schkolnik wrote:
> > > ..
> > > > > =?WINDOWS-1255?Q?=E0=E4=F8
> > > > >
> > > > > Does anyone know why this is, and if there is anything I can do
> > > > > about it ?
> > > ..
> > Where can I find such convertor already written?
> 
> Here's a little something I wrote to convert such quoted-printable
> headers (it doesn't support base64 yet). Note that it's in awk, and
> rather ugly; hackers-il devotees could start an entire flamewar on
> why awk sucks for this purpose and perl/python/algol would have been
> better - please avoid such arguments, and instead just provide better
> (and tested) code - if you have it.
> 
> function hextonum(c){
> 	c=toupper(c)
> 	if(c=="A"){ return 10;
> 	} else if(c=="B"){ return 11;
> 	} else if(c=="C"){ return 12;
> 	} else if(c=="D"){ return 13;
> 	} else if(c=="E"){ return 14;
> 	} else if(c=="F"){ return 15;
> 	} else { return c; }
> }
> function tostring(s   ,a,i,n,b1,b2){
> 	# convert header possibly encoded like RFC 2047 to string we can
> 	# use to send an SMS
> 	if(s !~ /^=\?/ || s !~ /\?=$/ || split(s,a,"\?")!=5){
> 		return s;
> 	}
> 	if(a[3]=="q" || a[3]=="Q"){
> 		s="";
> 		n=length(a[4])
> 		for(i=1;i<=n;i++){
> 			b=substr(a[4],i,1);
> 			if(b=="_"){
> 				s= s " "
> 			} else if(b=="="){
> 				b1=substr(a[4],i+1,1);
> 				b2=substr(a[4],i+2,1);
> 				i+=2
> 				s= s sprintf("%c", hextonum(b1)*16+hextonum(b2))
> 			} else {
> 				s= s b
> 			}
> 		}
> 		return s;
> 	}
> 	# TODO: handle B (base64) encoding
> 	# give up, I dont know what to do.
> 	return s;
> }
> 
> -- 
> Nadav Har'El                        |       Tuesday, Dec 18 2001, 3 Tevet 5762
> nyh@math.technion.ac.il             |-----------------------------------------
> Phone: +972-53-245868, ICQ 13349191 |Take my advice, I don't use it anyway.
> http://nadav.harel.org.il           |
> 
> =================================================================
> To unsubscribe, send mail to linux-il-request@linux.org.il with
> the word "unsubscribe" in the message body, e.g., run the command
> echo unsubscribe | mail linux-il-request@linux.org.il
> 


=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il