Re: Word boundaries
[email protected] (Lars Dɪᴇᴄᴋᴏᴡ 迪拉斯) Mon, 26 Mar 2012 12:57:51 +0200
| Newsgroups | perl.unicode |
|---|---|
| Message-ID | <[email protected]> |
--Sig_/JGEXu6Y1/.yZUPQu4pZu609
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
> How can I check what script a character belongs to?
$ perl -Mutf8 -MUnicode::UCD=3Dcharinfo -E'say charinfo(ord
"=E4=B8=BA")->{script}'
Han
Sanity checks:
$ perl -Mutf8 -E'say "=E4=B8=BA" =3D~ /\p{Han}/'
1
$ uniprops -a1 =E4=B8=BA | ack Script
Script=3DHan
Script=3DHani
> check if it is the same as the
> previous one - i.e. back to C mode of programming.
Let the regex engine help you advance the character counter.
$ cat langs
=CE=95=CE=BB=CE=BB=CE=B7=CE=BD=CE=B9=CE=BA=CE=ACEnglish=ED=95=9C=EA=B5=
=AD=EC=96=B4=E6=97=A5=E6=9C=AC=E8=AA=9E=D0=A0=D1=83=D1=81=D1=81=D0=BA=D0=B8=
=D0=B9=E0=B9=84=E0=B8=97=E0=B8=A2
----
$ cat langs.pl
use 5.010;
use strictures;
use Unicode::UCD qw(charinfo);
sub script {
return charinfo(ord substr($_[0], 0, 1))->{script}
};
# necessary because pos() magic is tracked on the scalar.
my $copy =3D $_;=20
while (/(\X)/g) {
my $script =3D script $1;
my ($part) =3D $copy =3D~ /(\p{$script}+)/;
say $part;
pos($_) =3D pos($_) + length($part);
}
----
$ perl -C -ln langs.pl < langs
=CE=95=CE=BB=CE=BB=CE=B7=CE=BD=CE=B9=CE=BA=CE=AC
English
=ED=95=9C=EA=B5=AD=EC=96=B4
=D0=A0=D1=83=D1=81=D1=81=D0=BA=D0=B8=D0=B9
=E0=B9=84=E0=B8=97=E0=B8=A2
--Sig_/JGEXu6Y1/.yZUPQu4pZu609
Content-Type: application/pgp-signature; name=signature.asc
Content-Disposition: attachment; filename=signature.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
iEYEARECAAYFAk9wS7cACgkQFtlTdOX00HoWIwCfV4HorC9YiPJY8bwghoIq6ZpO
QMwAnAvw259rLOPVtCr64tWW+dKEq8Z4
=igKO
-----END PGP SIGNATURE-----
--Sig_/JGEXu6Y1/.yZUPQu4pZu609--