Grokbase
x

Re: Can I `see' what encoding my stream is?

View PostFlat  Thread  Threaded | < Prev - Next >
Tux Re: Can I `see' what encoding my stream is?
| +1 vote
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Tue, 9 Feb 2010 10:21:42 +0100, "H.Merijn Brand"
<h.m.brand@xs4all.nl> wrote:

> On Mon, 08 Feb 2010 23:40:32 +0100, Slaven Rezic <slaven@rezic.de>
> wrote:
>
> > "H.Merijn Brand" <h.m.brand@xs4all.nl> writes:
> >
> > >
> > > To prevent double encoding, is it possible to `see' (from XS) that the
> > > stream is opened with something like
> > >
> > >  open my $dst, ">:utf8", "file";
> > > or
> > > open my $dst, ">:encoding(utf8)", "file";
> > > or
> > >  open my $dst, ">", "file";
> > >  binmode $dst, ":encoding(utf8)";
> > >
> > > ?
> >
> > Check the output of PerlIO::get_layers($dst).
>
> Right, so is this a bug:
> --8<---
> use strict;
> use warnings;
>
> use Data::Peek;
>
> my $out = "";
> open my $fh, ">:utf8", \$out;
>
> DDumper [ PerlIO::get_layers ($fh, details => 1) ];
> -->8---

FWIW: This looks more sane:

open my $fh, ">:encoding(utf8)", \$out;

=>

$VAR1 = [
    'scalar',
    undef,
    6296064,
    'encoding',
    'utf8',
    4231680
];


> =>
>
> $VAR1 = [
>     'scalar',
>     undef,
>     6328832
>     ];
>
> Where is my "utf8" layer?
>


--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/

Thread : Can I `see' what encoding my stream is?
1)
Tux In XS, I have the following snippet: SV *tmp = newSVpv (csv->buffer, csv->used); dSP;...
2)
Slaven Rezic Check the output of PerlIO::get_layers($dst).
3)
Tux Right, so is this a bug: use strict; use warnings; use Data::Peek; my $out = ""; open my $fh,...
4)
Tux FWIW: This looks more sane: open my $fh, ">:encoding(utf8)", \$out; $VAR1 = [ 'scalar', undef,...
5)
Eirik Berg Hanssen Try PerlIO::get_layers ($fh) =96 or, for clarity, PerlIO::get_layers Alternatively, you could note...
6)
Tux Thanks for all the feedback, This code now prevents double encoding in Text::CSV_XS: #ifdef...
7)
Ben Morrow Quoth h.m.brand@xs4all.nl ("H.Merijn Brand"): universal.c as a wrapper around PerlIO_get_layers,...
spacer
View PostFlat  Thread  Threaded | < Prev - Next >