Module: LogStash::Util::UnicodeTrimmer

Defined in:
lib/logstash/util/unicode_trimmer.rb

Constant Summary collapse

MAX_CHAR_BYTES =
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