Skip to content

Commit

Permalink
refactor CutBlanks method and add deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 30, 2015
1 parent 1146a01 commit 14f5907
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions library/types/src/modules/String.rb
Expand Up @@ -307,19 +307,15 @@ def FormatTime(seconds)
end
end

# Remove blanks at begin and end of input string.
# Remove spaces and tabs at begin and end of input string.
# @param [String] input string to be stripped
# @return stripped string
# @example CutBlanks(" any input ") -> "any input"
# @deprecated if remove also \n then use {::String#strip}, otherwise simple sub is enough
# @example CutBlanks(" \tany input ") -> "any input"
def CutBlanks(input)
return "" if input.nil? || Ops.less_than(Builtins.size(input), 1)

pos1 = Builtins.findfirstnotof(input, " \t")
return "" if pos1.nil?

pos2 = Builtins.findlastnotof(input, " \t")
return "" if input.nil?

Builtins.substring(input, pos1, Ops.add(Ops.subtract(pos2, pos1), 1))
input.sub(/\A[ \t]*(.*[^ \t])[ \t]*\z/, "\\1")
end

# Remove any leading zeros
Expand Down

0 comments on commit 14f5907

Please sign in to comment.