Module: Api2Convert::Support::Strings

Defined in:
lib/api2convert/support/strings.rb

Overview

Small string helpers shared across the SDK. Internal, not part of the public API.

Class Method Summary collapse

Class Method Details

.trim_trailing(value, chars) ⇒ Object

Strip every trailing character contained in chars from value.

Deliberately a scan rather than a regex: %r/+\z and friends backtrack, so a string ending in a long run of separators costs O(n^2) to match (CodeQL's rb/polynomial-redos). job.server arrives from the API and base_url from caller config, so neither is worth a quadratic path. This is a single reverse scan — O(n), no backtracking, identical result.



16
17
18
19
20
# File 'lib/api2convert/support/strings.rb', line 16

def trim_trailing(value, chars)
  last = value.length
  last -= 1 while last.positive? && chars.include?(value[last - 1])
  last == value.length ? value : value[0, last]
end