Skip to content

Instantly share code, notes, and snippets.

@leedo
Created January 6, 2011 17:57
Show Gist options
  • Save leedo/768263 to your computer and use it in GitHub Desktop.
Save leedo/768263 to your computer and use it in GitHub Desktop.
*{AnyEvent::IRC::Util::split_unicode_string} = sub {
my ($enc, $str, $maxlen) = @_;
return $str unless length (encode ($enc, $str)) > $maxlen;
my $cur_out = '';
my $word = '';
my @lines;
while (length ($str) > 0) {
$word .= substr $str, 0, 1, '';
if ($word =~ /\w\W$/ || length ($str) == 0) {
if (length (encode ($enc, $cur_out.$word)) > $maxlen) {
push @lines, $cur_out;
$cur_out = '';
}
$cur_out .= $word;
$word = '';
}
}
push @lines, $cur_out if length ($cur_out);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment