Re: String Encocoding in Gtk-Perl: Hoping for Clarification
- From: Brian Manning <elspicyjack gmail com>
- To: Peter Daum <gator_ml yahoo de>
- Cc: gtk-perl-list gnome org
- Subject: Re: String Encocoding in Gtk-Perl: Hoping for Clarification
- Date: Sat, 8 May 2010 23:42:24 -0700
On Sat, May 8, 2010 at 10:42 AM, Peter Daum <gator_ml yahoo de> wrote:
In the past, all data returned from any Gtk widgets used to be
UTF8-encoded (I vaguely remember that there were some locale-dependant
issues; I consistently use "en_US.ISO-8859-1"). Now in the same context
I get 8-bit data.
Gtk2-Perl is still returning UTF-8 data.
Platform: OS X 10.5 with Perl 5.10 and Gtk2-Perl 1.202, LANG=en_US.UTF-8.
Given:
#!/opt/local/bin/perl
use Gtk2 '-init';
my $window = Gtk2::Window->new();
my $button = new Gtk2::Button( "print" );
my $entry = new Gtk2::Entry;
my $vbox = Gtk2::VBox->new (FALSE, 8);
$window->add($vbox);
$vbox->add($button);
$vbox->add($entry);
# perl bitches about multibyte characters unless you set UTF-8 on STDOUT
binmode STDOUT, ":utf8";
$button->signal_connect( "clicked",sub {
my $word = $entry->get_text();
my @word = split(//, $word);
my $hexword = q();
foreach my $letter ( @word ) {
$hexword .= sprintf(q(0x%0x), ord($letter)) . q( );
} # foreach my $letter ( @word )
print qq|$word ( $hexword )\n|;
} );
$window->show_all();
Gtk2->main;
I can input 'test' and 'ÑÐÑÑ' (a string that needs two bytes per
character to encode), and both will be printed to STDOUT as UTF-8:
[manzana][brian ~]$ perl output.test.pl
test ( 0x74 0x65 0x73 0x74 )
ÑÐÑÑ ( 0x442 0x435 0x441 0x442 )
As you can see, the output is not 8-bit for the second input string.
Even changing locales to the locale you gave doesn't change the output;
[manzana][brian ~]$ LANG=en_US.ISO-8859-1 perl output.test.pl
test ( 0x74 0x65 0x73 0x74 )
ÑÐÑÑ ( 0x442 0x435 0x441 0x442 )
Do you have a complete example that shows your problem?
Thanks,
Brian
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]