mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
39 lines
749 B
Ruby
39 lines
749 B
Ruby
class String
|
|
def lstrip
|
|
a = 0
|
|
z = self.size - 1
|
|
a += 1 while " \f\n\r\t\v".include?(self[a]) and a <= z
|
|
(z >= 0) ? self[a..z] : ""
|
|
end
|
|
|
|
def rstrip
|
|
a = 0
|
|
z = self.size - 1
|
|
z -= 1 while " \f\n\r\t\v\0".include?(self[z]) and a <= z
|
|
(z >= 0) ? self[a..z] : ""
|
|
end
|
|
|
|
def strip
|
|
a = 0
|
|
z = self.size - 1
|
|
a += 1 while " \f\n\r\t\v".include?(self[a]) and a <= z
|
|
z -= 1 while " \f\n\r\t\v\0".include?(self[z]) and a <= z
|
|
(z >= 0) ? self[a..z] : ""
|
|
end
|
|
|
|
def lstrip!
|
|
s = self.lstrip
|
|
(s == self) ? nil : self.replace(s)
|
|
end
|
|
|
|
def rstrip!
|
|
s = self.rstrip
|
|
(s == self) ? nil : self.replace(s)
|
|
end
|
|
|
|
def strip!
|
|
s = self.strip
|
|
(s == self) ? nil : self.replace(s)
|
|
end
|
|
end
|