Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to Use Pack to Convert UTF-16 Surrogate Pairs to UTF-8?

by haukex (Archbishop)
on Jun 09, 2022 at 08:02 UTC ( [id://11144542]=note: print w/replies, xml ) Need Help??


in reply to How to Use Pack to Convert UTF-16 Surrogate Pairs to UTF-8?

I would really like a solution that just uses pack without having to use any additional libraries (JSON::XS, Encode, etc.).

Why? This very much smells like an X/Y problem to me. JSON::PP has been in the core for over 11 years (since Perl 5.14).

use warnings; use strict; use JSON::PP; use Data::Dump; my $enc = '"Alice \ud83d\ude06 Bob"'; my $json = JSON::PP->new->allow_nonref; dd $json->decode($enc); # "Alice \x{1F606} Bob"

Minor edit for clarification.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found