Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Intra-Unicode Conversions

by kettle (Beadle)
on Nov 15, 2006 at 17:46 UTC ( [id://584229]=note: print w/replies, xml ) Need Help??


in reply to Intra-Unicode Conversions

Thanks so much for all the great explanations! That really cleared things up. I also wrote a hack to solve the problem I alluded to at the end of my first post. It is extremely inefficient, but seems to properly carry out all of the conversions I'm interested in. Please rip it to shreds for me:
#!/usr/bin/perl -w use strict; use warnings; #Convert annoying, worthless 'fullwidth' Latin-1 characters #to their semi-sane normal ASCII counterparts my(%codes,$wide,$ascii,$x); #this is the land where the fullwidth latin-1 characters reside for($x=65281;$x<65374;$x++){ ($wide,$ascii) = make_codes($x); $codes{$wide} = $ascii; } while(<>){ chomp; foreach my $utf(keys %codes){ s/$utf/$codes{$utf}/g; } print $_."\n"; } sub make_codes{ my $ud = $_[0]; my $from = ud_to_utf8hex($ud); #subtract 65248 to get the ASCII value my $to = ud_to_utf8hex($ud-65248); return($from, $to); } sub ud_to_utf8hex{ my $ud = $_[0]; my ($b1,$b2,$b3); if($ud >= 0 && $ud <= 127){ #basic ASCII values don't need to be a +ltered return(sprintf("%c",$ud)); }elsif($ud >= 2048 && $ud <= 65535){ #valid for 2048 <= $ud <= 655 +35 $b1 = 224 + sprintf("%d", ($ud/4096)); $b2 = 128 + (($ud/64) % 64); $b3 = 128 + ($ud % 64); } return(sprintf("\\x\{%X\}\\x\{%X\}\\x\{%X\}",$b1,$b2,$b3)); }
I chose to use the decimal numbers for some practice with the unicode standard, and because they are easier on my brain than the hex codes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://584229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found