From fd640aec82f65134d589d9603d0ed669e90ebb60 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 27 Dec 2007 07:38:23 +0000 Subject: [PATCH] * re.c (rb_reg_s_union): show encodings in error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ re.c | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c4fab6d80c..6ba45bed6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Dec 27 16:37:06 2007 Tanaka Akira + + * re.c (rb_reg_s_union): show encodings in error message. + Thu Dec 27 15:25:16 2007 Tanaka Akira * encoding.c (rb_enc_codelen): show codepoint in error message. diff --git a/re.c b/re.c index dcbc234602..eae1ebd05b 100644 --- a/re.c +++ b/re.c @@ -2631,13 +2631,15 @@ rb_reg_s_union(VALUE self, VALUE args0) if (!has_ascii_incompat) has_ascii_incompat = enc; else if (has_ascii_incompat != enc) - rb_raise(rb_eArgError, "regexp encodings differ"); + rb_raise(rb_eArgError, "incompatible encodings: %s and %s", + rb_enc_name(has_ascii_incompat), rb_enc_name(enc)); } 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"); + rb_raise(rb_eArgError, "incompatible encodings: %s and %s", + rb_enc_name(has_ascii_compat_fixed), rb_enc_name(enc)); } else { has_asciionly = 1; @@ -2652,7 +2654,8 @@ rb_reg_s_union(VALUE self, VALUE args0) if (!has_ascii_incompat) has_ascii_incompat = enc; else if (has_ascii_incompat != enc) - rb_raise(rb_eArgError, "regexp encodings differ"); + rb_raise(rb_eArgError, "incompatible encodings: %s and %s", + rb_enc_name(has_ascii_incompat), rb_enc_name(enc)); } else if (rb_enc_str_asciionly_p(e)) { has_asciionly = 1; @@ -2661,12 +2664,20 @@ rb_reg_s_union(VALUE self, VALUE args0) if (!has_ascii_compat_fixed) has_ascii_compat_fixed = enc; else if (has_ascii_compat_fixed != enc) - rb_raise(rb_eArgError, "regexp encodings differ"); + rb_raise(rb_eArgError, "incompatible encodings: %s and %s", + rb_enc_name(has_ascii_compat_fixed), rb_enc_name(enc)); } v = rb_reg_s_quote(Qnil, e); } - if (has_ascii_incompat && (has_asciionly || has_ascii_compat_fixed)) { - rb_raise(rb_eArgError, "regexp encodings differ"); + if (has_ascii_incompat) { + if (has_asciionly) { + rb_raise(rb_eArgError, "ASCII incompatible encoding: %s", + rb_enc_name(has_ascii_incompat)); + } + if (has_ascii_compat_fixed) { + rb_raise(rb_eArgError, "incompatible encodings: %s and %s", + rb_enc_name(has_ascii_incompat), rb_enc_name(has_ascii_compat_fixed)); + } } rb_str_append(source, v);