in reply to How to convert between Unicode codepoint and UTF8 character code on Perl?
TIMTOWTDI but here's an illustrative test. See also How to ask better questions using Test::More and sample data
use strict; use warnings; use Encode 'encode'; use Unicode::Char; use Test::More tests => 2; is to_bytes ('0x03C0'), 'CF80', 'Code point to bytes (0x format)'; is to_bytes ('U+03C0'), 'CF80', 'Code point to bytes (U+ format)'; sub to_bytes { my $u = Unicode::Char->new; (my $in = shift) =~ s/^(?:0x|U\+)//; return uc unpack 'H*', encode 'UTF-8', $u->u ($in); }
Translating bytes to code points is left as an exercise.
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to convert between Unicode codepoint and UTF8 character code on Perl?
by wyt248er (Initiate) on Oct 25, 2021 at 04:34 UTC | |
by hippo (Archbishop) on Oct 25, 2021 at 10:19 UTC | |
by Anonymous Monk on Oct 25, 2021 at 07:38 UTC |