Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: What does utf8::upgrade actually do.

by dave_the_m (Monsignor)
on Feb 17, 2021 at 09:04 UTC ( #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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-05-24 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?