There's a snippit for this in the output_message function of cbstream.rb. (This code has quote a few places where it does ugly hacks with character encodings, because it was written back when only ruby 1.8 existed. Nowadays we have ruby 1.9 which has a better system for handling strings with various encodings than perl.) It's not directly applicable here, but the principle is the same.
Assumes $str contains the decoded string. Then, after
$1 should contain at most 384 bytes and not end with an incomplete utf-8 character.$str =~ /\A(.{0,383}[\x00-\xbf]|)/s or die;
Update: ikegami's right, the above regex is wrong. (I still believe the one in cbstream is right, but does something different.)
In reply to Re: limiting length of utf8 string in bytes
by ambrus
in thread limiting length of utf8 string in bytes
by pbijnens
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |