Commit b783311e authored by Yukihiro Matz Matsumoto's avatar Yukihiro Matz Matsumoto

Merge branch 'master' of github.com:mruby/mruby

parents 318ad9c8 3c5bf780
......@@ -26,6 +26,9 @@ MRuby::Build.new do |conf|
# Use extensional String class
conf.gem 'mrbgems/mruby-string-ext'
# Use extensional Numeric class
conf.gem 'mrbgems/mruby-numeric-ext'
# Generate binaries
# conf.bins = %w(mrbc mruby mirb)
......
MRuby::Gem::Specification.new('mruby-numeric-ext') do |spec|
spec.license = 'MIT'
spec.authors = 'mruby developers'
end
#include "mruby.h"
#include "mruby/numeric.h"
static mrb_value
mrb_int_chr(mrb_state *mrb, mrb_value x)
{
mrb_int chr;
char c;
chr = mrb_fixnum(x);
if (chr >= (1 << CHAR_BIT)) {
mrb_raisef(mrb, E_RANGE_ERROR, "%ld out of char range", chr);
}
c = (char)chr;
return mrb_str_new(mrb, &c, 1);
}
void
mrb_mruby_numeric_ext_gem_init(mrb_state* mrb)
{
struct RClass *i = mrb_class_get(mrb, "Integer");
mrb_define_method(mrb, i, "chr", mrb_int_chr, ARGS_NONE());
}
void
mrb_mruby_numeric_ext_gem_final(mrb_state* mrb)
{
}
##
# Numeric(Ext) Test
assert('Integer#chr') do
assert_equal(65.chr, "A")
assert_equal(0x42.chr, "B")
# multibyte encoding (not support yet)
assert_raise(RangeError) { 12345.chr }
end
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
......@@ -16,3 +16,57 @@ end
assert('String#dump') do
"foo".dump == "\"foo\""
end
assert('String#strip') do
s = " abc "
s.strip
"".strip == "" and " \t\r\n\f\v".strip == "" and
"\0a\0".strip == "\0a" and
"abc".strip == "abc" and
" abc".strip == "abc" and
"abc ".strip == "abc" and
" abc ".strip == "abc" and
s == " abc "
end
assert('String#lstrip') do
s = " abc "
s.lstrip
"".lstrip == "" and " \t\r\n\f\v".lstrip == "" and
"\0a\0".lstrip == "\0a\0" and
"abc".lstrip == "abc" and
" abc".lstrip == "abc" and
"abc ".lstrip == "abc " and
" abc ".lstrip == "abc " and
s == " abc "
end
assert('String#rstrip') do
s = " abc "
s.rstrip
"".rstrip == "" and " \t\r\n\f\v".rstrip == "" and
"\0a\0".rstrip == "\0a" and
"abc".rstrip == "abc" and
" abc".rstrip == " abc" and
"abc ".rstrip == "abc" and
" abc ".rstrip == " abc" and
s == " abc "
end
assert('String#strip!') do
s = " abc "
t = "abc"
s.strip! == "abc" and s == "abc" and t.strip! == nil
end
assert('String#lstrip!') do
s = " abc "
t = "abc "
s.lstrip! == "abc " and s == "abc " and t.lstrip! == nil
end
assert('String#rstrip!') do
s = " abc "
t = " abc"
s.rstrip! == " abc" and s == " abc" and t.rstrip! == nil
end
......@@ -69,9 +69,9 @@ module MRuby
@out_ext = build.exts.object
if build_dir.include? "mrbgems/"
generated_file_matcher = Regexp.new("^#{build_dir}/(.*)#{Regexp.escape out_ext}$")
generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(.*)#{Regexp.escape out_ext}$")
else
generated_file_matcher = Regexp.new("^#{build_dir}/(?!mrbgems/.+/)(.*)#{Regexp.escape out_ext}$")
generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(?!mrbgems/.+/)(.*)#{Regexp.escape out_ext}$")
end
source_exts.each do |ext, compile|
rule generated_file_matcher => [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment