Module: TCellAgent::Utils::Strings
- Defined in:
- lib/tcell_agent/utils/strings.rb
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/
Class Method Summary collapse
- .blank?(str) ⇒ Boolean
-
.java_hashcode(str) ⇒ Object
emulate the java String.hashcode() without upcasting to BigInt.
- .present?(str) ⇒ Boolean
- .remove_trailing_slash(path) ⇒ Object
Class Method Details
.blank?(str) ⇒ Boolean
6 7 8 |
# File 'lib/tcell_agent/utils/strings.rb', line 6 def self.blank?(str) str.nil? || str.empty? || BLANK_RE === str # rubocop:disable Style/CaseEquality end |
.java_hashcode(str) ⇒ Object
emulate the java String.hashcode() without upcasting to BigInt
21 22 23 24 25 26 27 28 |
# 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) ⇒ Boolean
10 11 12 |
# File 'lib/tcell_agent/utils/strings.rb', line 10 def self.present?(str) !blank?(str) end |
.remove_trailing_slash(path) ⇒ Object
14 15 16 17 18 |
# File 'lib/tcell_agent/utils/strings.rb', line 14 def self.remove_trailing_slash(path) return path.chomp('/') if path && path != '/' path end |