Boris Zentner wrote:

No, I think the stored strings are correct currently. The example use latin1 chars that by luck are bellow 256 in utf8. In other words we can not convert them back. A conversion back and forth is not possible every-time.

But how APR::Table is supposed to know whether it should restore the UTF8 flag or not, if it has no place to store it?


How about this solution:

use Devel::Peek;
use Encode;
@str = ("Hi " . chr(0x2663), "there");
for my $str (@str) {
    print "perl original string:\n";
    Dump($str);
    Encode::_utf8_off($str); # simulate set/get to apr::Table
    print "perl string returned from APR::Table:\n";
    Dump($str);
    print "fixed perl string:\n";
    $str = decode("utf8", $str);
    Dump($str);
    print "\n------------\n";
}

Here I've added: $str = decode("utf8", $str); to your original example. As you can see, both ascii and real unicode are handled correctly.

/tmp> perl utf8.pl
perl original string:
SV = PV(0x804cef8) at 0x804cc20
  REFCNT = 2
  FLAGS = (POK,pPOK,UTF8)
  PV = 0x805f450 "Hi \342\231\243"\0 [UTF8 "Hi \x{2663}"]
  CUR = 6
  LEN = 7
perl string returned from APR::Table:
SV = PVMG(0x80cee20) at 0x804cc20
  REFCNT = 2
  FLAGS = (SMG,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x805f450 "Hi \342\231\243"\0
  CUR = 6
  LEN = 7
  MAGIC = 0x80fe258
    MG_VIRTUAL = &PL_vtbl_utf8
    MG_TYPE = PERL_MAGIC_utf8(w)
    MG_LEN = 4
fixed perl string:
SV = PVMG(0x80cee20) at 0x804cc20
  REFCNT = 2
  FLAGS = (SMG,POK,pPOK,UTF8)
  IV = 0
  NV = 0
  PV = 0x80feeb0 "Hi \342\231\243"\0 [UTF8 "Hi \x{2663}"]
  CUR = 6
  LEN = 7
  MAGIC = 0x80fe258
    MG_VIRTUAL = &PL_vtbl_utf8
    MG_TYPE = PERL_MAGIC_utf8(w)
    MG_LEN = 4

------------
perl original string:
SV = PV(0x804cf4c) at 0x804cd04
  REFCNT = 2
  FLAGS = (POK,pPOK)
  PV = 0x805db78 "there"\0
  CUR = 5
  LEN = 6
perl string returned from APR::Table:
SV = PV(0x804cf4c) at 0x804cd04
  REFCNT = 2
  FLAGS = (POK,pPOK)
  PV = 0x805db78 "there"\0
  CUR = 5
  LEN = 6
fixed perl string:
SV = PV(0x804cf4c) at 0x804cd04
  REFCNT = 2
  FLAGS = (POK,pPOK,UTF8)
  PV = 0x80fef08 "there"\0 [UTF8 "there"]
  CUR = 5
  LEN = 6

------------


-- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to