in reply to Re: Trying to determine the output length of a Unicode string
in thread Trying to determine the output length of a Unicode string
sub length_in_grapheme_clusters { my $length; $length++ while $_[0] =~ m/\X/g; return $length; }
As previously mentioned, this can be written as:
orsub length_in_grapheme_clusters { my $length = () = $_[0] =~ /\X/g; return $length; }
sub length_in_grapheme_clusters { return 0+( () = $_[0] =~ /\X/g ); }
You must roll your own.
As previously mentioned, he does not need to roll his own as there's already an existing solution. (It was also mentioned that length_in_grapheme_clusters is not sufficient.)
Update: Fixed length_in_grapheme_clusters so it can be called in list context.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Trying to determine the output length of a Unicode string
by Jim (Curate) on Sep 26, 2011 at 19:19 UTC | |
by ikegami (Patriarch) on Sep 26, 2011 at 19:37 UTC | |
by Jim (Curate) on Sep 26, 2011 at 20:18 UTC | |
by ikegami (Patriarch) on Sep 26, 2011 at 20:29 UTC | |
by Jim (Curate) on Sep 26, 2011 at 21:22 UTC | |
|