summaryrefslogtreecommitdiff
path: root/ext/iconv/iconv.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-04 10:39:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-04 10:39:46 +0000
commitf132f2705ded61b6b76ed829351c7f24ed0640e5 (patch)
tree8e2b713a9ee418650b4be0b4a33114ffaff7f2a8 /ext/iconv/iconv.c
parentd43b7e03ef4295fd28f3080ff57f2b1ced60d5a1 (diff)
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#do_includes): replace
also locally defined modules. * ext/iconv/iconv.c: backport Iconv::InvalidEncoding from CVS HEAD. * ext/strscan/strscan.c: moved misplaced rdoc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8070 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/iconv/iconv.c')
-rw-r--r--ext/iconv/iconv.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index c395373ff2..a6d63855ae 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -83,6 +83,7 @@ struct iconv_env_t
VALUE (*append)_((VALUE, VALUE));
};
+static VALUE rb_eIconvInvalidEncoding;
static VALUE rb_eIconvFailure;
static VALUE rb_eIconvIllegalSeq;
static VALUE rb_eIconvInvalidChar;
@@ -161,10 +162,15 @@ iconv_create
cd = iconv_open(tocode, fromcode);
}
if (cd == (iconv_t)-1) {
- volatile VALUE msg = rb_str_new2("iconv(\"");
+ int inval = errno == EINVAL;
+ volatile VALUE msg = rb_str_new2("iconv(\"" + (inval ? 5 : 0));
+ char *s;
+
rb_str_buf_cat2(rb_str_buf_append(msg, to), "\", \"");
rb_str_buf_cat2(rb_str_buf_append(msg, from), "\")");
- rb_sys_fail(StringValuePtr(msg));
+ s = StringValuePtr(msg);
+ if (!inval) rb_sys_fail(s);
+ rb_raise(rb_eIconvInvalidEncoding, "invalid encoding %s", s);
}
}
@@ -625,6 +631,8 @@ iconv_s_iconv
* Document-method: Iconv::conv
* call-seq: Iconv.iconv(to, from, *strs)
*
+ * Shorthand for
+ * Iconv.iconv(to, from, str).join
* See Iconv.iconv ???
*/
static VALUE
@@ -732,7 +740,7 @@ iconv_iconv
return iconv_convert(VALUE2ICONV(cd), str,
NIL_P(n1) ? 0 : NUM2INT(n1),
- NIL_P(n2) ? -1 : NUM2INT(n2),
+ NIL_P(n2) ? -1 : NUM2INT(n2),
NULL);
}
@@ -868,6 +876,7 @@ Init_iconv _((void))
rb_define_method(rb_eIconvFailure, "failed", iconv_failure_failed, 0);
rb_define_method(rb_eIconvFailure, "inspect", iconv_failure_inspect, 0);
+ rb_eIconvInvalidEncoding = rb_define_class_under(rb_cIconv, "InvalidEncoding", rb_eArgError);
rb_eIconvIllegalSeq = rb_define_class_under(rb_cIconv, "IllegalSequence", rb_eArgError);
rb_eIconvInvalidChar = rb_define_class_under(rb_cIconv, "InvalidCharacter", rb_eArgError);
rb_eIconvOutOfRange = rb_define_class_under(rb_cIconv, "OutOfRange", rb_eRuntimeError);