diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-04 16:30:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-04 16:30:33 +0000 |
commit | 8638ee26e704cb9b2e40bcbced713d459a374b1f (patch) | |
tree | fb26b1bc5985fead18bfe5ea1e59f6c8bb1a4e32 /re.c | |
parent | 91f9acdfeee3cf4340988193bd1fa6ad1834789f (diff) | |
download | ruby-8638ee26e704cb9b2e40bcbced713d459a374b1f.tar.gz |
* include/ruby/intern.h, re.c (rb_reg_new): keep interface same as
1.8. [ruby-core:14583]
* include/ruby/intern.h, re.c (rb_reg_new_str): renamed, and defines
HAVE_RB_REG_NEW_STR macro to tell if it is available.
* include/ruby/encoding.h (rb_enc_reg_new): added.
* insns.def (toregexp), marshal.c (r_object0): use rb_reg_new_str().
* re.c (rb_reg_regcomp, rb_reg_s_union): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 44 |
1 files changed, 38 insertions, 6 deletions
@@ -460,14 +460,14 @@ rb_reg_raise(const char *s, long len, const char *err, VALUE re) } static VALUE -rb_reg_error_desc(VALUE str, int options, const char *err) +rb_enc_reg_error_desc(const char *s, long len, rb_encoding *enc, int options, const char *err) { char opts[6]; VALUE desc = rb_str_buf_new2(err); - rb_enc_copy(desc, str); + rb_enc_associate(desc, enc); rb_str_buf_cat2(desc, ": /"); - rb_reg_expr_str(desc, RSTRING_PTR(str), RSTRING_LEN(str)); + rb_reg_expr_str(desc, s, len); opts[0] = '/'; option_to_str(opts + 1, options); rb_str_buf_cat2(desc, opts); @@ -475,6 +475,19 @@ rb_reg_error_desc(VALUE str, int options, const char *err) } static void +rb_enc_reg_raise(const char *s, long len, rb_encoding *enc, int options, const char *err) +{ + rb_exc_raise(rb_enc_reg_error_desc(s, len, enc, options, err)); +} + +static VALUE +rb_reg_error_desc(VALUE str, int options, const char *err) +{ + return rb_enc_reg_error_desc(RSTRING_PTR(str), RSTRING_LEN(str), + rb_enc_get(str), options, err); +} + +static void rb_reg_raise_str(VALUE str, int options, const char *err) { rb_exc_raise(rb_reg_error_desc(str, options, err)); @@ -2040,7 +2053,7 @@ rb_reg_s_alloc(VALUE klass) } VALUE -rb_reg_new(VALUE s, int options) +rb_reg_new_str(VALUE s, int options) { VALUE re = rb_reg_s_alloc(rb_cRegexp); onig_errmsg_buffer err; @@ -2053,6 +2066,25 @@ rb_reg_new(VALUE s, int options) } VALUE +rb_enc_reg_new(const char *s, long len, rb_encoding *enc, int options) +{ + VALUE re = rb_reg_s_alloc(rb_cRegexp); + onig_errmsg_buffer err; + + if (rb_reg_initialize(re, s, len, enc, options, err) != 0) { + rb_enc_reg_raise(s, len, enc, options, err); + } + + return re; +} + +VALUE +rb_reg_new(const char *s, long len, int options) +{ + return rb_enc_reg_new(s, len, rb_ascii8bit_encoding(), options); +} + +VALUE rb_reg_compile(VALUE str, int options) { VALUE re = rb_reg_s_alloc(rb_cRegexp); @@ -2078,7 +2110,7 @@ rb_reg_regcomp(VALUE str) && memcmp(RREGEXP(reg_cache)->str, RSTRING_PTR(str), RSTRING_LEN(str)) == 0) return reg_cache; - return reg_cache = rb_reg_new(save_str, 0); + return reg_cache = rb_reg_new_str(save_str, 0); } /* @@ -2607,7 +2639,7 @@ rb_reg_s_union(VALUE self, VALUE args0) else { VALUE quoted; quoted = rb_reg_s_quote(Qnil, arg); - return rb_reg_new(quoted, 0); + return rb_reg_new_str(quoted, 0); } } else { |