diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-29 08:03:51 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-29 08:03:51 +0000 |
commit | d5c8ad535961968b40823512ccdb12e38f1ed529 (patch) | |
tree | ec9fda92b59a605bc0a836f625a71e871a23a6a7 /re.c | |
parent | 65615986ec0cfc5971c990abe46643b0edbcab8d (diff) |
* insns.def (toregexp): generate a regexp from strings instead of one
string.
* re.c (rb_reg_new_ary): defined for toregexp. it concatenates
strings after each string is preprocessed.
* compile.c (compile_dstr_fragments): split from compile_dstr.
(compile_dstr): call compile_dstr_fragments.
(compile_dregx): defined for dynamic regexp.
(iseq_compile_each): use compile_dregx for dynamic regexp.
[ruby-dev:33400]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 75 |
1 files changed, 47 insertions, 28 deletions
@@ -1949,36 +1949,53 @@ rb_reg_check_preprocess(VALUE str) return Qnil; } -#if 0 static VALUE -rb_reg_preprocess_obj(VALUE str, - rb_encoding **fixed_enc, onig_errmsg_buffer err) +rb_reg_preprocess_dregexp(VALUE ary) { - VALUE buf; - char *p, *end; - rb_encoding *enc; + rb_encoding *fixed_enc = 0; + onig_errmsg_buffer err = ""; + int i; + VALUE result = 0; + int argc = RARRAY_LEN(ary); + VALUE *argv = RARRAY_PTR(ary); - StringValue(str); - p = RSTRING_PTR(str); - end = p + RSTRING_LEN(str); - enc = rb_enc_get(str); + if (argc == 0) { + rb_raise(rb_eArgError, "no arguments given"); + } - buf = rb_reg_preprocess(p, end, enc, fixed_enc, err); - RB_GC_GUARD(str); - return buf; -} + for (i = 0; i < argc; i++) { + VALUE str = argv[i]; + VALUE buf; + char *p, *end; + rb_encoding *enc; -static VALUE -rb_reg_preprocess_m(VALUE klass, VALUE obj) -{ - rb_encoding *fixed_enc = 0; - onig_errmsg_buffer err = ""; - VALUE str = rb_reg_preprocess_obj(obj, &fixed_enc, err); - if (str == Qnil) - rb_raise(rb_eArgError, "%s", err); - return rb_assoc_new(str, fixed_enc ? Qtrue : Qfalse); + StringValue(str); + p = RSTRING_PTR(str); + end = p + RSTRING_LEN(str); + enc = rb_enc_get(str); + + buf = rb_reg_preprocess(p, end, enc, &fixed_enc, err); + RB_GC_GUARD(str); + + if (buf == Qnil) + rb_raise(rb_eArgError, "%s", err); + + if (i == 0) { + /* The encoding of the first fragment is the encoding + * given by the regexp option or script encoding. */ + if (fixed_enc == 0) { + rb_enc_copy(buf, str); + } + } + + if (!result) + result = buf; + else + rb_str_buf_append(result, buf); + } + + return result; } -#endif static int rb_reg_initialize(VALUE obj, const char *s, int len, rb_encoding *enc, @@ -2085,6 +2102,12 @@ rb_reg_new_str(VALUE s, int options) } VALUE +rb_reg_new_ary(VALUE ary, int opt) +{ + return rb_reg_new_str(rb_reg_preprocess_dregexp(ary), opt); +} + +VALUE rb_enc_reg_new(const char *s, long len, rb_encoding *enc, int options) { VALUE re = rb_reg_s_alloc(rb_cRegexp); @@ -3042,10 +3065,6 @@ Init_Regexp(void) rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1); rb_define_singleton_method(rb_cRegexp, "try_convert", rb_reg_s_try_convert, 1); -#if 0 - rb_define_singleton_method(rb_cRegexp, "preprocess", rb_reg_preprocess_m, 1); -#endif - rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1); rb_define_method(rb_cRegexp, "initialize_copy", rb_reg_init_copy, 1); rb_define_method(rb_cRegexp, "hash", rb_reg_hash, 0); |