mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* error.c (rb_eEncCompatError): add Exception.
* include/ruby/ruby.h: ditto. * encoding.c (rb_enc_check): use rb_eEncCompatError. * string.c (rb_enc_cr_str_buf_cat): ditto. * string.c (rb_str_sub_bang): ditto. * string.c (rb_str_hex): ditto. * string.c (rb_str_oct): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fc6484cbf4
commit
85c41f4fbc
6 changed files with 63 additions and 44 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Wed Aug 13 02:46:01 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* error.c (rb_eEncCompatError): add Exception.
|
||||
|
||||
* include/ruby/ruby.h: ditto.
|
||||
|
||||
* encoding.c (rb_enc_check): use rb_eEncCompatError.
|
||||
|
||||
* string.c (rb_enc_cr_str_buf_cat): ditto.
|
||||
|
||||
* string.c (rb_str_sub_bang): ditto.
|
||||
|
||||
* string.c (rb_str_hex): ditto.
|
||||
|
||||
* string.c (rb_str_oct): ditto.
|
||||
|
||||
Wed Aug 13 02:36:47 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* transcode.c (str_transcode): fix error message.
|
||||
|
|
|
@ -600,7 +600,7 @@ rb_enc_check(VALUE str1, VALUE str2)
|
|||
{
|
||||
rb_encoding *enc = rb_enc_compatible(str1, str2);
|
||||
if (!enc)
|
||||
rb_raise(rb_eArgError, "character encodings differ: %s and %s",
|
||||
rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
|
||||
rb_enc_name(rb_enc_get(str1)),
|
||||
rb_enc_name(rb_enc_get(str2)));
|
||||
return enc;
|
||||
|
@ -743,7 +743,7 @@ rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc)
|
|||
if (MBCLEN_CHARFOUND_P(r))
|
||||
return rb_enc_mbc_to_codepoint(p, e, enc);
|
||||
else
|
||||
rb_raise(rb_eArgError, "invalid mbstring sequence");
|
||||
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc));
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -751,7 +751,7 @@ rb_enc_codelen(int c, rb_encoding *enc)
|
|||
{
|
||||
int n = ONIGENC_CODE_TO_MBCLEN(enc,c);
|
||||
if (n == 0) {
|
||||
rb_raise(rb_eArgError, "invalid codepoint 0x%x", c);
|
||||
rb_raise(rb_eArgError, "invalid codepoint 0x%x in %s", c, rb_enc_name(enc));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
|
2
error.c
2
error.c
|
@ -328,6 +328,7 @@ VALUE rb_eSecurityError;
|
|||
VALUE rb_eNotImpError;
|
||||
VALUE rb_eNoMemError;
|
||||
VALUE rb_cNameErrorMesg;
|
||||
VALUE rb_eEncCompatError;
|
||||
|
||||
VALUE rb_eScriptError;
|
||||
VALUE rb_eSyntaxError;
|
||||
|
@ -1032,6 +1033,7 @@ Init_Exception(void)
|
|||
rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
|
||||
rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
|
||||
rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
|
||||
rb_eEncCompatError = rb_define_class("EncodingCompatibilityError", rb_eStandardError);
|
||||
|
||||
rb_eScriptError = rb_define_class("ScriptError", rb_eException);
|
||||
rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
|
||||
|
|
|
@ -958,6 +958,7 @@ RUBY_EXTERN VALUE rb_eFloatDomainError;
|
|||
RUBY_EXTERN VALUE rb_eLocalJumpError;
|
||||
RUBY_EXTERN VALUE rb_eSysStackError;
|
||||
RUBY_EXTERN VALUE rb_eRegexpError;
|
||||
RUBY_EXTERN VALUE rb_eEncCompatError;
|
||||
|
||||
RUBY_EXTERN VALUE rb_eScriptError;
|
||||
RUBY_EXTERN VALUE rb_eNameError;
|
||||
|
|
8
string.c
8
string.c
|
@ -1575,7 +1575,7 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len,
|
|||
str_cr != ENC_CODERANGE_7BIT &&
|
||||
ptr_cr != ENC_CODERANGE_7BIT) {
|
||||
incompatible:
|
||||
rb_raise(rb_eArgError, "append incompatible encoding strings: %s and %s",
|
||||
rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
|
||||
rb_enc_name(rb_enc_from_index(str_encindex)),
|
||||
rb_enc_name(rb_enc_from_index(ptr_encindex)));
|
||||
}
|
||||
|
@ -3218,7 +3218,7 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
|
|||
if (coderange_scan(RSTRING_PTR(str), beg0, str_enc) != ENC_CODERANGE_7BIT ||
|
||||
coderange_scan(RSTRING_PTR(str)+end0,
|
||||
RSTRING_LEN(str)-end0, str_enc) != ENC_CODERANGE_7BIT) {
|
||||
rb_raise(rb_eArgError, "character encodings differ: %s and %s",
|
||||
rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
|
||||
rb_enc_name(str_enc),
|
||||
rb_enc_name(STR_ENC_GET(repl)));
|
||||
}
|
||||
|
@ -5813,7 +5813,7 @@ rb_str_hex(VALUE str)
|
|||
rb_encoding *enc = rb_enc_get(str);
|
||||
|
||||
if (!rb_enc_asciicompat(enc)) {
|
||||
rb_raise(rb_eArgError, "ASCII incompatible encoding: %s", rb_enc_name(enc));
|
||||
rb_raise(rb_eEncCompatError, "ASCII incompatible encoding: %s", rb_enc_name(enc));
|
||||
}
|
||||
return rb_str_to_inum(str, 16, Qfalse);
|
||||
}
|
||||
|
@ -5839,7 +5839,7 @@ rb_str_oct(VALUE str)
|
|||
rb_encoding *enc = rb_enc_get(str);
|
||||
|
||||
if (!rb_enc_asciicompat(enc)) {
|
||||
rb_raise(rb_eArgError, "ASCII incompatible encoding: %s", rb_enc_name(enc));
|
||||
rb_raise(rb_eEncCompatError, "ASCII incompatible encoding: %s", rb_enc_name(enc));
|
||||
}
|
||||
return rb_str_to_inum(str, -8, Qfalse);
|
||||
}
|
||||
|
|
|
@ -261,7 +261,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_plus
|
||||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
if s1.encoding != s2.encoding && !s1.ascii_only? && !s2.ascii_only?
|
||||
assert_raise(ArgumentError) { s1 + s2 }
|
||||
assert_raise(EncodingCompatibilityError) { s1 + s2 }
|
||||
else
|
||||
t = enccall(s1, :+, s2)
|
||||
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
|
@ -344,7 +344,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
assert_equal(a(s), a(s1) + a(s2))
|
||||
assert_str_enc_propagation(s, s1, s2)
|
||||
else
|
||||
assert_raise(ArgumentError) { s << s2 }
|
||||
assert_raise(EncodingCompatibilityError) { s << s2 }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -396,7 +396,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
else
|
||||
assert_raise(ArgumentError) { s1[s2] }
|
||||
assert_raise(EncodingCompatibilityError) { s1[s2] }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -481,7 +481,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
else
|
||||
assert_raise(ArgumentError) { t[i] = s2 }
|
||||
assert_raise(EncodingCompatibilityError) { t[i] = s2 }
|
||||
end
|
||||
}
|
||||
}
|
||||
|
@ -513,7 +513,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
else
|
||||
assert_raise(ArgumentError) { t[i,len] = s2 }
|
||||
assert_raise(EncodingCompatibilityError) { t[i,len] = s2 }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -526,7 +526,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
!s2.ascii_only? ? s2.encoding : nil,
|
||||
!s3.ascii_only? ? s3.encoding : nil].uniq.compact
|
||||
if 1 < encs.length
|
||||
assert_raise(ArgumentError, IndexError) { t[s2] = s3 }
|
||||
assert_raise(EncodingCompatibilityError, IndexError) { t[s2] = s3 }
|
||||
else
|
||||
if encs.empty?
|
||||
encs = [
|
||||
|
@ -565,7 +565,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
else
|
||||
assert_raise(ArgumentError, RangeError,
|
||||
assert_raise(EncodingCompatibilityError, RangeError,
|
||||
"t=#{encdump(s1)};t[#{first}..#{last}]=#{encdump(s2)}") {
|
||||
t[first..last] = s2
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
else
|
||||
assert_raise(ArgumentError, RangeError,
|
||||
assert_raise(EncodingCompatibilityError, RangeError,
|
||||
"t=#{encdump(s1)};t[#{first}...#{last}]=#{encdump(s2)}") {
|
||||
t[first...last] = s2
|
||||
}
|
||||
|
@ -655,7 +655,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.center(width, s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.center(width, s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :center, width, s2)
|
||||
|
@ -676,7 +676,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.ljust(width, s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.ljust(width, s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :ljust, width, s2)
|
||||
|
@ -697,7 +697,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.rjust(width, s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.rjust(width, s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :rjust, width, s2)
|
||||
|
@ -711,7 +711,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
if !s1.ascii_only? && !s2.ascii_only? && !Encoding.compatible?(s1,s2)
|
||||
if s1.bytesize > s2.bytesize
|
||||
assert_raise(ArgumentError) { s1.chomp(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.chomp(s2) }
|
||||
end
|
||||
next
|
||||
end
|
||||
|
@ -777,11 +777,11 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_count
|
||||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
if !s1.valid_encoding? || !s2.valid_encoding?
|
||||
assert_raise(ArgumentError) { s1.count(s2) }
|
||||
assert_raise(ArgumentError, EncodingCompatibilityError) { s1.count(s2) }
|
||||
next
|
||||
end
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.count(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.count(s2) }
|
||||
next
|
||||
end
|
||||
n = enccall(s1, :count, s2)
|
||||
|
@ -809,11 +809,11 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !s1.valid_encoding? || !s2.valid_encoding?
|
||||
assert_raise(ArgumentError) { s1.delete(s2) }
|
||||
assert_raise(ArgumentError, EncodingCompatibilityError) { s1.delete(s2) }
|
||||
next
|
||||
end
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.delete(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.delete(s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :delete, s2)
|
||||
|
@ -855,11 +855,11 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_each_line
|
||||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
if !s1.valid_encoding? || !s2.valid_encoding?
|
||||
assert_raise(ArgumentError) { s1.each_line(s2) {} }
|
||||
assert_raise(ArgumentError, EncodingCompatibilityError) { s1.each_line(s2) {} }
|
||||
next
|
||||
end
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.each_line(s2) {} }
|
||||
assert_raise(EncodingCompatibilityError) { s1.each_line(s2) {} }
|
||||
next
|
||||
end
|
||||
lines = []
|
||||
|
@ -908,9 +908,9 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_include?
|
||||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.include?(s2) }
|
||||
assert_raise(ArgumentError) { s1.index(s2) }
|
||||
assert_raise(ArgumentError) { s1.rindex(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.include?(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.index(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.rindex(s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :include?, s2)
|
||||
|
@ -941,7 +941,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_index
|
||||
combination(STRINGS, STRINGS, -2..2) {|s1, s2, pos|
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.index(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.index(s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :index, s2, pos)
|
||||
|
@ -974,7 +974,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_rindex
|
||||
combination(STRINGS, STRINGS, -2..2) {|s1, s2, pos|
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.rindex(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.rindex(s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :rindex, s2, pos)
|
||||
|
@ -1023,11 +1023,11 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
t2 = s1.dup
|
||||
begin
|
||||
t1[nth, 0] = s2
|
||||
rescue ArgumentError, IndexError => e1
|
||||
rescue EncodingCompatibilityError, IndexError => e1
|
||||
end
|
||||
begin
|
||||
t2.insert(nth, s2)
|
||||
rescue ArgumentError, IndexError => e2
|
||||
rescue EncodingCompatibilityError, IndexError => e2
|
||||
end
|
||||
assert_equal(t1, t2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t")
|
||||
assert_equal(e1.class, e2.class, "begin #{encdump s1}.insert(#{nth},#{encdump s2}); rescue ArgumentError, IndexError => e; e end")
|
||||
|
@ -1041,7 +1041,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
t1.insert(nth, s2)
|
||||
slen = s2.length
|
||||
assert_equal(t1[nth-slen+1,slen], s2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t")
|
||||
rescue ArgumentError, IndexError => e
|
||||
rescue EncodingCompatibilityError, IndexError => e
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -1186,11 +1186,11 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_squeeze
|
||||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
if !s1.valid_encoding? || !s2.valid_encoding?
|
||||
assert_raise(ArgumentError, "#{encdump s1}.squeeze(#{encdump s2})") { s1.squeeze(s2) }
|
||||
assert_raise(ArgumentError, EncodingCompatibilityError, "#{encdump s1}.squeeze(#{encdump s2})") { s1.squeeze(s2) }
|
||||
next
|
||||
end
|
||||
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
|
||||
assert_raise(ArgumentError) { s1.squeeze(s2) }
|
||||
assert_raise(EncodingCompatibilityError) { s1.squeeze(s2) }
|
||||
next
|
||||
end
|
||||
t = enccall(s1, :squeeze, s2)
|
||||
|
@ -1280,7 +1280,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !str_enc_compatible?(s1, s2, s3)
|
||||
assert_raise(ArgumentError, desc) { s1.tr(s2, s3) }
|
||||
assert_raise(EncodingCompatibilityError, desc) { s1.tr(s2, s3) }
|
||||
next
|
||||
end
|
||||
if !s1.valid_encoding?
|
||||
|
@ -1309,11 +1309,11 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !s1.valid_encoding?
|
||||
assert_raise(ArgumentError, desc) { s1.tr_s(s2, s3) }
|
||||
assert_raise(ArgumentError, EncodingCompatibilityError, desc) { s1.tr_s(s2, s3) }
|
||||
next
|
||||
end
|
||||
if !str_enc_compatible?(s1, s2, s3)
|
||||
assert_raise(ArgumentError, desc) { s1.tr(s2, s3) }
|
||||
assert_raise(EncodingCompatibilityError, desc) { s1.tr(s2, s3) }
|
||||
next
|
||||
end
|
||||
if s2.empty?
|
||||
|
@ -1423,7 +1423,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !str_enc_compatible?(s1.gsub(r2, ''), s3)
|
||||
assert_raise(ArgumentError, desc) { doit.call }
|
||||
assert_raise(EncodingCompatibilityError, desc) { doit.call }
|
||||
next
|
||||
end
|
||||
t = nil
|
||||
|
@ -1477,7 +1477,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
if !str_enc_compatible?(s1.gsub(r2, ''), s3)
|
||||
assert_raise(ArgumentError, desc) { doit.call }
|
||||
assert_raise(EncodingCompatibilityError, desc) { doit.call }
|
||||
next
|
||||
end
|
||||
t = ret = nil
|
||||
|
@ -1538,7 +1538,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
desc = "#{encdump s1}.end_with?(#{encdump s2})"
|
||||
if !str_enc_compatible?(s1, s2)
|
||||
assert_raise(ArgumentError, desc) { s1.end_with?(s2) }
|
||||
assert_raise(EncodingCompatibilityError, desc) { s1.end_with?(s2) }
|
||||
next
|
||||
end
|
||||
if s1.length < s2.length
|
||||
|
@ -1557,7 +1557,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
desc = "#{encdump s1}.start_with?(#{encdump s2})"
|
||||
if !str_enc_compatible?(s1, s2)
|
||||
assert_raise(ArgumentError, desc) { s1.start_with?(s2) }
|
||||
assert_raise(EncodingCompatibilityError, desc) { s1.start_with?(s2) }
|
||||
next
|
||||
end
|
||||
s1 = s1.dup.force_encoding("ASCII-8BIT")
|
||||
|
@ -1592,7 +1592,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
desc = "#{encdump s1}.partition(#{encdump s2})"
|
||||
if !str_enc_compatible?(s1, s2)
|
||||
assert_raise(ArgumentError, desc) { s1.partition(s2) }
|
||||
assert_raise(EncodingCompatibilityError, desc) { s1.partition(s2) }
|
||||
next
|
||||
end
|
||||
i = enccall(s1, :index, s2)
|
||||
|
@ -1608,7 +1608,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
desc = "#{encdump s1}.rpartition(#{encdump s2})"
|
||||
if !str_enc_compatible?(s1, s2)
|
||||
assert_raise(ArgumentError, desc) { s1.rpartition(s2) }
|
||||
assert_raise(EncodingCompatibilityError, desc) { s1.rpartition(s2) }
|
||||
next
|
||||
end
|
||||
i = enccall(s1, :rindex, s2)
|
||||
|
|
Loading…
Add table
Reference in a new issue