diff options
| author | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-09 00:39:45 +0900 |
|---|---|---|
| committer | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-09 00:39:45 +0900 |
| commit | b783311ec442d4b27f67ecb287c413cac36df147 (patch) | |
| tree | 8f90cb67e53f2b949cd62b515dce981806f6a2e9 /mrbgems/mruby-string-ext/mrblib/string.rb | |
| parent | 318ad9c802d010b398a9683407716b5c7ef32b00 (diff) | |
| parent | 3c5bf780e4a3dcd2e73edd2475140ce0c2a46268 (diff) | |
| download | mruby-b783311ec442d4b27f67ecb287c413cac36df147.tar.gz mruby-b783311ec442d4b27f67ecb287c413cac36df147.zip | |
Merge branch 'master' of github.com:mruby/mruby
Diffstat (limited to 'mrbgems/mruby-string-ext/mrblib/string.rb')
| -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 |
