Commit 3046cc7b authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

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

parents c150f115 2040347d
......@@ -8,21 +8,17 @@
#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include "mruby.h"
#include "mruby/array.h"
#include <mruby/proc.h>
#include <mruby/data.h>
#include <mruby/compile.h>
#include "mruby/proc.h"
#include "mruby/compile.h"
#include "mruby/string.h"
#ifdef ENABLE_READLINE
#include <limits.h>
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include <mruby/string.h>
#ifdef ENABLE_READLINE
static const char *history_file_name = ".mirb_history";
char history_path[PATH_MAX];
#endif
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
#include "mruby/proc.h"
#include "mruby/array.h"
#include "mruby/string.h"
#include "mruby/compile.h"
#include "mruby/dump.h"
#include "mruby/variable.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef ENABLE_STDIO
static void
......
......@@ -6,11 +6,8 @@
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/hash.h"
#include "mruby/khash.h"
#include "mruby/string.h"
#include "mruby/variable.h"
/*
* call-seq:
......
#include <limits.h>
#include "mruby.h"
#include "mruby/numeric.h"
static mrb_value
mrb_int_chr(mrb_state *mrb, mrb_value x)
......
......@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
#include <stdio.h>
#include "mt19937ar.h"
/* Period parameters */
......
#include "mruby.h"
#include "mruby/string.h"
#include <ctype.h>
#include <string.h>
#include "mruby.h"
#include "mruby/string.h"
static mrb_value
mrb_str_getbyte(mrb_state *mrb, mrb_value str)
......
......@@ -247,6 +247,38 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str)
return mrb_str_aref(mrb, str, a1);
}
static mrb_value
mrb_str_reverse_bang(mrb_state *mrb, mrb_value str)
{
int utf8_len = mrb_utf8_strlen(str);
if (utf8_len > 1) {
int len = RSTRING_LEN(str);
char *buf = (char *)mrb_malloc(mrb, len);
unsigned char* p = (unsigned char*)buf;
unsigned char* e = (unsigned char*)buf + len;
unsigned char* r = (unsigned char*)RSTRING_END(str);
memcpy(buf, RSTRING_PTR(str), len);
mrb_str_modify(mrb, mrb_str_ptr(str));
while (p<e) {
int clen = utf8len(p);
r -= clen;
memcpy(r, p, clen);
p += clen;
}
mrb_free(mrb, buf);
}
return str;
}
static mrb_value
mrb_str_reverse(mrb_state *mrb, mrb_value str)
{
return mrb_str_reverse_bang(mrb, mrb_str_dup(mrb, str));
}
void
mrb_mruby_string_utf8_gem_init(mrb_state* mrb)
{
......@@ -255,6 +287,8 @@ mrb_mruby_string_utf8_gem_init(mrb_state* mrb)
mrb_define_method(mrb, s, "size", mrb_str_size, MRB_ARGS_NONE());
mrb_define_method(mrb, s, "[]", mrb_str_aref_m, MRB_ARGS_ANY());
mrb_define_method(mrb, s, "slice", mrb_str_aref_m, MRB_ARGS_ANY());
mrb_define_method(mrb, s, "reverse", mrb_str_reverse, MRB_ARGS_NONE());
mrb_define_method(mrb, s, "reverse!", mrb_str_reverse_bang, MRB_ARGS_NONE());
}
void
......
......@@ -9,3 +9,19 @@ assert('String#[]') do
assert_equal "んに", "こんにちわ世界"[1,2]
assert_equal "世", "こんにちわ世界"["世"]
end
assert('String#reverse', '15.2.10.5.29') do
a = 'こんにちわ世界!'
a.reverse
assert_equal 'こんにちわ世界!', a
assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse
end
assert('String#reverse!', '15.2.10.5.30') do
a = 'こんにちわ世界!'
a.reverse!
assert_equal '!界世わちにんこ', a
assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse!
end
......@@ -10,7 +10,6 @@
#include "mruby/array.h"
#include "mruby/string.h"
#include "mruby/class.h"
#include "mruby/data.h"
#include "mruby/variable.h"
#define RSTRUCT_ARY(st) mrb_ary_ptr(st)
......
#include "mruby.h"
#include "mruby/irep.h"
#include "mruby/dump.h"
#include "mruby/string.h"
#include "mruby/proc.h"
extern const uint8_t mrblib_irep[];
......
......@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
#include <limits.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
......
......@@ -4,6 +4,7 @@
** See Copyright Notice in mruby.h
*/
#include <stdarg.h>
#include "mruby.h"
#include "mruby/variable.h"
#include "mruby/proc.h"
......@@ -11,7 +12,6 @@
#include "mruby/string.h"
#include "mruby/class.h"
#include "mruby/debug.h"
#include <stdarg.h>
typedef void (*output_stream_func)(mrb_state*, void*, int, const char*, ...);
......
......@@ -4,9 +4,9 @@
** See Copyright Notice in mruby.h
*/
#include "mruby.h"
#include <stdarg.h>
#include <ctype.h>
#include <stdarg.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/numeric.h"
......
......@@ -4,10 +4,9 @@
** See Copyright Notice in mruby.h
*/
#include <ctype.h>
#include <string.h>
#include "mruby/dump.h"
#include <ctype.h>
#include "mruby/string.h"
#include "mruby/irep.h"
#include "mruby/numeric.h"
......
......@@ -7,10 +7,8 @@
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/irep.h"
#include "mruby/proc.h"
#include "mruby/string.h"
......
......@@ -6,8 +6,6 @@
#include "mruby.h"
#include "mruby/string.h"
#include "error.h"
#include "mruby/numeric.h"
#include "mruby/data.h"
#include "mruby/class.h"
......
......@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include "mruby.h"
......
......@@ -5,11 +5,9 @@
*/
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/numeric.h"
#include "mruby/string.h"
#include "error.h"
mrb_bool
mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2)
......
......@@ -7,7 +7,6 @@
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
#include "mruby/class.h"
#include "mruby/irep.h"
#include "mruby/variable.h"
#include "mruby/debug.h"
......
......@@ -107,16 +107,6 @@ mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len)
return str;
}
static inline void
str_mod_check(mrb_state *mrb, mrb_value str, char *p, mrb_int len)
{
struct RString *s = mrb_str_ptr(str);
if (s->ptr != p || s->len != len) {
mrb_raise(mrb, E_RUNTIME_ERROR, "string modified");
}
}
#define mrb_obj_alloc_string(mrb) ((struct RString*)mrb_obj_alloc((mrb), MRB_TT_STRING, (mrb)->string_class))
/* char offset to byte offset */
......
......@@ -5,7 +5,6 @@
*/
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include "mruby.h"
#include "mruby/khash.h"
......
......@@ -4,14 +4,12 @@
** See Copyright Notice in mruby.h
*/
#include <ctype.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/proc.h"
#include "mruby/string.h"
#include "mruby/variable.h"
#include "error.h"
#include <ctype.h>
typedef int (iv_foreach_func)(mrb_state*,mrb_sym,mrb_value,void*);
......
......@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
#include <string.h>
#include <setjmp.h>
#include <stddef.h>
#include <stdarg.h>
......@@ -13,7 +12,6 @@
#include "mruby/class.h"
#include "mruby/hash.h"
#include "mruby/irep.h"
#include "mruby/numeric.h"
#include "mruby/proc.h"
#include "mruby/range.h"
#include "mruby/string.h"
......
......@@ -149,7 +149,7 @@ module MRuby
end
end # generate_gem_init
def print_gem_init_header(f)
def print_gem_comment(f)
f.puts %Q[/*]
f.puts %Q[ * This file is loading the irep]
f.puts %Q[ * Ruby GEM code.]
......@@ -158,15 +158,23 @@ module MRuby
f.puts %Q[ * This file was generated!]
f.puts %Q[ * All manual changes will get lost.]
f.puts %Q[ */]
end
def print_gem_init_header(f)
print_gem_comment(f)
f.puts %Q[#include <stdlib.h>] unless rbfiles.empty?
f.puts %Q[#include "mruby.h"]
f.puts %Q[#include "mruby/irep.h"] unless rbfiles.empty?
end
def print_gem_test_header(f)
print_gem_comment(f)
f.puts %Q[#include <stdlib.h>]
f.puts %Q[#include "mruby.h"]
f.puts %Q[#include "mruby/array.h"]
f.puts %Q[#include "mruby/irep.h"]
f.puts %Q[#include "mruby/dump.h"]
f.puts %Q[#include "mruby/string.h"]
f.puts %Q[#include "mruby/proc.h"]
f.puts %Q[#include "mruby/variable.h"]
f.puts %Q[#include "mruby/array.h"]
f.puts %Q[#include "mruby/hash.h"]
end
def version_ok?(req_versions)
......
......@@ -5,7 +5,7 @@ MRuby.each_target do
file test_rbobj => g.test_rbireps
file g.test_rbireps => [g.test_rbfiles].flatten + [g.build.mrbcfile] do |t|
open(t.name, 'w') do |f|
g.print_gem_init_header(f)
g.print_gem_test_header(f)
test_preload = [g.dir, MRUBY_ROOT].map {|dir|
File.expand_path(g.test_preload, dir)
}.find {|file| File.exist?(file) }
......
#include <stdlib.h>
#include "mruby.h"
#include "mruby/irep.h"
#include "mruby/dump.h"
#include "mruby/string.h"
#include "mruby/proc.h"
extern const uint8_t mrbtest_irep[];
......
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