diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-16 03:29:16 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-16 03:29:16 +0000 |
commit | 52510289842a8b643c4b699de39ffdc1b7a8a383 (patch) | |
tree | ab276e59f37078d1fac0f04f4dbd324ae2d231be /ext/iconv/iconv.c | |
parent | 4eae86c8bba7d5c9bd73013b5ef9144a45de7fc9 (diff) | |
download | ruby-52510289842a8b643c4b699de39ffdc1b7a8a383.tar.gz |
* ext/iconv/iconv.c (iconv_s_list): new method Iconv.list
(libiconv only).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/iconv/iconv.c')
-rw-r--r-- | ext/iconv/iconv.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index bceb7ca692..3694f9b9ff 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -611,6 +611,15 @@ iconv_s_iconv return rb_ensure(iconv_s_convert, (VALUE)&arg, iconv_free, ICONV2VALUE(arg.cd)); } +/* +=begin +--- Iconv.conv(to, from, str) + Shorthand for + Iconv.iconv(to, from, str).join + see ((<Iconv.iconv>)) +=end +*/ + static VALUE iconv_s_conv #ifdef HAVE_PROTOTYPES @@ -630,6 +639,72 @@ iconv_s_conv return rb_ensure(iconv_s_convert, (VALUE)&arg, iconv_free, ICONV2VALUE(arg.cd)); } +/* +=begin +--- Iconv.list {|*aliases| ... } + Iterates each alias sets. +=end + */ + +#ifdef HAVE_ICONVLIST +struct iconv_name_list { + unsigned int namescount; + const char *const *names; +}; + +static VALUE +list_iconv_i +#ifdef HAVE_PROTOTYPES + (VALUE ptr) +#else /* HAVE_PROTOTYPES */ + (ptr) + VALUE ptr; +#endif /* HAVE_PROTOTYPES */ +{ + struct iconv_name_list *p = (struct iconv_name_list *)ptr; + unsigned int i, namescount = p->namescount; + const char *const *names = p->names; + VALUE ary = rb_ary_new2(namescount); + + for (i = 0; i < namescount; i++) { + rb_ary_push(ary, rb_str_new2(names[i])); + } + return rb_yield(ary); +} + +static int +list_iconv +#ifdef HAVE_PROTOTYPES + (unsigned int namescount, const char *const *names, void *data) +#else /* HAVE_PROTOTYPES */ + (namescount, names, data) + unsigned int namescount; + const char *const *names; + void *data; +#endif /* HAVE_PROTOTYPES */ +{ + int *state = data; + struct iconv_name_list list; + + list.namescount = namescount; + list.names = names; + rb_protect(list_iconv_i, (VALUE)&list, state); + return *state; +} +#endif + +static VALUE +iconv_s_list _((void)) +{ +#ifdef HAVE_ICONVLIST + int state = 0; + iconvlist(list_iconv, &state); +#else + rb_notimplement(); +#endif + return Qnil; +} + /* =begin @@ -843,6 +918,7 @@ Init_iconv _((void)) rb_define_singleton_method(rb_cIconv, "open", iconv_s_open, 2); rb_define_singleton_method(rb_cIconv, "iconv", iconv_s_iconv, -1); rb_define_singleton_method(rb_cIconv, "conv", iconv_s_conv, 3); + rb_define_singleton_method(rb_cIconv, "list", iconv_s_list, 0); rb_define_method(rb_cIconv, "initialize", iconv_initialize, 2); rb_define_method(rb_cIconv, "close", iconv_finish, 0); rb_define_method(rb_cIconv, "iconv", iconv_iconv, -1); |