Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 6 and print columns

Tags:

perl

raku

Does Perl 6 have something equivalent to the Unicode::GCString's columns method?

Perl 5 example:

#!/usr/bin/env perl
use warnings;
use strict;
use 5.10.0;
use utf8;
use open qw( :std :utf8 );
use Unicode::GCString;

my $s = '合'; # U+5408

say length $s;      # 1

my $gcs = Unicode::GCString->new( $s );
say $gcs->columns;  # 2
like image 276
sid_com Avatar asked Jul 06 '15 16:07

sid_com


1 Answers

Perl6 has builtin Unicode support, with native Uni and NFC/NFD/NFKC/NFKD normalized types.

What I vaguely understand is, that the Unicode::GCString::columns method determines eastasian language linebreaking support. 合 is composed of 2 "syllables" (they call it "grapheme clusters") on top of each other, thus 2 columns.

That being said, perl6 internally (on the MoarVM level) has access to the unicode database where the linebreaking properties are stored, but to my knowledge there's currently no module, like Unicode::UCD available to make the East_Asian_Width properties available for something like a Unicode::GCString.

On the other side, converting Unicode::LineBreak to perl6 looks easy enough, accessing the sombok library via NativeCall.

like image 76
rurban Avatar answered Oct 14 '22 02:10

rurban