- or download this
sub truncate_utf8 {
my ($utf8, $len) = @_;
$len += 0; # Make sure $len is a number.
return $utf8 =~ s/^.{0,$len)\K(?![\x80-\xBF]).*//sr;
}
- or download this
use warnings;
use strict;
...
ok 14
ok 15
# Looks like you failed 10 tests of 15.
- or download this
sub truncate_utf8 {
my ($utf8, $len) = @_;
...
$next = chop($utf8) while (ord($next) & 0xC0) == 0x80;
return $utf8;
}
- or download this
use warnings;
use strict;
...
ok 14
ok 15
# Looks like you failed 10 tests of 15.