ruby-changes:7060
From: akr <ko1@a...>
Date: Wed, 13 Aug 2008 17:49:56 +0900 (JST)
Subject: [ruby-changes:7060] Ruby:r18578 (trunk): * transcode.c (econv_inspect): new method.
akr 2008-08-13 17:47:57 +0900 (Wed, 13 Aug 2008) New Revision: 18578 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18578 Log: * transcode.c (econv_inspect): new method. + Modified files: trunk/ChangeLog trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18577) +++ ChangeLog (revision 18578) @@ -1,3 +1,7 @@ +Wed Aug 13 17:47:09 2008 Tanaka Akira <akr@f...> + + * transcode.c (econv_inspect): new method. + Wed Aug 13 17:35:58 2008 Tanaka Akira <akr@f...> * transcode.c (transcode_restartable0): several local variables Index: transcode.c =================================================================== --- transcode.c (revision 18577) +++ transcode.c (revision 18578) @@ -1396,6 +1396,20 @@ return self; } +static VALUE +econv_inspect(VALUE self) +{ + const char *cname = rb_obj_classname(self); + rb_trans_t *ts = DATA_PTR(self); + + if (!ts) + return rb_sprintf("#<%s: uninitialized>", cname); + else + return rb_sprintf("#<%s: %s to %s>", cname, + ts->elems[0].from, + ts->last_tc->transcoder->to_encoding); +} + #define IS_ECONV(obj) (RDATA(obj)->dfree == (RUBY_DATA_FUNC)econv_free) static rb_trans_t * @@ -1406,6 +1420,9 @@ rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding::Converter)", rb_class2name(CLASS_OF(self))); } + if (!DATA_PTR(self)) { + rb_raise(rb_eTypeError, "uninitialized encoding converter"); + } return DATA_PTR(self); } @@ -1542,6 +1559,7 @@ rb_cEncodingConverter = rb_define_class_under(rb_cEncoding, "Converter", rb_cData); rb_define_alloc_func(rb_cEncodingConverter, econv_s_allocate); rb_define_method(rb_cEncodingConverter, "initialize", econv_init, -1); + rb_define_method(rb_cEncodingConverter, "inspect", econv_inspect, 0); rb_define_method(rb_cEncodingConverter, "primitive_convert", econv_primitive_convert, -1); rb_define_method(rb_cEncodingConverter, "max_output", econv_max_output, 0); rb_define_const(rb_cEncodingConverter, "PARTIAL_INPUT", INT2FIX(PARTIAL_INPUT)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/