ruby-changes:2527
From: ko1@a...
Date: 26 Nov 2007 11:28:23 +0900
Subject: [ruby-changes:2527] akr - Ruby:r14018 (trunk): * re.c (rb_reg_fixed_encoding_p): extracted from rb_reg_prepare_re and
akr 2007-11-26 11:27:59 +0900 (Mon, 26 Nov 2007)
New Revision: 14018
Modified files:
trunk/ChangeLog
trunk/re.c
Log:
* re.c (rb_reg_fixed_encoding_p): extracted from rb_reg_prepare_re and
rb_reg_s_union.
(rb_reg_s_union): refactored.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14018&r2=14017
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=14018&r2=14017
Index: re.c
===================================================================
--- re.c (revision 14017)
+++ re.c (revision 14018)
@@ -706,6 +706,15 @@
FL_SET(match, MATCH_BUSY);
}
+static VALUE
+rb_reg_fixed_encoding_p(VALUE re)
+{
+ if (ENCODING_GET(re) != 0 || FL_TEST(re, KCODE_FIXED))
+ return Qtrue;
+ else
+ return Qfalse;
+}
+
static void
rb_reg_prepare_re(VALUE re, VALUE str)
{
@@ -714,7 +723,7 @@
rb_reg_check(re);
/* ignorecase status */
- if (ENCODING_GET(re) != 0 || FL_TEST(re, KCODE_FIXED)) {
+ if (rb_reg_fixed_encoding_p(re)) {
if (ENCODING_GET(re) != rb_enc_get_index(str) &&
rb_enc_str_coderange(str) != ENC_CODERANGE_SINGLE) {
rb_raise(rb_eArgError, "character encodings differ");
@@ -1822,16 +1831,12 @@
else {
int i;
VALUE source = rb_str_buf_new(0);
- rb_encoding *enc;
+ rb_encoding *result_enc;
- int has_asciionly_string = 0;
- rb_encoding *has_ascii_compat_string = 0;
- rb_encoding *has_ascii_incompat_string = 0;
+ int has_asciionly = 0;
+ rb_encoding *has_ascii_compat_fixed = 0;
+ rb_encoding *has_ascii_incompat = 0;
- int has_generic_regexp = 0;
- rb_encoding *has_ascii_compat_fixed_regexp = 0;
- rb_encoding *has_ascii_incompat_regexp = 0;
-
for (i = 0; i < argc; i++) {
volatile VALUE v;
VALUE e = rb_ary_entry(args0, i);
@@ -1841,83 +1846,63 @@
v = rb_check_regexp_type(e);
if (!NIL_P(v)) {
- rb_encoding *enc0 = rb_enc_get(v);
- if (!rb_enc_asciicompat(enc0)) {
- if (!has_ascii_incompat_regexp) {
- has_ascii_incompat_regexp = enc0;
- }
- else {
- if (has_ascii_incompat_regexp != enc0)
- rb_raise(rb_eArgError, "regexp encodings differ");
- }
+ rb_encoding *enc = rb_enc_get(v);
+ if (!rb_enc_asciicompat(enc)) {
+ if (!has_ascii_incompat)
+ has_ascii_incompat = enc;
+ else if (has_ascii_incompat != enc)
+ rb_raise(rb_eArgError, "regexp encodings differ");
}
- else if (ENCODING_GET(v) != 0 || FL_TEST(v, KCODE_FIXED)) {
- if (!has_ascii_compat_fixed_regexp) {
- has_ascii_compat_fixed_regexp = enc0;
- }
- else {
- if (has_ascii_compat_fixed_regexp != enc0)
- rb_raise(rb_eArgError, "regexp encodings differ");
- }
+ else if (rb_reg_fixed_encoding_p(v)) {
+ if (!has_ascii_compat_fixed)
+ has_ascii_compat_fixed = enc;
+ else if (has_ascii_compat_fixed != enc)
+ rb_raise(rb_eArgError, "regexp encodings differ");
}
else {
- has_generic_regexp = 1;
+ has_asciionly = 1;
}
v = rb_reg_to_s(v);
}
else {
+ rb_encoding *enc = rb_enc_get(e);
StringValue(e);
+ enc = rb_enc_get(e);
if (!rb_enc_str_asciicompat_p(e)) {
- rb_encoding *enc0 = rb_enc_get(e);
- if (!has_ascii_incompat_string) {
- has_ascii_incompat_string = enc0;
- }
- else {
- if (has_ascii_incompat_string != enc0)
- rb_raise(rb_eArgError, "regexp encodings differ");
- }
+ if (!has_ascii_incompat)
+ has_ascii_incompat = enc;
+ else if (has_ascii_incompat != enc)
+ rb_raise(rb_eArgError, "regexp encodings differ");
}
else if (rb_enc_str_asciionly_p(e)) {
- has_asciionly_string = 1;
+ has_asciionly = 1;
}
else {
- rb_encoding *enc0 = rb_enc_get(e);
- if (!has_ascii_compat_string) {
- has_ascii_compat_string = enc0;
- }
- else {
- if (has_ascii_compat_string != enc0)
- rb_raise(rb_eArgError, "regexp encodings differ");
- }
+ if (!has_ascii_compat_fixed)
+ has_ascii_compat_fixed = enc;
+ else if (has_ascii_compat_fixed != enc)
+ rb_raise(rb_eArgError, "regexp encodings differ");
}
v = rb_reg_s_quote(Qnil, e);
}
+ if (has_ascii_incompat && (has_asciionly || has_ascii_compat_fixed)) {
+ rb_raise(rb_eArgError, "regexp encodings differ");
+ }
+
rb_str_append(source, v);
}
- if (has_ascii_incompat_string || has_ascii_incompat_regexp) {
- if (has_asciionly_string || has_ascii_compat_string ||
- has_generic_regexp || has_ascii_compat_fixed_regexp)
- rb_raise(rb_eArgError, "regexp encodings differ");
- if (has_ascii_incompat_string && has_ascii_incompat_regexp &&
- has_ascii_incompat_string != has_ascii_incompat_regexp)
- rb_raise(rb_eArgError, "regexp encodings differ");
- enc = has_ascii_incompat_string;
- if (enc == 0)
- enc = has_ascii_incompat_regexp;
+
+ if (has_ascii_incompat) {
+ result_enc = has_ascii_incompat;
}
- else if (has_ascii_compat_string || has_ascii_compat_fixed_regexp) {
- if (has_ascii_compat_string && has_ascii_compat_fixed_regexp &&
- has_ascii_compat_string != has_ascii_compat_fixed_regexp)
- rb_raise(rb_eArgError, "regexp encodings differ");
- enc = has_ascii_compat_string;
- if (enc == 0)
- enc = has_ascii_compat_fixed_regexp;
+ else if (has_ascii_compat_fixed) {
+ result_enc = has_ascii_compat_fixed;
}
else {
- enc = rb_enc_from_index(0);
+ result_enc = rb_enc_from_index(0);
}
- rb_enc_associate(source, enc);
+ rb_enc_associate(source, result_enc);
return rb_class_new_instance(1, &source, rb_cRegexp);
}
}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 14017)
+++ ChangeLog (revision 14018)
@@ -1,3 +1,9 @@
+Mon Nov 26 11:24:04 2007 Tanaka Akira <akr@f...>
+
+ * re.c (rb_reg_fixed_encoding_p): extracted from rb_reg_prepare_re and
+ rb_reg_s_union.
+ (rb_reg_s_union): refactored.
+
Mon Nov 26 10:44:20 2007 Nobuyoshi Nakada <nobu@r...>
* io.c (rb_read_internal, rb_sysopen_internal): remove C99 dependency.
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml