diff options
| author | Tomoyuki Sahara <[email protected]> | 2013-03-08 09:45:04 +0900 |
|---|---|---|
| committer | Tomoyuki Sahara <[email protected]> | 2013-03-08 09:45:04 +0900 |
| commit | 11edea38804e2a7021c27e9d905bb001f3fce156 (patch) | |
| tree | a40a2142bbf8ae8ae99e7b13e6b60c619bbd6fea /mrbgems/mruby-string-ext/mrblib | |
| parent | aa73a1068f2fd5cbff7e4623ab2036d360933ff9 (diff) | |
| download | mruby-11edea38804e2a7021c27e9d905bb001f3fce156.tar.gz mruby-11edea38804e2a7021c27e9d905bb001f3fce156.zip | |
add "strip" family to String.
Diffstat (limited to 'mrbgems/mruby-string-ext/mrblib')
| -rw-r--r-- | mrbgems/mruby-string-ext/mrblib/string.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb new file mode 100644 index 000000000..142a63882 --- /dev/null +++ b/mrbgems/mruby-string-ext/mrblib/string.rb @@ -0,0 +1,38 @@ +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 |
