This RabbitMQ page states:
Queue names may be up to 255 bytes of UTF-8 characters.
In ruby (1.9.3), how would I truncate a UTF-8 string by byte-count without breaking in the middle of a character? The resulting string should be the longest possible valid UTF-8 string that fits in the byte limit.
For Rails >= 3.0 you have ActiveSupport::Multibyte::Chars limit method.
From API docs:
- (Object) limit(limit)
Limit the byte size of the string to a number of bytes without breaking characters. Usable when the storage for a string is limited for some reason.
Example:
'こんにちは'.mb_chars.limit(7).to_s # => "こん"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With