Module: LogStash::Util::UnicodeTrimmer
- Defined in:
- lib/logstash/util/unicode_trimmer.rb
Constant Summary collapse
- MAX_CHAR_BYTES =
The largest possible unicode chars are 4 bytes stackoverflow.com/questions/9533258/what-is-the-maximum-number-of-bytes-for-a-utf-8-encoded-character tools.ietf.org/html/rfc3629
4
Class Method Summary collapse
Class Method Details
.trim_bytes(orig_str, desired_bytes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/logstash/util/unicode_trimmer.rb', line 15 def self.trim_bytes(orig_str, desired_bytes) return orig_str if orig_str.bytesize <= desired_bytes pre_shortened = pre_shorten(orig_str, desired_bytes) case pre_shortened.bytesize <=> desired_bytes when 0 pre_shortened when 1 shrink_bytes(pre_shortened, orig_str, desired_bytes) when -1 grow_bytes(pre_shortened, orig_str, desired_bytes) end end |