module TCellAgent::Utils::Strings

Constants

BLANK_RE

Public Class Methods

blank?(str) click to toggle source
# File lib/tcell_agent/utils/strings.rb, line 6
def self.blank?(str)
  str.nil? || str.empty? || BLANK_RE === str
end
java_hashcode(str) click to toggle source

emulate the java String.hashcode() without upcasting to BigInt

# File lib/tcell_agent/utils/strings.rb, line 21
def self.java_hashcode(str)
  result = 0
  str.each_codepoint do |cp|
    # prevent overflow into BigInt which would cause heap allocs + emulate c-style int32 signed add overflow
    result = ((((((result & 0x07FFFFFF) << 5) - result) + cp) + 0x80000000) & 0xFFFFFFFF) - 0x80000000
  end
  result
end
present?(str) click to toggle source
# File lib/tcell_agent/utils/strings.rb, line 10
def self.present?(str)
  !blank?(str)
end
remove_trailing_slash(path) click to toggle source
# File lib/tcell_agent/utils/strings.rb, line 14
def self.remove_trailing_slash(path)
  return path.chomp('/') if path && path != '/'

  path
end