Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: What does utf8::upgrade actually do.

by dave_the_m (Monsignor)
on Feb 17, 2021 at 09:04 UTC ( [id://11128489]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
    @codepoints = map ord($_), split //, $s1;
    $s2 = join '', map chr($_), @codepoints;
    ok($s1 eq $s2);
    ok(length($s1) == length($s2);
  2. or download this
    $s1 = "abc\x80";
    $s2 = $s1;        # currently SVf_UTF8 not set; string uses 4 bytes of
    + storage
    chop($s2);        # currently perl doesn't downgrade; the 0x80 codepoi
    +nt still stored as 2 bytes
    ok($s1 eq $s2);
    ok(length($s1) == length($s2));
  3. or download this
    utf8::downgrade($s2); # the the 0x80 codepoint now stored as 1 byte
    ok(length($s1) == $length($s2));
    ok($s1 eq $s2);

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (8)
As of 2024-04-17 16:02 GMT
Find Nodes?
    Voting Booth?

    No recent polls found